Skip to content

Commit

Permalink
Merge branch 'main' into dependent-new-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
awson committed Oct 1, 2024
2 parents d9069b0 + 47d42cf commit a038c27
Show file tree
Hide file tree
Showing 2,315 changed files with 124,707 additions and 57,475 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,24 @@ jobs:
**/crash_diagnostics/*
macos:
runs-on: macos-14
needs: [ stage1 ]
strategy:
fail-fast: true
fail-fast: false
matrix:
config: [
generic-cxx03,
generic-cxx23,
generic-modules,
apple-configuration
]
include:
- config: generic-cxx03
os: macos-latest
- config: generic-cxx23
os: macos-latest
- config: generic-modules
os: macos-latest
- config: apple-configuration
os: macos-latest
- config: apple-system
os: macos-13
- config: apple-system-hardened
os: macos-13
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: maxim-lobanov/setup-xcode@v1
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-binaries-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ on:
- '.github/workflows/release-binaries.yml'
- '.github/workflows/release-binaries-setup-stage/*'
- '.github/workflows/release-binaries-save-stage/*'
- 'clang/cmake/caches/Release.cmake'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || 'dispatch' }}
Expand Down
6 changes: 6 additions & 0 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ bool shouldPrint(const BinaryFunction &Function) {
}
}

std::optional<StringRef> Origin = Function.getOriginSectionName();
if (Origin && llvm::any_of(opts::PrintOnly, [&](const std::string &Name) {
return Name == *Origin;
}))
return true;

return false;
}

Expand Down
6 changes: 3 additions & 3 deletions bolt/test/AArch64/constant_island_pie_update.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.rela.exe -nostdlib \
# RUN: -Wl,-q -Wl,-z,notext
# RUN: llvm-bolt %t.rela.exe -o %t.rela.bolt --use-old-text=0 --lite=0
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.rela.bolt | FileCheck %s
# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.rela.bolt | FileCheck %s
# RUN: llvm-readelf -rsW %t.rela.bolt | FileCheck --check-prefix=ELFCHECK %s
// .relr.dyn
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.relr.exe -nostdlib \
# RUN: -Wl,-q -Wl,-z,notext -Wl,--pack-dyn-relocs=relr
# RUN: llvm-objcopy --remove-section .rela.mytext %t.relr.exe
# RUN: llvm-bolt %t.relr.exe -o %t.relr.bolt --use-old-text=0 --lite=0
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.relr.bolt | FileCheck %s
# RUN: llvm-objdump -j .text -d %t.relr.bolt | \
# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.relr.bolt | FileCheck %s
# RUN: llvm-objdump -j .text -d -z %t.relr.bolt | \
# RUN: FileCheck %s --check-prefix=ADDENDCHECK
# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=RELRELFCHECK %s
# RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s
Expand Down
2 changes: 1 addition & 1 deletion bolt/test/AArch64/update-weak-reference-symbol.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %clang %cflags -Wl,-z,notext -shared -Wl,-q %s -o %t.so
// RUN: llvm-bolt %t.so -o %t.so.bolt
// RUN: llvm-nm -n %t.so.bolt > %t.out.txt
// RUN: llvm-objdump -dj .rodata %t.so.bolt >> %t.out.txt
// RUN: llvm-objdump -z -dj .rodata %t.so.bolt >> %t.out.txt
// RUN: FileCheck %s --input-file=%t.out.txt

# CHECK: w func_1
Expand Down
29 changes: 29 additions & 0 deletions bolt/test/X86/print-only-section.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Check that --print-only flag works with sections.

# REQUIRES: system-linux

# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t.exe
# RUN: llvm-bolt %t.exe -o %t.out --print-cfg --print-only=unused_code 2>&1 \
# RUN: | FileCheck %s

# CHECK: Binary Function "foo"
# CHECK-NOT: Binary Function "_start"

.text
.globl _start
.type _start, %function
_start:
.cfi_startproc
ret
.cfi_endproc
.size _start, .-_start

.section unused_code,"ax",@progbits
.globl foo
.type foo, %function
foo:
.cfi_startproc
ret
.cfi_endproc
.size foo, .-foo
45 changes: 45 additions & 0 deletions bolt/test/merge-fdata-uninitialized-header.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Test that merge-fdata correctly handles YAML header with an uninitialized
## fields. a.yaml does not have hash-func set and it used to crash merge-fdata.

# REQUIRES: system-linux

# RUN: split-file %s %t
# RUN: not merge-fdata %t/a.yaml %t/b.yaml 2>&1 | FileCheck %s

# CHECK: cannot merge profiles with different hash functions

#--- a.yaml
---
header:
profile-version: 1
binary-name: 'a.out'
binary-build-id: '<unknown>'
profile-flags: [ lbr ]
profile-origin: branch profile reader
profile-events: ''
dfs-order: false
functions:
- name: 'main'
fid: 1
hash: 0x50BBA3441D436491
exec: 1
nblocks: 0
...
#--- b.yaml
---
header:
profile-version: 1
binary-name: 'a.out'
binary-build-id: '<unknown>'
profile-flags: [ lbr ]
profile-origin: branch profile reader
profile-events: ''
dfs-order: false
hash-func: xxh3
functions:
- name: 'main'
fid: 1
hash: 0x50BBA3441D436491
exec: 1
nblocks: 0
...
12 changes: 11 additions & 1 deletion bolt/tools/merge-fdata/merge-fdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void mergeProfileHeaders(BinaryProfileHeader &MergedHeader,
errs() << "WARNING: merging profiles with different sampling events\n";
MergedHeader.EventNames += "," + Header.EventNames;
}

if (MergedHeader.HashFunction != Header.HashFunction)
report_error("merge conflict",
"cannot merge profiles with different hash functions");
}

void mergeBasicBlockProfile(BinaryBasicBlockProfile &MergedBB,
Expand Down Expand Up @@ -386,6 +390,7 @@ int main(int argc, char **argv) {
// Merged information for all functions.
StringMap<BinaryFunctionProfile> MergedBFs;

bool FirstHeader = true;
for (std::string &InputDataFilename : Inputs) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
MemoryBuffer::getFileOrSTDIN(InputDataFilename);
Expand All @@ -409,7 +414,12 @@ int main(int argc, char **argv) {
}

// Merge the header.
mergeProfileHeaders(MergedHeader, BP.Header);
if (FirstHeader) {
MergedHeader = BP.Header;
FirstHeader = false;
} else {
mergeProfileHeaders(MergedHeader, BP.Header);
}

// Do the function merge.
for (BinaryFunctionProfile &BF : BP.Functions) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-move/tool/ClangMove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int main(int argc, const char **argv) {
for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
OS << " {\n";
OS << " \"FilePath\": \"" << *I << "\",\n";
const auto Entry = FileMgr.getFile(*I);
const auto Entry = FileMgr.getOptionalFileRef(*I);
auto ID = SM.translateFile(*Entry);
std::string Content;
llvm::raw_string_ostream ContentStream(Content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static std::string getNameOfNamespace(const CXXRecordDecl *Decl) {
std::string Ns;
llvm::raw_string_ostream OStream(Ns);
NsDecl->printQualifiedName(OStream);
OStream.flush();
return Ns.empty() ? "(global)" : Ns;
}

Expand Down
61 changes: 35 additions & 26 deletions clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,58 @@
//===----------------------------------------------------------------------===//

#include "PosixReturnCheck.h"
#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Lex/Lexer.h"

using namespace clang::ast_matchers;

namespace clang::tidy::bugprone {

static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result,
const char *BindingStr) {
const CallExpr *MatchedCall = cast<CallExpr>(
(Result.Nodes.getNodeAs<BinaryOperator>(BindingStr))->getLHS());
static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result) {
const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>("call");
const SourceManager &SM = *Result.SourceManager;
return Lexer::getSourceText(CharSourceRange::getTokenRange(
MatchedCall->getCallee()->getSourceRange()),
SM, Result.Context->getLangOpts());
}

void PosixReturnCheck::registerMatchers(MatchFinder *Finder) {
const auto PosixCall =
callExpr(callee(functionDecl(
anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
unless(hasName("::posix_openpt")))))
.bind("call");
const auto ZeroIntegerLiteral = integerLiteral(equals(0));
const auto NegIntegerLiteral =
unaryOperator(hasOperatorName("-"), hasUnaryOperand(integerLiteral()));

Finder->addMatcher(
binaryOperator(
hasOperatorName("<"),
hasLHS(callExpr(callee(functionDecl(
anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
unless(hasName("::posix_openpt")))))),
hasRHS(integerLiteral(equals(0))))
anyOf(allOf(hasOperatorName("<"), hasLHS(PosixCall),
hasRHS(ZeroIntegerLiteral)),
allOf(hasOperatorName(">"), hasLHS(ZeroIntegerLiteral),
hasRHS(PosixCall))))
.bind("ltzop"),
this);
Finder->addMatcher(
binaryOperator(
hasOperatorName(">="),
hasLHS(callExpr(callee(functionDecl(
anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
unless(hasName("::posix_openpt")))))),
hasRHS(integerLiteral(equals(0))))
anyOf(allOf(hasOperatorName(">="), hasLHS(PosixCall),
hasRHS(ZeroIntegerLiteral)),
allOf(hasOperatorName("<="), hasLHS(ZeroIntegerLiteral),
hasRHS(PosixCall))))
.bind("atop"),
this);
Finder->addMatcher(binaryOperator(hasAnyOperatorName("==", "!="),
hasOperands(PosixCall, NegIntegerLiteral))
.bind("binop"),
this);
Finder->addMatcher(
binaryOperator(
hasAnyOperatorName("==", "!=", "<=", "<"),
hasLHS(callExpr(callee(functionDecl(
anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
unless(hasName("::posix_openpt")))))),
hasRHS(unaryOperator(hasOperatorName("-"),
hasUnaryOperand(integerLiteral()))))
binaryOperator(anyOf(allOf(hasAnyOperatorName("<=", "<"),
hasLHS(PosixCall), hasRHS(NegIntegerLiteral)),
allOf(hasAnyOperatorName(">", ">="),
hasLHS(NegIntegerLiteral), hasRHS(PosixCall))))
.bind("binop"),
this);
}
Expand All @@ -61,23 +67,26 @@ void PosixReturnCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *LessThanZeroOp =
Result.Nodes.getNodeAs<BinaryOperator>("ltzop")) {
SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc();
StringRef NewBinOp =
LessThanZeroOp->getOpcode() == BinaryOperator::Opcode::BO_LT ? ">"
: "<";
diag(OperatorLoc, "the comparison always evaluates to false because %0 "
"always returns non-negative values")
<< getFunctionSpelling(Result, "ltzop")
<< FixItHint::CreateReplacement(OperatorLoc, Twine(">").str());
<< getFunctionSpelling(Result)
<< FixItHint::CreateReplacement(OperatorLoc, NewBinOp);
return;
}
if (const auto *AlwaysTrueOp =
Result.Nodes.getNodeAs<BinaryOperator>("atop")) {
diag(AlwaysTrueOp->getOperatorLoc(),
"the comparison always evaluates to true because %0 always returns "
"non-negative values")
<< getFunctionSpelling(Result, "atop");
<< getFunctionSpelling(Result);
return;
}
const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binop");
diag(BinOp->getOperatorLoc(), "%0 only returns non-negative values")
<< getFunctionSpelling(Result, "binop");
<< getFunctionSpelling(Result);
}

} // namespace clang::tidy::bugprone
Loading

0 comments on commit a038c27

Please sign in to comment.