Skip to content

Commit b27b523

Browse files
committed
merge main into amd-staging
2 parents e1d745b + eb77061 commit b27b523

File tree

951 files changed

+40868
-28467
lines changed

Some content is hidden

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

951 files changed

+40868
-28467
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
stage1:
3838
if: github.repository_owner == 'llvm'
3939
runs-on: libcxx-self-hosted-linux
40-
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
40+
container: ghcr.io/llvm/libcxx-linux-builder:b6bb9dc5abd7c6452c13a53fa8949cb259db459b
4141
continue-on-error: false
4242
strategy:
4343
fail-fast: false
@@ -75,7 +75,7 @@ jobs:
7575
stage2:
7676
if: github.repository_owner == 'llvm'
7777
runs-on: libcxx-self-hosted-linux
78-
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
78+
container: ghcr.io/llvm/libcxx-linux-builder:b6bb9dc5abd7c6452c13a53fa8949cb259db459b
7979
needs: [ stage1 ]
8080
continue-on-error: false
8181
strategy:
@@ -167,7 +167,7 @@ jobs:
167167
- config: 'generic-msan'
168168
machine: libcxx-self-hosted-linux
169169
runs-on: ${{ matrix.machine }}
170-
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
170+
container: ghcr.io/llvm/libcxx-linux-builder:b6bb9dc5abd7c6452c13a53fa8949cb259db459b
171171
steps:
172172
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
173173
- name: ${{ matrix.config }}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,30 @@ void RewriteInstance::readDynamicRelocations(const SectionRef &Section,
24552455
if (Symbol)
24562456
SymbolIndex[Symbol] = getRelocationSymbol(InputFile, Rel);
24572457

2458+
const uint64_t ReferencedAddress = SymbolAddress + Addend;
2459+
BinaryFunction *Func =
2460+
BC->getBinaryFunctionContainingAddress(ReferencedAddress);
2461+
2462+
if (Relocation::isRelative(RType) && SymbolAddress == 0) {
2463+
if (Func) {
2464+
if (!Func->isInConstantIsland(ReferencedAddress)) {
2465+
if (const uint64_t ReferenceOffset =
2466+
ReferencedAddress - Func->getAddress()) {
2467+
Func->addEntryPointAtOffset(ReferenceOffset);
2468+
}
2469+
} else {
2470+
BC->errs() << "BOLT-ERROR: referenced address at 0x"
2471+
<< Twine::utohexstr(ReferencedAddress)
2472+
<< " is in constant island of function " << *Func << "\n";
2473+
exit(1);
2474+
}
2475+
}
2476+
} else if (Relocation::isRelative(RType) && SymbolAddress != 0) {
2477+
BC->errs() << "BOLT-ERROR: symbol address non zero for RELATIVE "
2478+
"relocation type\n";
2479+
exit(1);
2480+
}
2481+
24582482
BC->addDynamicRelocation(Rel.getOffset(), Symbol, RType, Addend);
24592483
}
24602484
}
@@ -5696,7 +5720,7 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
56965720
for (const BinaryBasicBlock &BB : *BF)
56975721
if (BB.isEntryPoint() &&
56985722
(BF->getAddress() + BB.getOffset()) == OldAddress)
5699-
return BF->getOutputAddress() + BB.getOffset();
5723+
return BB.getOutputStartAddress();
57005724
}
57015725
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
57025726
"input address 0x"

bolt/test/AArch64/computed-goto.s

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This test checks that BOLT creates entry points for addresses
2+
// referenced by dynamic relocations.
3+
// The test also checks that BOLT can map addresses inside functions.
4+
5+
// Checks for error and entry points.
6+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
7+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
8+
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
9+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg | FileCheck --check-prefix=CHECK-ENTRIES %s
10+
11+
// Checks for dynamic relocations.
12+
# RUN: llvm-readelf -dr %t.bolt > %t.out.txt
13+
# RUN: llvm-objdump -j .rela.dyn -d %t.bolt >> %t.out.txt
14+
# RUN: FileCheck --check-prefix=CHECK-RELOCS %s --input-file=%t.out.txt
15+
16+
// Before bolt could handle mapping addresses within moved functions, it
17+
// would bail out with an error of the form:
18+
// BOLT-ERROR: unable to get new address corresponding to input address 0x10390 in function main. Consider adding this function to --skip-funcs=...
19+
// These addresses arise if computed GOTO is in use.
20+
// Check that bolt does not emit any error.
21+
# CHECK-NOT: BOLT-ERROR
22+
23+
// Check that there are dynamic relocations.
24+
# CHECK-RELOCS: Dynamic section at offset {{.*}} contains {{.*}} entries:
25+
# CHECK-RELOCS: Relocation section '.rela.dyn' at offset {{.*}} contains {{.*}} entries
26+
27+
// Check that dynamic relocations were updated
28+
# CHECK-RELOCS: [[#%x,OFF:]] [[#%x,INFO_DYN:]] R_AARCH64_RELATIVE [[#%x,ADDR:]]
29+
# CHECK-RELOCS-NEXT: [[#OFF + 8]] {{0*}}[[#INFO_DYN]] R_AARCH64_RELATIVE [[#ADDR + 8]]
30+
# CHECK-RELOCS: [[#ADDR]] <unknown>
31+
# CHECK-RELOCS: [[#ADDR + 8]] <unknown>
32+
33+
// Check that BOLT registers extra entry points for dynamic relocations.
34+
# CHECK-ENTRIES: Binary Function "main" after building cfg {
35+
# CHECK-ENTRIES: IsMultiEntry: 1
36+
# CHECK-ENTRIES: .Ltmp0 {{.*}}
37+
# CHECK-ENTRIES-NEXT: Secondary Entry Point: {{.*}}
38+
# CHECK-ENTRIES: .Ltmp1 {{.*}}
39+
# CHECK-ENTRIES-NEXT: Secondary Entry Point: {{.*}}
40+
41+
.globl main
42+
.p2align 2
43+
.type main,@function
44+
main:
45+
.cfi_startproc
46+
adrp x8, .L__const.main.ptrs+8
47+
add x8, x8, :lo12:.L__const.main.ptrs+8
48+
ldr x9, [x8], #8
49+
br x9
50+
51+
.Label0: // Block address taken
52+
ldr x9, [x8], #8
53+
br x9
54+
55+
.Label1: // Block address taken
56+
mov w0, #42
57+
ret
58+
59+
.Lfunc_end0:
60+
.size main, .Lfunc_end0-main
61+
.cfi_endproc
62+
.type .L__const.main.ptrs,@object
63+
.section .data.rel.ro,"aw",@progbits
64+
.p2align 3, 0x0
65+
.L__const.main.ptrs:
66+
.xword .Label0
67+
.xword .Label1

bolt/test/X86/Inputs/indirect_goto.c renamed to bolt/test/Inputs/indirect_goto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
int main(int argc, char *argv[]) {
2-
static const void *T1[] = { &&L1, &&L2 };
3-
static const void *T2[] = { &&L2, &&L3 };
2+
static const void *T1[] = {&&L1, &&L2};
3+
static const void *T2[] = {&&L2, &&L3};
44

55
const void **T = (argc > 1) ? T1 : T2;
66

bolt/test/X86/indirect-goto-pie.test

Lines changed: 0 additions & 16 deletions
This file was deleted.

bolt/test/X86/indirect-goto.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Check llvm-bolt processes binaries compiled from sources that use indirect goto.
2-
RUN: %clang %cflags -no-pie %S/Inputs/indirect_goto.c -Wl,-q -o %t
2+
RUN: %clang %cflags -no-pie %S/../Inputs/indirect_goto.c -Wl,-q -o %t
33
RUN: llvm-bolt %t -o %t.null --relocs=1 --print-cfg --print-only=main \
44
RUN: --strict \
55
RUN: 2>&1 | FileCheck %s

bolt/test/indirect-goto-relocs.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test checks that BOLT creates entry points from sources
2+
// that use indirect goto.
3+
4+
RUN: %clang %cflags -pie %S/Inputs/indirect_goto.c -o %t.exe -Wl,-q
5+
RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg | FileCheck --check-prefix=CHECK-PIE %s
6+
7+
RUN: %clang %cflags -no-pie %S/Inputs/indirect_goto.c -o %t.exe -Wl,-q
8+
RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg | FileCheck --check-prefix=CHECK-NO-PIE %s
9+
10+
// Check that BOLT registers extra entry points for dynamic relocations with PIE.
11+
CHECK-PIE: Binary Function "main" after building cfg {
12+
CHECK-PIE: IsMultiEntry: 1
13+
CHECK-PIE: Secondary Entry Points : {{.*}}
14+
15+
// Check that BOLT does not register extra entry points for dynamic relocations
16+
// without PIE
17+
CHECK-NO-PIE: Binary Function "main" after building cfg {
18+
CHECK-NO-PIE-NOT: IsMultiEntry: 1
19+
CHECK-NO-PIE-NOT: Secondary Entry Points : {{.*}}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ void SingleWorkItemBarrierCheck::check(const MatchFinder::MatchResult &Result) {
5454
bool IsNDRange = false;
5555
if (MatchedDecl->hasAttr<ReqdWorkGroupSizeAttr>()) {
5656
const auto *Attribute = MatchedDecl->getAttr<ReqdWorkGroupSizeAttr>();
57-
if (Attribute->getXDim() > 1 || Attribute->getYDim() > 1 ||
58-
Attribute->getZDim() > 1)
57+
auto Eval = [&](Expr *E) {
58+
return E->EvaluateKnownConstInt(MatchedDecl->getASTContext())
59+
.getExtValue();
60+
};
61+
if (Eval(Attribute->getXDim()) > 1 || Eval(Attribute->getYDim()) > 1 ||
62+
Eval(Attribute->getZDim()) > 1)
5963
IsNDRange = true;
6064
}
6165
if (IsNDRange) // No warning if kernel is treated as an NDRange.

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ void ComparePointerToMemberVirtualFunctionCheck::check(
7070
// compare with variable which type is pointer to member function.
7171
llvm::SmallVector<SourceLocation, 12U> SameSignatureVirtualMethods{};
7272
const auto *MPT = cast<MemberPointerType>(DRE->getType().getCanonicalType());
73-
const Type *T = MPT->getClass();
74-
if (T == nullptr)
75-
return;
76-
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
73+
const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
7774
if (RD == nullptr)
7875
return;
7976

clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ bool isQualificationConvertiblePointer(QualType From, QualType To,
219219

220220
if (P1->isMemberPointerType())
221221
return P2->isMemberPointerType() &&
222-
P1->getAs<MemberPointerType>()->getClass() ==
223-
P2->getAs<MemberPointerType>()->getClass();
222+
P1->getAs<MemberPointerType>()->getMostRecentCXXRecordDecl() ==
223+
P2->getAs<MemberPointerType>()->getMostRecentCXXRecordDecl();
224224

225225
if (P1->isConstantArrayType())
226226
return P2->isConstantArrayType() &&

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
455455
CodeCompleteOpts.MainFileSignals = IP->Signals;
456456
CodeCompleteOpts.AllScopes = Config::current().Completion.AllScopes;
457457
CodeCompleteOpts.ArgumentLists = Config::current().Completion.ArgumentLists;
458+
CodeCompleteOpts.InsertIncludes =
459+
Config::current().Completion.HeaderInsertion;
458460
// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
459461
// both the old and the new version in case only one of them matches.
460462
CodeCompleteResult Result = clangd::codeComplete(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ struct CompletionCandidate {
294294
std::optional<llvm::StringRef>
295295
headerToInsertIfAllowed(const CodeCompleteOptions &Opts,
296296
CodeCompletionContext::Kind ContextKind) const {
297-
if (Opts.InsertIncludes == CodeCompleteOptions::NeverInsert ||
297+
if (Opts.InsertIncludes == Config::HeaderInsertionPolicy::NeverInsert ||
298298
RankedIncludeHeaders.empty() ||
299299
!contextAllowsHeaderInsertion(ContextKind))
300300
return std::nullopt;

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ struct CodeCompleteOptions {
7171
/// Whether to present doc comments as plain-text or markdown.
7272
MarkupKind DocumentationFormat = MarkupKind::PlainText;
7373

74-
enum IncludeInsertion {
75-
IWYU,
76-
NeverInsert,
77-
} InsertIncludes = IncludeInsertion::IWYU;
74+
Config::HeaderInsertionPolicy InsertIncludes =
75+
Config::HeaderInsertionPolicy::IWYU;
7876

7977
/// Whether include insertions for Objective-C code should use #import instead
8078
/// of #include.

clang-tools-extra/clangd/Config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,20 @@ struct Config {
147147
FullPlaceholders,
148148
};
149149

150+
enum class HeaderInsertionPolicy {
151+
IWYU, // Include what you use
152+
NeverInsert // Never insert headers as part of code completion
153+
};
154+
150155
/// Configures code completion feature.
151156
struct {
152157
/// Whether code completion includes results that are not visible in current
153158
/// scopes.
154159
bool AllScopes = true;
155160
/// controls the completion options for argument lists.
156161
ArgumentListsPolicy ArgumentLists = ArgumentListsPolicy::FullPlaceholders;
162+
/// Controls if headers should be inserted when completions are accepted
163+
HeaderInsertionPolicy HeaderInsertion = HeaderInsertionPolicy::IWYU;
157164
} Completion;
158165

159166
/// Configures hover feature.

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ struct FragmentCompiler {
697697
C.Completion.ArgumentLists = *Val;
698698
});
699699
}
700+
if (F.HeaderInsertion) {
701+
if (auto Val =
702+
compileEnum<Config::HeaderInsertionPolicy>("HeaderInsertion",
703+
*F.HeaderInsertion)
704+
.map("IWYU", Config::HeaderInsertionPolicy::IWYU)
705+
.map("Never", Config::HeaderInsertionPolicy::NeverInsert)
706+
.value())
707+
Out.Apply.push_back([Val](const Params &, Config &C) {
708+
C.Completion.HeaderInsertion = *Val;
709+
});
710+
}
700711
}
701712

702713
void compile(Fragment::HoverBlock &&F) {

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ struct Fragment {
341341
/// Delimiters: empty pair of delimiters "()" or "<>"
342342
/// FullPlaceholders: full name of both type and parameter
343343
std::optional<Located<std::string>> ArgumentLists;
344+
/// Add #include directives when accepting code completions. Config
345+
/// equivalent of the CLI option '--header-insertion'
346+
/// Valid values are enum Config::HeaderInsertionPolicy values:
347+
/// "IWYU": Include what you use. Insert the owning header for top-level
348+
/// symbols, unless the header is already directly included or the
349+
/// symbol is forward-declared
350+
/// "NeverInsert": Never insert headers
351+
std::optional<Located<std::string>> HeaderInsertion;
344352
};
345353
CompletionBlock Completion;
346354

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ class Parser {
245245
if (auto ArgumentLists = scalarValue(N, "ArgumentLists"))
246246
F.ArgumentLists = *ArgumentLists;
247247
});
248+
Dict.handle("HeaderInsertion", [&](Node &N) {
249+
if (auto HeaderInsertion = scalarValue(N, "HeaderInsertion"))
250+
F.HeaderInsertion = *HeaderInsertion;
251+
});
248252
Dict.parse(N);
249253
}
250254

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
627627
return DiagnosticsEngine::Ignored;
628628
switch (Info.getID()) {
629629
case diag::warn_no_newline_eof:
630-
case diag::warn_cxx98_compat_no_newline_eof:
631-
case diag::ext_no_newline_eof:
632630
// If the preamble doesn't span the whole file, drop the no newline at
633-
// eof warnings.
631+
// eof warning.
634632
return Bounds.Size != ContentsBuffer->getBufferSize()
635633
? DiagnosticsEngine::Level::Ignored
636634
: DiagLevel;

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,19 @@ opt<std::string> EnableFunctionArgSnippets{
251251
init("-1"),
252252
};
253253

254-
opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
254+
opt<Config::HeaderInsertionPolicy> HeaderInsertion{
255255
"header-insertion",
256256
cat(Features),
257257
desc("Add #include directives when accepting code completions"),
258258
init(CodeCompleteOptions().InsertIncludes),
259259
values(
260-
clEnumValN(CodeCompleteOptions::IWYU, "iwyu",
260+
clEnumValN(Config::HeaderInsertionPolicy::IWYU, "iwyu",
261261
"Include what you use. "
262262
"Insert the owning header for top-level symbols, unless the "
263263
"header is already directly included or the symbol is "
264264
"forward-declared"),
265265
clEnumValN(
266-
CodeCompleteOptions::NeverInsert, "never",
266+
Config::HeaderInsertionPolicy::NeverInsert, "never",
267267
"Never insert #include directives as part of code completion")),
268268
};
269269

@@ -668,6 +668,7 @@ class FlagsConfigProvider : public config::Provider {
668668
std::optional<Config::ExternalIndexSpec> IndexSpec;
669669
std::optional<Config::BackgroundPolicy> BGPolicy;
670670
std::optional<Config::ArgumentListsPolicy> ArgumentLists;
671+
std::optional<Config::HeaderInsertionPolicy> HeaderInsertionPolicy;
671672

672673
// If --compile-commands-dir arg was invoked, check value and override
673674
// default path.
@@ -712,6 +713,11 @@ class FlagsConfigProvider : public config::Provider {
712713
BGPolicy = Config::BackgroundPolicy::Skip;
713714
}
714715

716+
// If CLI has set never, use that regardless of what the config files have
717+
if (HeaderInsertion == Config::HeaderInsertionPolicy::NeverInsert) {
718+
HeaderInsertionPolicy = Config::HeaderInsertionPolicy::NeverInsert;
719+
}
720+
715721
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
716722
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
717723
: Config::ArgumentListsPolicy::Delimiters;
@@ -726,6 +732,8 @@ class FlagsConfigProvider : public config::Provider {
726732
C.Index.Background = *BGPolicy;
727733
if (ArgumentLists)
728734
C.Completion.ArgumentLists = *ArgumentLists;
735+
if (HeaderInsertionPolicy)
736+
C.Completion.HeaderInsertion = *HeaderInsertionPolicy;
729737
if (AllScopesCompletion.getNumOccurrences())
730738
C.Completion.AllScopes = AllScopesCompletion;
731739

0 commit comments

Comments
 (0)