Skip to content

Commit 5eadf27

Browse files
authored
Merge pull request #23 from Xilinx/tiagot.FXML-1406.llvm_bump_120423
LLVM bump to green commit 9c4611f
2 parents a2723ac + 683817f commit 5eadf27

File tree

2,396 files changed

+91324
-29834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,396 files changed

+91324
-29834
lines changed

bolt/lib/Core/BinarySection.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ BinarySection::hash(const BinaryData &BD,
3939
if (Itr != Cache.end())
4040
return Itr->second;
4141

42-
Cache[&BD] = 0;
42+
hash_code Hash =
43+
hash_combine(hash_value(BD.getSize()), hash_value(BD.getSectionName()));
44+
45+
Cache[&BD] = Hash;
46+
47+
if (!containsRange(BD.getAddress(), BD.getSize()))
48+
return Hash;
4349

4450
uint64_t Offset = BD.getAddress() - getAddress();
4551
const uint64_t EndOffset = BD.getEndAddress() - getAddress();
4652
auto Begin = Relocations.lower_bound(Relocation{Offset, 0, 0, 0, 0});
4753
auto End = Relocations.upper_bound(Relocation{EndOffset, 0, 0, 0, 0});
4854
const StringRef Contents = getContents();
4955

50-
hash_code Hash =
51-
hash_combine(hash_value(BD.getSize()), hash_value(BD.getSectionName()));
52-
5356
while (Begin != End) {
5457
const Relocation &Rel = *Begin++;
5558
Hash = hash_combine(

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,16 @@ void RewriteInstance::discoverFileObjects() {
10501050
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: considering symbol " << UniqueName
10511051
<< " for function\n");
10521052

1053+
if (Address == Section->getAddress() + Section->getSize()) {
1054+
assert(SymbolSize == 0 &&
1055+
"unexpect non-zero sized symbol at end of section");
1056+
LLVM_DEBUG(
1057+
dbgs()
1058+
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
1059+
registerName(SymbolSize);
1060+
continue;
1061+
}
1062+
10531063
if (!Section->isText()) {
10541064
assert(SymbolType != SymbolRef::ST_Function &&
10551065
"unexpected function inside non-code section");
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_AARCH64
7+
Entry: 0x90
8+
ProgramHeaders:
9+
- Type: PT_LOAD
10+
Flags: [ PF_X, PF_R ]
11+
FirstSec: .rodata
12+
LastSec: .text
13+
Align: 0x10000
14+
Offset: 0x0
15+
Sections:
16+
- Name: .rodata
17+
Type: SHT_PROGBITS
18+
Flags: [ SHF_ALLOC ]
19+
Address: 0x78
20+
AddressAlign: 0x1
21+
Content: '7800000000000000'
22+
- Name: .dummy
23+
Type: SHT_PROGBITS
24+
Flags: [ SHF_ALLOC ]
25+
Address: 0x80
26+
AddressAlign: 0x1
27+
Content: '78000000000000009000000000000000'
28+
- Name: .text
29+
Type: SHT_PROGBITS
30+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
31+
Address: 0x90
32+
AddressAlign: 0x4
33+
Content: FF4300D11F2003D508FFFF10080140F9E80700F9A80B8052010000D4FF430091C0035FD6
34+
- Name: .rela.text
35+
Type: SHT_RELA
36+
Flags: [ SHF_INFO_LINK ]
37+
Link: .symtab
38+
AddressAlign: 0x8
39+
Info: .text
40+
Relocations:
41+
- Offset: 0x94
42+
Symbol: Symbol
43+
Type: R_AARCH64_ADR_GOT_PAGE
44+
- Offset: 0x98
45+
Symbol: Symbol
46+
Type: R_AARCH64_LD64_GOT_LO12_NC
47+
- Name: .rela.dummy
48+
Type: SHT_RELA
49+
Flags: [ SHF_INFO_LINK ]
50+
Link: .symtab
51+
AddressAlign: 0x8
52+
Info: .dummy
53+
Relocations:
54+
- Offset: 0x80
55+
Symbol: Symbol
56+
Type: R_AARCH64_ABS64
57+
- Offset: 0x88
58+
Symbol: _start
59+
Type: R_AARCH64_ABS64
60+
Symbols:
61+
- Name: tmp.c
62+
Type: STT_FILE
63+
Index: SHN_ABS
64+
- Name: '$x.0'
65+
Section: .text
66+
Value: 0x90
67+
- Name: '$d.1'
68+
Index: SHN_ABS
69+
- Name: .text
70+
Type: STT_SECTION
71+
Section: .text
72+
Value: 0x90
73+
- Name: _start
74+
Type: STT_FUNC
75+
Section: .text
76+
Binding: STB_GLOBAL
77+
Value: 0x90
78+
Size: 0x24
79+
- Name: Symbol
80+
Section: .rodata
81+
Binding: STB_GLOBAL
82+
Value: 0x78
83+
...

bolt/test/AArch64/symbol-hashes.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This test checks that we don't try to use symbols outside of section when
2+
// generating symbol hashes
3+
4+
RUN: yaml2obj %p/Inputs/symbol-hashes.yaml -o %t.exe
5+
RUN: llvm-bolt %t.exe -force-data-relocations -o %t.exe.bolt
6+

bolt/test/X86/section-end-sym.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as
2+
## functions.
3+
4+
# REQUIRES: system-linux, asserts
5+
6+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
7+
# RUN: ld.lld %t.o -o %t.exe -q
8+
# RUN: llvm-bolt %t.exe -o /dev/null --print-cfg --debug-only=bolt 2>&1 \
9+
# RUN: | FileCheck %s
10+
11+
# CHECK: considering symbol etext for function
12+
# CHECK-NEXT: rejecting as symbol points to end of its section
13+
# CHECK-NOT: Binary Function "etext{{.*}}" after building cfg
14+
15+
16+
.text
17+
.globl _start
18+
.type _start,@function
19+
_start:
20+
retq
21+
.size _start, .-_start
22+
23+
.align 0x1000
24+
.globl etext
25+
etext:
26+
27+
.data
28+
.Lfoo:
29+
.word 0

clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class UseAfterMoveFinder {
5858
public:
5959
UseAfterMoveFinder(ASTContext *TheContext);
6060

61-
// Within the given function body, finds the first use of 'MovedVariable' that
61+
// Within the given code block, finds the first use of 'MovedVariable' that
6262
// occurs after 'MovingCall' (the expression that performs the move). If a
6363
// use-after-move is found, writes information about it to 'TheUseAfterMove'.
6464
// Returns whether a use-after-move was found.
65-
bool find(Stmt *FunctionBody, const Expr *MovingCall,
65+
bool find(Stmt *CodeBlock, const Expr *MovingCall,
6666
const ValueDecl *MovedVariable, UseAfterMove *TheUseAfterMove);
6767

6868
private:
@@ -104,7 +104,7 @@ static StatementMatcher inDecltypeOrTemplateArg() {
104104
UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)
105105
: Context(TheContext) {}
106106

107-
bool UseAfterMoveFinder::find(Stmt *FunctionBody, const Expr *MovingCall,
107+
bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
108108
const ValueDecl *MovedVariable,
109109
UseAfterMove *TheUseAfterMove) {
110110
// Generate the CFG manually instead of through an AnalysisDeclContext because
@@ -118,12 +118,11 @@ bool UseAfterMoveFinder::find(Stmt *FunctionBody, const Expr *MovingCall,
118118
Options.AddImplicitDtors = true;
119119
Options.AddTemporaryDtors = true;
120120
std::unique_ptr<CFG> TheCFG =
121-
CFG::buildCFG(nullptr, FunctionBody, Context, Options);
121+
CFG::buildCFG(nullptr, CodeBlock, Context, Options);
122122
if (!TheCFG)
123123
return false;
124124

125-
Sequence =
126-
std::make_unique<ExprSequence>(TheCFG.get(), FunctionBody, Context);
125+
Sequence = std::make_unique<ExprSequence>(TheCFG.get(), CodeBlock, Context);
127126
BlockMap = std::make_unique<StmtToBlockMap>(TheCFG.get(), Context);
128127
Visited.clear();
129128

@@ -398,20 +397,28 @@ static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
398397
}
399398

400399
void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
400+
// try_emplace is a common maybe-moving function that returns a
401+
// bool to tell callers whether it moved. Ignore std::move inside
402+
// try_emplace to avoid false positives as we don't track uses of
403+
// the bool.
404+
auto TryEmplaceMatcher =
405+
cxxMemberCallExpr(callee(cxxMethodDecl(hasName("try_emplace"))));
401406
auto CallMoveMatcher =
402-
callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1),
407+
callExpr(argumentCountIs(1), callee(functionDecl(hasName("::std::move"))),
403408
hasArgument(0, declRefExpr().bind("arg")),
409+
unless(inDecltypeOrTemplateArg()),
410+
unless(hasParent(TryEmplaceMatcher)), expr().bind("call-move"),
404411
anyOf(hasAncestor(compoundStmt(
405412
hasParent(lambdaExpr().bind("containing-lambda")))),
406-
hasAncestor(functionDecl().bind("containing-func"))),
407-
unless(inDecltypeOrTemplateArg()),
408-
// try_emplace is a common maybe-moving function that returns a
409-
// bool to tell callers whether it moved. Ignore std::move inside
410-
// try_emplace to avoid false positives as we don't track uses of
411-
// the bool.
412-
unless(hasParent(cxxMemberCallExpr(
413-
callee(cxxMethodDecl(hasName("try_emplace")))))))
414-
.bind("call-move");
413+
hasAncestor(functionDecl(anyOf(
414+
cxxConstructorDecl(
415+
hasAnyConstructorInitializer(withInitializer(
416+
expr(anyOf(equalsBoundNode("call-move"),
417+
hasDescendant(expr(
418+
equalsBoundNode("call-move")))))
419+
.bind("containing-ctor-init"))))
420+
.bind("containing-ctor"),
421+
functionDecl().bind("containing-func"))))));
415422

416423
Finder->addMatcher(
417424
traverse(
@@ -434,6 +441,10 @@ void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
434441
}
435442

436443
void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) {
444+
const auto *ContainingCtor =
445+
Result.Nodes.getNodeAs<CXXConstructorDecl>("containing-ctor");
446+
const auto *ContainingCtorInit =
447+
Result.Nodes.getNodeAs<Expr>("containing-ctor-init");
437448
const auto *ContainingLambda =
438449
Result.Nodes.getNodeAs<LambdaExpr>("containing-lambda");
439450
const auto *ContainingFunc =
@@ -445,23 +456,38 @@ void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) {
445456
if (!MovingCall || !MovingCall->getExprLoc().isValid())
446457
MovingCall = CallMove;
447458

448-
Stmt *FunctionBody = nullptr;
449-
if (ContainingLambda)
450-
FunctionBody = ContainingLambda->getBody();
451-
else if (ContainingFunc)
452-
FunctionBody = ContainingFunc->getBody();
453-
else
454-
return;
455-
456459
// Ignore the std::move if the variable that was passed to it isn't a local
457460
// variable.
458461
if (!Arg->getDecl()->getDeclContext()->isFunctionOrMethod())
459462
return;
460463

461-
UseAfterMoveFinder Finder(Result.Context);
462-
UseAfterMove Use;
463-
if (Finder.find(FunctionBody, MovingCall, Arg->getDecl(), &Use))
464-
emitDiagnostic(MovingCall, Arg, Use, this, Result.Context);
464+
// Collect all code blocks that could use the arg after move.
465+
llvm::SmallVector<Stmt *> CodeBlocks{};
466+
if (ContainingCtor) {
467+
CodeBlocks.push_back(ContainingCtor->getBody());
468+
if (ContainingCtorInit) {
469+
// Collect the constructor initializer expressions.
470+
bool BeforeMove{true};
471+
for (CXXCtorInitializer *Init : ContainingCtor->inits()) {
472+
if (BeforeMove && Init->getInit()->IgnoreImplicit() ==
473+
ContainingCtorInit->IgnoreImplicit())
474+
BeforeMove = false;
475+
if (!BeforeMove)
476+
CodeBlocks.push_back(Init->getInit());
477+
}
478+
}
479+
} else if (ContainingLambda) {
480+
CodeBlocks.push_back(ContainingLambda->getBody());
481+
} else if (ContainingFunc) {
482+
CodeBlocks.push_back(ContainingFunc->getBody());
483+
}
484+
485+
for (Stmt *CodeBlock : CodeBlocks) {
486+
UseAfterMoveFinder Finder(Result.Context);
487+
UseAfterMove Use;
488+
if (Finder.find(CodeBlock, MovingCall, Arg->getDecl(), &Use))
489+
emitDiagnostic(MovingCall, Arg, Use, this, Result.Context);
490+
}
465491
}
466492

467493
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
4747
if (!isGoogletestTestMacro(MacroName) || !Args ||
4848
Args->getNumMacroArguments() < 2)
4949
return;
50-
const Token *TestCaseNameToken = Args->getUnexpArgument(0);
50+
const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
5151
const Token *TestNameToken = Args->getUnexpArgument(1);
52-
if (!TestCaseNameToken || !TestNameToken)
52+
if (!TestSuiteNameToken || !TestNameToken)
5353
return;
54-
std::string TestCaseName = PP->getSpelling(*TestCaseNameToken);
55-
if (TestCaseName.find('_') != std::string::npos)
56-
Check->diag(TestCaseNameToken->getLocation(),
57-
"avoid using \"_\" in test case name \"%0\" according to "
54+
std::string TestSuiteNameMaybeDisabled =
55+
PP->getSpelling(*TestSuiteNameToken);
56+
StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
57+
TestSuiteName.consume_front(KDisabledTestPrefix);
58+
if (TestSuiteName.contains('_'))
59+
Check->diag(TestSuiteNameToken->getLocation(),
60+
"avoid using \"_\" in test suite name \"%0\" according to "
5861
"Googletest FAQ")
59-
<< TestCaseName;
62+
<< TestSuiteName;
6063

6164
std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
6265
StringRef TestName = TestNameMaybeDisabled;

clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,19 @@ void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
235235

236236
// Destructor.
237237
Finder->addMatcher(
238-
cxxDestructorDecl(unless(hasParent(IsUnionLikeClass)), isDefinition())
238+
cxxDestructorDecl(isDefinition(), unless(ofClass(IsUnionLikeClass)))
239239
.bind(SpecialFunction),
240240
this);
241+
// Constructor.
241242
Finder->addMatcher(
242243
cxxConstructorDecl(
243-
unless(
244-
hasParent(decl(anyOf(IsUnionLikeClass, functionTemplateDecl())))),
245-
isDefinition(),
244+
isDefinition(), unless(ofClass(IsUnionLikeClass)),
245+
unless(hasParent(functionTemplateDecl())),
246246
anyOf(
247247
// Default constructor.
248-
allOf(unless(hasAnyConstructorInitializer(isWritten())),
249-
unless(isVariadic()), parameterCountIs(0),
250-
IsPublicOrOutOfLineUntilCPP20),
248+
allOf(parameterCountIs(0),
249+
unless(hasAnyConstructorInitializer(isWritten())),
250+
unless(isVariadic()), IsPublicOrOutOfLineUntilCPP20),
251251
// Copy constructor.
252252
allOf(isCopyConstructor(),
253253
// Discard constructors that can be used as a copy
@@ -258,9 +258,9 @@ void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
258258
this);
259259
// Copy-assignment operator.
260260
Finder->addMatcher(
261-
cxxMethodDecl(unless(hasParent(
262-
decl(anyOf(IsUnionLikeClass, functionTemplateDecl())))),
263-
isDefinition(), isCopyAssignmentOperator(),
261+
cxxMethodDecl(isDefinition(), isCopyAssignmentOperator(),
262+
unless(ofClass(IsUnionLikeClass)),
263+
unless(hasParent(functionTemplateDecl())),
264264
// isCopyAssignmentOperator() allows the parameter to be
265265
// passed by value, and in this case it cannot be
266266
// defaulted.
@@ -299,6 +299,12 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
299299
if (!SpecialFunctionDecl->isCopyAssignmentOperator() && !Body->body_empty())
300300
return;
301301

302+
// If body contain any preprocesor derictives, don't warn.
303+
if (IgnoreMacros && utils::lexer::rangeContainsExpansionsOrDirectives(
304+
Body->getSourceRange(), *Result.SourceManager,
305+
Result.Context->getLangOpts()))
306+
return;
307+
302308
// If there are comments inside the body, don't do the change.
303309
bool ApplyFix = SpecialFunctionDecl->isCopyAssignmentOperator() ||
304310
bodyEmpty(Result.Context, Body);

0 commit comments

Comments
 (0)