Skip to content

Commit 22c845b

Browse files
committed
Merge commit '17d276a6b8c9d9dce7d3317fe56fd3aa4987f0ea' into llvmspirv_pulldown
2 parents 7b5e20d + 17d276a commit 22c845b

File tree

350 files changed

+9027
-3855
lines changed

Some content is hidden

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

350 files changed

+9027
-3855
lines changed

.github/workflows/pr-code-format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install clang-format
2828
uses: aminya/setup-cpp@v1
2929
with:
30-
clangformat: 16.0.6
30+
clangformat: 17.0.1
3131

3232
- name: Setup Python env
3333
uses: actions/setup-python@v4

bolt/lib/Passes/Aligner.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,27 @@ void AlignerPass::runOnFunctions(BinaryContext &BC) {
158158
BinaryContext::IndependentCodeEmitter Emitter =
159159
BC.createIndependentMCCodeEmitter();
160160

161-
if (opts::UseCompactAligner)
162-
alignCompact(BF, Emitter.MCE.get());
163-
else
164-
alignMaxBytes(BF);
165-
166161
// Align objects that contains constant islands and no code
167162
// to at least 8 bytes.
168163
if (!BF.size() && BF.hasIslandsInfo()) {
169-
const uint16_t Alignment = BF.getConstantIslandAlignment();
170-
if (BF.getAlignment() < Alignment)
171-
BF.setAlignment(Alignment);
172-
173-
if (BF.getMaxAlignmentBytes() < Alignment)
174-
BF.setMaxAlignmentBytes(Alignment);
175-
176-
if (BF.getMaxColdAlignmentBytes() < Alignment)
177-
BF.setMaxColdAlignmentBytes(Alignment);
164+
uint16_t Alignment = BF.getConstantIslandAlignment();
165+
// Check if we're forcing output alignment and it is greater than minimal
166+
// CI required one
167+
if (!opts::UseCompactAligner && Alignment < opts::AlignFunctions &&
168+
opts::AlignFunctions <= opts::AlignFunctionsMaxBytes)
169+
Alignment = opts::AlignFunctions;
170+
171+
BF.setAlignment(Alignment);
172+
BF.setMaxAlignmentBytes(Alignment);
173+
BF.setMaxColdAlignmentBytes(Alignment);
174+
return;
178175
}
179176

177+
if (opts::UseCompactAligner)
178+
alignCompact(BF, Emitter.MCE.get());
179+
else
180+
alignMaxBytes(BF);
181+
180182
if (opts::AlignBlocks && !opts::PreserveBlocksAlignment)
181183
alignBlocks(BF, Emitter.MCE.get());
182184
};

bolt/lib/Rewrite/RewriteInstance.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -4720,9 +4720,11 @@ void RewriteInstance::patchELFAllocatableRelrSection(
47204720
const uint8_t PSize = BC->AsmInfo->getCodePointerSize();
47214721
const uint64_t MaxDelta = ((CHAR_BIT * DynamicRelrEntrySize) - 1) * PSize;
47224722

4723-
auto FixAddend = [&](const BinarySection &Section, const Relocation &Rel) {
4723+
auto FixAddend = [&](const BinarySection &Section, const Relocation &Rel,
4724+
uint64_t FileOffset) {
47244725
// Fix relocation symbol value in place if no static relocation found
4725-
// on the same address
4726+
// on the same address. We won't check the BF relocations here since it
4727+
// is rare case and no optimization is required.
47264728
if (Section.getRelocationAt(Rel.Offset))
47274729
return;
47284730

@@ -4731,11 +4733,6 @@ void RewriteInstance::patchELFAllocatableRelrSection(
47314733
if (!Addend)
47324734
return;
47334735

4734-
uint64_t FileOffset = Section.getOutputFileOffset();
4735-
if (!FileOffset)
4736-
FileOffset = Section.getInputFileOffset();
4737-
4738-
FileOffset += Rel.Offset;
47394736
OS.pwrite(reinterpret_cast<const char *>(&Addend), PSize, FileOffset);
47404737
};
47414738

@@ -4757,7 +4754,7 @@ void RewriteInstance::patchELFAllocatableRelrSection(
47574754
RelOffset = RelOffset == 0 ? SectionAddress + Rel.Offset : RelOffset;
47584755
assert((RelOffset & 1) == 0 && "Wrong relocation offset");
47594756
RelOffsets.emplace(RelOffset);
4760-
FixAddend(Section, Rel);
4757+
FixAddend(Section, Rel, RelOffset);
47614758
}
47624759
}
47634760

bolt/test/AArch64/constant_island_pie_update.s

+24-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
// .relr.dyn
1414
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.relr.exe -nostdlib \
1515
# RUN: -Wl,-q -Wl,-z,notext -Wl,--pack-dyn-relocs=relr
16+
# RUN: llvm-objcopy --remove-section .rela.mytext %t.relr.exe
1617
# RUN: llvm-bolt %t.relr.exe -o %t.relr.bolt --use-old-text=0 --lite=0
1718
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.relr.bolt | FileCheck %s
19+
# RUN: llvm-objdump -j .text -d %t.relr.bolt | \
20+
# RUN: FileCheck %s --check-prefix=ADDENDCHECK
1821
# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=ELFCHECK %s
1922
# RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s
2023

@@ -30,6 +33,11 @@
3033
# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
3134
# CHECK-NEXT: {{.*}} .word 0x00000000
3235

36+
// Check that addend was properly patched in mytextP with stripped relocations
37+
# ADDENDCHECK: [[#%x,ADDR:]] <exitLocal>:
38+
# ADDENDCHECK: {{.*}} <mytextP>:
39+
# ADDENDCHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
40+
# ADDENDCHECK-NEXT: {{.*}} .word 0x00000000
3341

3442
// Check that we've relaxed adr to adrp + add to refer external CI
3543
# CHECK: <addressDynCi>:
@@ -40,9 +48,10 @@
4048
# ELFCHECK: [[#%x,OFF:]] [[#%x,INFO_DYN:]] R_AARCH64_RELATIVE
4149
# ELFCHECK-NEXT: [[#OFF + 8]] {{0*}}[[#INFO_DYN]] R_AARCH64_RELATIVE
4250
# ELFCHECK-NEXT: [[#OFF + 24]] {{0*}}[[#INFO_DYN]] R_AARCH64_RELATIVE
51+
# ELFCHECK-NEXT: {{.*}} R_AARCH64_RELATIVE
4352
# ELFCHECK: {{.*}}[[#OFF]] {{.*}} $d
4453

45-
// Check that .relr.dyn size is 2 bytes to ensure that last 2 relocations were
54+
// Check that .relr.dyn size is 2 bytes to ensure that last 3 relocations were
4655
// encoded as a bitmap so the total section size for 3 relocations is 2 bytes.
4756
# RELRSZCHECK: .relr.dyn RELR [[#%x,ADDR:]] [[#%x,OFF:]] {{0*}}10
4857

@@ -81,3 +90,17 @@ addressDynCi:
8190
adr x1, .Lci
8291
bl _start
8392
.size addressDynCi, .-addressDynCi
93+
94+
.section ".mytext", "ax"
95+
.balign 8
96+
.global dummy
97+
.type dummy, %function
98+
dummy:
99+
nop
100+
.word 0
101+
.size dummy, .-dummy
102+
103+
.global mytextP
104+
mytextP:
105+
.xword exitLocal
106+
.size mytextP, .-mytextP

clang-tools-extra/clangd/CodeComplete.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,9 @@ struct CodeCompletionBuilder {
460460
bool IsConcept = false;
461461
if (C.SemaResult) {
462462
getSignature(*SemaCCS, &S.Signature, &S.SnippetSuffix, C.SemaResult->Kind,
463-
C.SemaResult->CursorKind, &Completion.RequiredQualifier);
464-
if (!C.SemaResult->FunctionCanBeCall)
465-
S.SnippetSuffix.clear();
463+
C.SemaResult->CursorKind,
464+
/*IncludeFunctionArguments=*/C.SemaResult->FunctionCanBeCall,
465+
/*RequiredQualifiers=*/&Completion.RequiredQualifier);
466466
S.ReturnType = getReturnType(*SemaCCS);
467467
if (C.SemaResult->Kind == CodeCompletionResult::RK_Declaration)
468468
if (const auto *D = C.SemaResult->getDeclaration())

clang-tools-extra/clangd/CodeCompletionStrings.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/AST/RawCommentList.h"
1313
#include "clang/Basic/SourceManager.h"
1414
#include "clang/Sema/CodeCompleteConsumer.h"
15+
#include "llvm/Support/Compiler.h"
1516
#include "llvm/Support/JSON.h"
1617
#include <limits>
1718
#include <utility>
@@ -118,7 +119,8 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
118119
void getSignature(const CodeCompletionString &CCS, std::string *Signature,
119120
std::string *Snippet,
120121
CodeCompletionResult::ResultKind ResultKind,
121-
CXCursorKind CursorKind, std::string *RequiredQualifiers) {
122+
CXCursorKind CursorKind, bool IncludeFunctionArguments,
123+
std::string *RequiredQualifiers) {
122124
// Placeholder with this index will be $0 to mark final cursor position.
123125
// Usually we do not add $0, so the cursor is placed at end of completed text.
124126
unsigned CursorSnippetArg = std::numeric_limits<unsigned>::max();
@@ -138,6 +140,8 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
138140
unsigned SnippetArg = 0;
139141
bool HadObjCArguments = false;
140142
bool HadInformativeChunks = false;
143+
144+
std::optional<unsigned> TruncateSnippetAt;
141145
for (const auto &Chunk : CCS) {
142146
// Informative qualifier chunks only clutter completion results, skip
143147
// them.
@@ -243,6 +247,13 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
243247
"CompletionItems");
244248
break;
245249
case CodeCompletionString::CK_LeftParen:
250+
// We're assuming that a LeftParen in a declaration starts a function
251+
// call, and arguments following the parenthesis could be discarded if
252+
// IncludeFunctionArguments is false.
253+
if (!IncludeFunctionArguments &&
254+
ResultKind == CodeCompletionResult::RK_Declaration)
255+
TruncateSnippetAt.emplace(Snippet->size());
256+
LLVM_FALLTHROUGH;
246257
case CodeCompletionString::CK_RightParen:
247258
case CodeCompletionString::CK_LeftBracket:
248259
case CodeCompletionString::CK_RightBracket:
@@ -264,6 +275,8 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
264275
break;
265276
}
266277
}
278+
if (TruncateSnippetAt)
279+
*Snippet = Snippet->substr(0, *TruncateSnippetAt);
267280
}
268281

269282
std::string formatDocumentation(const CodeCompletionString &CCS,

clang-tools-extra/clangd/CodeCompletionStrings.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D);
4242
/// If set, RequiredQualifiers is the text that must be typed before the name.
4343
/// e.g "Base::" when calling a base class member function that's hidden.
4444
///
45+
/// If \p IncludeFunctionArguments is disabled, the \p Snippet will only
46+
/// contain function name and template arguments, if any.
47+
///
4548
/// When \p ResultKind is RK_Pattern, the last placeholder will be $0,
4649
/// indicating the cursor should stay there.
4750
/// Note that for certain \p CursorKind like \p CXCursor_Constructor, $0 won't
4851
/// be emitted in order to avoid overlapping normal parameters.
4952
void getSignature(const CodeCompletionString &CCS, std::string *Signature,
5053
std::string *Snippet,
5154
CodeCompletionResult::ResultKind ResultKind,
52-
CXCursorKind CursorKind,
55+
CXCursorKind CursorKind, bool IncludeFunctionArguments = true,
5356
std::string *RequiredQualifiers = nullptr);
5457

5558
/// Assembles formatted documentation for a completion result. This includes

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

+53-15
Original file line numberDiff line numberDiff line change
@@ -530,54 +530,92 @@ TEST(CompletionTest, HeuristicsForMemberFunctionCompletion) {
530530

531531
Annotations Code(R"cpp(
532532
struct Foo {
533-
static int staticMethod();
534-
int method() const;
533+
static int staticMethod(int);
534+
int method(int) const;
535+
template <typename T, typename U, typename V = int>
536+
T generic(U, V);
537+
template <typename T, int U>
538+
static T staticGeneric();
535539
Foo() {
536-
this->$keepSnippet^
537-
$keepSnippet^
538-
Foo::$keepSnippet^
540+
this->$canBeCall^
541+
$canBeCall^
542+
Foo::$canBeCall^
539543
}
540544
};
541545
542546
struct Derived : Foo {
547+
using Foo::method;
548+
using Foo::generic;
543549
Derived() {
544-
Foo::$keepSnippet^
550+
Foo::$canBeCall^
545551
}
546552
};
547553
548554
struct OtherClass {
549555
OtherClass() {
550556
Foo f;
551-
f.$keepSnippet^
552-
&Foo::$noSnippet^
557+
Derived d;
558+
f.$canBeCall^
559+
; // Prevent parsing as 'f.f'
560+
f.Foo::$canBeCall^
561+
&Foo::$canNotBeCall^
562+
;
563+
d.Foo::$canBeCall^
564+
;
565+
d.Derived::$canBeCall^
553566
}
554567
};
555568
556569
int main() {
557570
Foo f;
558-
f.$keepSnippet^
559-
&Foo::$noSnippet^
571+
Derived d;
572+
f.$canBeCall^
573+
; // Prevent parsing as 'f.f'
574+
f.Foo::$canBeCall^
575+
&Foo::$canNotBeCall^
576+
;
577+
d.Foo::$canBeCall^
578+
;
579+
d.Derived::$canBeCall^
560580
}
561581
)cpp");
562582
auto TU = TestTU::withCode(Code.code());
563583

564-
for (const auto &P : Code.points("noSnippet")) {
584+
for (const auto &P : Code.points("canNotBeCall")) {
565585
auto Results = completions(TU, P, /*IndexSymbols*/ {}, Opts);
566586
EXPECT_THAT(Results.Completions,
567-
Contains(AllOf(named("method"), snippetSuffix(""))));
587+
Contains(AllOf(named("method"), signature("(int) const"),
588+
snippetSuffix(""))));
589+
// We don't have any arguments to deduce against if this isn't a call.
590+
// Thus, we should emit these deducible template arguments explicitly.
591+
EXPECT_THAT(
592+
Results.Completions,
593+
Contains(AllOf(named("generic"),
594+
signature("<typename T, typename U>(U, V)"),
595+
snippetSuffix("<${1:typename T}, ${2:typename U}>"))));
568596
}
569597

570-
for (const auto &P : Code.points("keepSnippet")) {
598+
for (const auto &P : Code.points("canBeCall")) {
571599
auto Results = completions(TU, P, /*IndexSymbols*/ {}, Opts);
572600
EXPECT_THAT(Results.Completions,
573-
Contains(AllOf(named("method"), snippetSuffix("()"))));
601+
Contains(AllOf(named("method"), signature("(int) const"),
602+
snippetSuffix("(${1:int})"))));
603+
EXPECT_THAT(
604+
Results.Completions,
605+
Contains(AllOf(named("generic"), signature("<typename T>(U, V)"),
606+
snippetSuffix("<${1:typename T}>(${2:U}, ${3:V})"))));
574607
}
575608

576609
// static method will always keep the snippet
577610
for (const auto &P : Code.points()) {
578611
auto Results = completions(TU, P, /*IndexSymbols*/ {}, Opts);
579612
EXPECT_THAT(Results.Completions,
580-
Contains(AllOf(named("staticMethod"), snippetSuffix("()"))));
613+
Contains(AllOf(named("staticMethod"), signature("(int)"),
614+
snippetSuffix("(${1:int})"))));
615+
EXPECT_THAT(Results.Completions,
616+
Contains(AllOf(
617+
named("staticGeneric"), signature("<typename T, int U>()"),
618+
snippetSuffix("<${1:typename T}, ${2:int U}>()"))));
581619
}
582620
}
583621

clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ class CompletionStringTest : public ::testing::Test {
2525
protected:
2626
void computeSignature(const CodeCompletionString &CCS,
2727
CodeCompletionResult::ResultKind ResultKind =
28-
CodeCompletionResult::ResultKind::RK_Declaration) {
28+
CodeCompletionResult::ResultKind::RK_Declaration,
29+
bool IncludeFunctionArguments = true) {
2930
Signature.clear();
3031
Snippet.clear();
3132
getSignature(CCS, &Signature, &Snippet, ResultKind,
3233
/*CursorKind=*/CXCursorKind::CXCursor_NotImplemented,
34+
/*IncludeFunctionArguments=*/IncludeFunctionArguments,
3335
/*RequiredQualifiers=*/nullptr);
3436
}
3537

@@ -156,6 +158,28 @@ TEST_F(CompletionStringTest, SnippetsInPatterns) {
156158
EXPECT_EQ(Snippet, " ${1:name} = $0;");
157159
}
158160

161+
TEST_F(CompletionStringTest, DropFunctionArguments) {
162+
Builder.AddTypedTextChunk("foo");
163+
Builder.AddChunk(CodeCompletionString::CK_LeftAngle);
164+
Builder.AddPlaceholderChunk("typename T");
165+
Builder.AddChunk(CodeCompletionString::CK_Comma);
166+
Builder.AddPlaceholderChunk("int U");
167+
Builder.AddChunk(CodeCompletionString::CK_RightAngle);
168+
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
169+
Builder.AddPlaceholderChunk("arg1");
170+
Builder.AddChunk(CodeCompletionString::CK_Comma);
171+
Builder.AddPlaceholderChunk("arg2");
172+
Builder.AddChunk(CodeCompletionString::CK_RightParen);
173+
174+
computeSignature(
175+
*Builder.TakeString(),
176+
/*ResultKind=*/CodeCompletionResult::ResultKind::RK_Declaration,
177+
/*IncludeFunctionArguments=*/false);
178+
// Arguments dropped from snippet, kept in signature.
179+
EXPECT_EQ(Signature, "<typename T, int U>(arg1, arg2)");
180+
EXPECT_EQ(Snippet, "<${1:typename T}, ${2:int U}>");
181+
}
182+
159183
TEST_F(CompletionStringTest, IgnoreInformativeQualifier) {
160184
Builder.AddTypedTextChunk("X");
161185
Builder.AddInformativeChunk("info ok");

clang/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ Bug Fixes to C++ Support
359359
reference. Fixes:
360360
(`#64162 <https://github.com/llvm/llvm-project/issues/64162>`_)
361361

362+
- Clang no longer tries to capture non-odr-used variables that appear
363+
in the enclosing expression of a lambda expression with a noexcept specifier.
364+
(`#67492 <https://github.com/llvm/llvm-project/issues/67492>`_)
365+
362366
Bug Fixes to AST Handling
363367
^^^^^^^^^^^^^^^^^^^^^^^^^
364368
- Fixed an import failure of recursive friend class template.

0 commit comments

Comments
 (0)