Skip to content

Commit 7069c5a

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 6872fed + 315c904 commit 7069c5a

File tree

202 files changed

+3854
-1995
lines changed

Some content is hidden

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

202 files changed

+3854
-1995
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,10 +2356,9 @@ class BinaryFunction {
23562356
bool postProcessIndirectBranches(MCPlusBuilder::AllocatorIdTy AllocId);
23572357

23582358
/// Validate that all data references to function offsets are claimed by
2359-
/// recognized jump tables. Register externally referenced blocks as entry
2360-
/// points. Returns true if there are no unclaimed externally referenced
2361-
/// offsets.
2362-
bool validateExternallyReferencedOffsets();
2359+
/// recognized jump tables. Returns true if there are no unclaimed externally
2360+
/// referenced offsets.
2361+
bool validateInternalRefDataRelocations();
23632362

23642363
/// Return all call site profile info for this function.
23652364
IndirectCallSiteProfile &getAllCallSites() { return AllCallSites; }

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,41 +2041,47 @@ void BinaryFunction::postProcessJumpTables() {
20412041
}
20422042
}
20432043

2044-
bool BinaryFunction::validateExternallyReferencedOffsets() {
2045-
SmallPtrSet<MCSymbol *, 4> JTTargets;
2046-
for (const JumpTable *JT : llvm::make_second_range(JumpTables))
2047-
JTTargets.insert_range(JT->Entries);
2048-
2049-
bool HasUnclaimedReference = false;
2050-
for (uint64_t Destination : ExternallyReferencedOffsets) {
2051-
// Ignore __builtin_unreachable().
2052-
if (Destination == getSize())
2053-
continue;
2054-
// Ignore constant islands
2055-
if (isInConstantIsland(Destination + getAddress()))
2056-
continue;
2044+
bool BinaryFunction::validateInternalRefDataRelocations() {
2045+
if (InternalRefDataRelocations.empty())
2046+
return true;
20572047

2058-
if (BinaryBasicBlock *BB = getBasicBlockAtOffset(Destination)) {
2059-
// Check if the externally referenced offset is a recognized jump table
2060-
// target.
2061-
if (JTTargets.contains(BB->getLabel()))
2062-
continue;
2048+
// Rely on the user hint that all data refs are valid and only used as
2049+
// destinations by indirect branch in the same function.
2050+
if (opts::StrictMode)
2051+
return true;
20632052

2064-
if (opts::Verbosity >= 1) {
2065-
BC.errs() << "BOLT-WARNING: unclaimed data to code reference (possibly "
2066-
<< "an unrecognized jump table entry) to " << BB->getName()
2067-
<< " in " << *this << "\n";
2068-
}
2069-
auto L = BC.scopeLock();
2070-
addEntryPoint(*BB);
2071-
} else {
2072-
BC.errs() << "BOLT-WARNING: unknown data to code reference to offset "
2073-
<< Twine::utohexstr(Destination) << " in " << *this << "\n";
2074-
setIgnored();
2053+
DenseSet<uint64_t> UnclaimedRelocations(InternalRefDataRelocations);
2054+
for (const JumpTable *JT : llvm::make_second_range(JumpTables)) {
2055+
uint64_t EntryAddress = JT->getAddress();
2056+
while (EntryAddress < JT->getAddress() + JT->getSize()) {
2057+
UnclaimedRelocations.erase(EntryAddress);
2058+
EntryAddress += JT->EntrySize;
20752059
}
2076-
HasUnclaimedReference = true;
20772060
}
2078-
return !HasUnclaimedReference;
2061+
2062+
if (UnclaimedRelocations.empty())
2063+
return true;
2064+
2065+
BC.errs() << "BOLT-WARNING: " << UnclaimedRelocations.size()
2066+
<< " unclaimed data relocation"
2067+
<< (UnclaimedRelocations.size() > 1 ? "s" : "")
2068+
<< " remain against function " << *this;
2069+
if (opts::Verbosity) {
2070+
BC.errs() << ":\n";
2071+
for (uint64_t RelocationAddress : UnclaimedRelocations) {
2072+
const Relocation *Relocation = BC.getRelocationAt(RelocationAddress);
2073+
BC.errs() << " ";
2074+
if (Relocation)
2075+
BC.errs() << *Relocation;
2076+
else
2077+
BC.errs() << "<missing relocation>";
2078+
BC.errs() << '\n';
2079+
}
2080+
} else {
2081+
BC.errs() << ". Re-run with -v=1 to see the list\n";
2082+
}
2083+
2084+
return false;
20792085
}
20802086

20812087
bool BinaryFunction::postProcessIndirectBranches(
@@ -2200,14 +2206,6 @@ bool BinaryFunction::postProcessIndirectBranches(
22002206
LastIndirectJumpBB->updateJumpTableSuccessors();
22012207
}
22022208

2203-
// Validate that all data references to function offsets are claimed by
2204-
// recognized jump tables. Register externally referenced blocks as entry
2205-
// points.
2206-
if (!opts::StrictMode && hasInternalReference()) {
2207-
if (!validateExternallyReferencedOffsets())
2208-
return false;
2209-
}
2210-
22112209
if (HasUnknownControlFlow && !BC.HasRelocations)
22122210
return false;
22132211

@@ -2496,12 +2494,18 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
24962494
CurrentState = State::CFG;
24972495

24982496
// Make any necessary adjustments for indirect branches.
2499-
if (!postProcessIndirectBranches(AllocatorId)) {
2500-
if (opts::Verbosity) {
2501-
BC.errs() << "BOLT-WARNING: failed to post-process indirect branches for "
2502-
<< *this << '\n';
2503-
}
2497+
bool ValidCFG = postProcessIndirectBranches(AllocatorId);
2498+
if (!ValidCFG && opts::Verbosity) {
2499+
BC.errs() << "BOLT-WARNING: failed to post-process indirect branches for "
2500+
<< *this << '\n';
2501+
}
2502+
2503+
// Validate that all data references to function offsets are claimed by
2504+
// recognized jump tables.
2505+
if (ValidCFG)
2506+
ValidCFG = validateInternalRefDataRelocations();
25042507

2508+
if (!ValidCFG) {
25052509
if (BC.isAArch64())
25062510
PreserveNops = BC.HasRelocations;
25072511

bolt/test/X86/unclaimed-jt-entries.s

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232

3333
# RUN: llvm-bolt %t.exe -v=1 -o %t.out 2>&1 | FileCheck %s
3434

35-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
36-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
37-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
38-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
39-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
40-
# CHECK: BOLT-WARNING: failed to post-process indirect branches for main
35+
# CHECK: BOLT-WARNING: 11 unclaimed data relocations remain against function main
4136

4237
.text
4338
.globl main

bolt/test/runtime/X86/unclaimed-jt-entries.s

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818

1919
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
2020
# RUN: %clang %cflags %S/Inputs/unclaimed-jt-entries.c -no-pie %t.o -o %t.exe -Wl,-q
21-
# RUN: llvm-bolt %t.exe -v=1 -o %t.out --sequential-disassembly 2>&1 | FileCheck %s
21+
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck %s
2222

23-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
24-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
25-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
26-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
27-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
28-
# CHECK: BOLT-WARNING: failed to post-process indirect branches for func
23+
# CHECK: BOLT-WARNING: 11 unclaimed data relocations remain against function func
2924

3025
# Run the optimized binary
3126
# RUN: %t.out 3 | FileCheck %s --check-prefix=CHECK3

clang-tools-extra/clang-tidy/.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Checks: >
99
-bugprone-narrowing-conversions,
1010
-bugprone-unchecked-optional-access,
1111
-bugprone-unused-return-value,
12+
cppcoreguidelines-init-variables,
13+
cppcoreguidelines-missing-std-forward,
14+
cppcoreguidelines-rvalue-reference-param-not-moved,
15+
cppcoreguidelines-virtual-class-destructor,
16+
google-readability-casting,
1217
misc-const-correctness,
1318
modernize-*,
1419
-modernize-avoid-c-arrays,

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
526526
Builder << Qualifiers::fromOpaqueValue(Info.getRawArg(Index));
527527
break;
528528
case clang::DiagnosticsEngine::ak_qualtype:
529-
Builder << QualType::getFromOpaquePtr((void *)Info.getRawArg(Index));
529+
Builder << QualType::getFromOpaquePtr(
530+
reinterpret_cast<void *>(Info.getRawArg(Index)));
530531
break;
531532
case clang::DiagnosticsEngine::ak_declarationname:
532533
Builder << DeclarationName::getFromOpaqueInteger(Info.getRawArg(Index));

clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "clang/Basic/SourceManager.h"
2020
#include "clang/Tooling/Core/Diagnostic.h"
2121
#include "llvm/ADT/STLExtras.h"
22-
#include "llvm/ADT/SmallVector.h"
2322
#include "llvm/ADT/StringExtras.h"
2423
#include "llvm/ADT/StringMap.h"
2524
#include "llvm/ADT/StringSwitch.h"

clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
6363
const QualType StructFieldTy = StructField->getType();
6464
if (StructFieldTy->isIncompleteType())
6565
return;
66-
const unsigned int StructFieldWidth =
67-
(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
68-
.Width;
66+
const unsigned int StructFieldWidth = static_cast<unsigned int>(
67+
Result.Context->getTypeInfo(StructFieldTy.getTypePtr()).Width);
6968
FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
7069
// FIXME: Recommend a reorganization of the struct (sort by StructField
7170
// size, largest to smallest).
@@ -79,7 +78,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
7978
CharUnits::fromQuantity(std::max<clang::CharUnits::QuantityType>(
8079
std::ceil(static_cast<float>(TotalBitSize) / CharSize), 1));
8180
const CharUnits MaxAlign = CharUnits::fromQuantity(
82-
std::ceil((float)Struct->getMaxAlignment() / CharSize));
81+
std::ceil(static_cast<float>(Struct->getMaxAlignment()) / CharSize));
8382
const CharUnits CurrAlign =
8483
Result.Context->getASTRecordLayout(Struct).getAlignment();
8584
const CharUnits NewAlign = computeRecommendedAlignment(MinByteSize);
@@ -99,8 +98,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
9998
diag(Struct->getLocation(),
10099
"accessing fields in struct %0 is inefficient due to padding; only "
101100
"needs %1 bytes but is using %2 bytes")
102-
<< Struct << (int)MinByteSize.getQuantity()
103-
<< (int)CurrSize.getQuantity()
101+
<< Struct << MinByteSize.getQuantity() << CurrSize.getQuantity()
104102
<< FixItHint::CreateInsertion(Struct->getEndLoc().getLocWithOffset(1),
105103
" __attribute__((packed))");
106104
diag(Struct->getLocation(),
@@ -112,8 +110,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
112110

113111
FixItHint FixIt;
114112
auto *Attribute = Struct->getAttr<AlignedAttr>();
115-
const std::string NewAlignQuantity =
116-
std::to_string((int)NewAlign.getQuantity());
113+
const std::string NewAlignQuantity = std::to_string(NewAlign.getQuantity());
117114
if (Attribute) {
118115
FixIt = FixItHint::CreateReplacement(
119116
Attribute->getRange(),
@@ -130,7 +127,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
130127
diag(Struct->getLocation(),
131128
"accessing fields in struct %0 is inefficient due to poor alignment; "
132129
"currently aligned to %1 bytes, but recommended alignment is %2 bytes")
133-
<< Struct << (int)CurrAlign.getQuantity() << NewAlignQuantity << FixIt;
130+
<< Struct << CurrAlign.getQuantity() << NewAlignQuantity << FixIt;
134131

135132
diag(Struct->getLocation(),
136133
"use \"__attribute__((aligned(%0)))\" to align struct %1 to %0 bytes",

clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,22 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement,
208208
return true;
209209
switch (Op->getOpcode()) {
210210
case (BO_AddAssign):
211-
Iterations = std::ceil(float(EndValue - InitValue) / ConstantValue);
211+
Iterations =
212+
std::ceil(static_cast<float>(EndValue - InitValue) / ConstantValue);
212213
break;
213214
case (BO_SubAssign):
214-
Iterations = std::ceil(float(InitValue - EndValue) / ConstantValue);
215+
Iterations =
216+
std::ceil(static_cast<float>(InitValue - EndValue) / ConstantValue);
215217
break;
216218
case (BO_MulAssign):
217-
Iterations =
218-
1 + ((std::log((double)EndValue) - std::log((double)InitValue)) /
219-
std::log((double)ConstantValue));
219+
Iterations = 1 + ((std::log(static_cast<double>(EndValue)) -
220+
std::log(static_cast<double>(InitValue))) /
221+
std::log(static_cast<double>(ConstantValue)));
220222
break;
221223
case (BO_DivAssign):
222-
Iterations =
223-
1 + ((std::log((double)InitValue) - std::log((double)EndValue)) /
224-
std::log((double)ConstantValue));
224+
Iterations = 1 + ((std::log(static_cast<double>(InitValue)) -
225+
std::log(static_cast<double>(EndValue))) /
226+
std::log(static_cast<double>(ConstantValue)));
225227
break;
226228
default:
227229
// All other operators are not handled; assume large bounds.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "llvm/ADT/SmallString.h"
1313
#include "llvm/ADT/SmallVector.h"
14-
#include <algorithm>
1514

1615
using namespace clang::ast_matchers;
1716

0 commit comments

Comments
 (0)