Skip to content

Commit bc215a1

Browse files
author
Yi Wu
committed
Merge branch 'main' into fdate
2 parents 510ada5 + 1256d1d commit bc215a1

File tree

696 files changed

+23794
-14664
lines changed

Some content is hidden

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

696 files changed

+23794
-14664
lines changed

.github/new-prs-labeler.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
clang:dataflow:
2-
- clang/**/Analysis/**/*
2+
- clang/include/clang/Analysis/FlowSensitive/**/*
3+
- clang/lib/Analysis/FlowSensitive/**/*
4+
- clang/unittests/Analysis/FlowSensitive/**/*
5+
- clang/docs/DataFlowAnalysisIntro.md
6+
- clang/docs/DataFlowAnalysisIntroImages/**/*
37

48
clang:frontend:
59
- clang/lib/AST/**/*

.github/workflows/issue-subscriber.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
steps:
1616
- name: Setup Automation Script
1717
run: |
18-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/"$GITHUB_SHA"/llvm/utils/git/github-automation.py
19-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/"$GITHUB_SHA"/llvm/utils/git/requirements.txt
18+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/"$GITHUB_SHA"/llvm/utils/git/github-automation.py
19+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/"$GITHUB_SHA"/llvm/utils/git/requirements.txt
2020
chmod a+x github-automation.py
2121
pip install -r requirements.txt
2222

.github/workflows/pr-subscriber.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ jobs:
1515
steps:
1616
- name: Setup Automation Script
1717
run: |
18-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
19-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
20-
curl -O -L https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/.github/workflows/pr-subscriber-wait.py
18+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
19+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
2120
chmod a+x github-automation.py
2221
pip install -r requirements.txt
2322

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@ class BinaryContext {
12391239
uint64_t
12401240
computeInstructionSize(const MCInst &Inst,
12411241
const MCCodeEmitter *Emitter = nullptr) const {
1242-
if (auto Size = MIB->getAnnotationWithDefault<uint32_t>(Inst, "Size"))
1243-
return Size;
1242+
if (std::optional<uint32_t> Size = MIB->getSize(Inst))
1243+
return *Size;
12441244

12451245
if (!Emitter)
12461246
Emitter = this->MCE.get();

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ class BinaryFunction {
12961296
/// Return true if the function body is non-contiguous.
12971297
bool isSplit() const { return isSimple() && getLayout().isSplit(); }
12981298

1299-
bool shouldPreserveNops() const { return PreserveNops; }
1299+
bool shouldPreserveNops() const;
13001300

13011301
/// Return true if the function has exception handling tables.
13021302
bool hasEHRanges() const { return HasEHRanges; }

bolt/include/bolt/Core/MCPlus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class MCAnnotation {
7272
kConditionalTailCall, /// CTC.
7373
kOffset, /// Offset in the function.
7474
kLabel, /// MCSymbol pointing to this instruction.
75+
kSize, /// Size of the instruction.
7576
kGeneric /// First generic annotation.
7677
};
7778

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,12 @@ class MCPlusBuilder {
11791179
/// is emitted to MCStreamer.
11801180
bool setLabel(MCInst &Inst, MCSymbol *Label) const;
11811181

1182+
/// Get instruction size specified via annotation.
1183+
std::optional<uint32_t> getSize(const MCInst &Inst) const;
1184+
1185+
/// Set instruction size.
1186+
void setSize(MCInst &Inst, uint32_t Size) const;
1187+
11821188
/// Return MCSymbol that represents a target of this instruction at a given
11831189
/// operand number \p OpNum. If there's no symbol associated with
11841190
/// the operand - return nullptr.

bolt/lib/Core/BinaryContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,8 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
18971897
}
18981898
if (std::optional<uint32_t> Offset = MIB->getOffset(Instruction))
18991899
OS << " # Offset: " << *Offset;
1900+
if (std::optional<uint32_t> Size = MIB->getSize(Instruction))
1901+
OS << " # Size: " << *Size;
19001902
if (MCSymbol *Label = MIB->getLabel(Instruction))
19011903
OS << " # Label: " << *Label;
19021904

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
507507
Streamer.emitLabel(InstrLabel);
508508
}
509509

510+
// Emit sized NOPs via MCAsmBackend::writeNopData() interface on x86.
511+
// This is a workaround for invalid NOPs handling by asm/disasm layer.
512+
if (BC.MIB->isNoop(Instr) && BC.isX86()) {
513+
if (std::optional<uint32_t> Size = BC.MIB->getSize(Instr)) {
514+
SmallString<15> Code;
515+
raw_svector_ostream VecOS(Code);
516+
BC.MAB->writeNopData(VecOS, *Size, BC.STI.get());
517+
Streamer.emitBytes(Code);
518+
continue;
519+
}
520+
}
521+
510522
Streamer.emitInstruction(Instr, *BC.STI);
511523
LastIsPrefix = BC.MIB->isPrefix(Instr);
512524
}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern cl::OptionCategory BoltRelocCategory;
5858

5959
extern cl::opt<bool> EnableBAT;
6060
extern cl::opt<bool> Instrument;
61+
extern cl::opt<bool> KeepNops;
6162
extern cl::opt<bool> StrictMode;
6263
extern cl::opt<bool> UpdateDebugSections;
6364
extern cl::opt<unsigned> Verbosity;
@@ -1380,7 +1381,7 @@ bool BinaryFunction::disassemble() {
13801381
// NOTE: disassembly loses the correct size information for noops on x86.
13811382
// E.g. nopw 0x0(%rax,%rax,1) is 9 bytes, but re-encoded it's only
13821383
// 5 bytes. Preserve the size info using annotations.
1383-
MIB->addAnnotation(Instruction, "Size", static_cast<uint32_t>(Size));
1384+
MIB->setSize(Instruction, Size);
13841385
}
13851386

13861387
addInstruction(Offset, std::move(Instruction));
@@ -4353,10 +4354,11 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) {
43534354
}
43544355

43554356
if (MCInst *LastInstr = BB->getLastNonPseudoInstr()) {
4356-
const uint32_t Size =
4357-
BC.MIB->getAnnotationWithDefault<uint32_t>(*LastInstr, "Size");
4358-
if (BB->getEndOffset() - Offset == Size)
4359-
return LastInstr;
4357+
if (std::optional<uint32_t> Size = BC.MIB->getSize(*LastInstr)) {
4358+
if (BB->getEndOffset() - Offset == Size) {
4359+
return LastInstr;
4360+
}
4361+
}
43604362
}
43614363

43624364
return nullptr;
@@ -4365,6 +4367,10 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) {
43654367
}
43664368
}
43674369

4370+
bool BinaryFunction::shouldPreserveNops() const {
4371+
return PreserveNops || opts::KeepNops;
4372+
}
4373+
43684374
void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
43694375
if (!opts::shouldPrint(*this))
43704376
return;

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) const {
279279
return true;
280280
}
281281

282+
std::optional<uint32_t> MCPlusBuilder::getSize(const MCInst &Inst) const {
283+
if (std::optional<int64_t> Value =
284+
getAnnotationOpValue(Inst, MCAnnotation::kSize))
285+
return static_cast<uint32_t>(*Value);
286+
return std::nullopt;
287+
}
288+
289+
void MCPlusBuilder::setSize(MCInst &Inst, uint32_t Size) const {
290+
setAnnotationOpValue(Inst, MCAnnotation::kSize, Size);
291+
}
292+
282293
bool MCPlusBuilder::hasAnnotation(const MCInst &Inst, unsigned Index) const {
283294
return (bool)getAnnotationOpValue(Inst, Index);
284295
}

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,15 @@ void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
608608
std::optional<uint32_t> Offset = BF->requiresAddressTranslation()
609609
? BC.MIB->getOffset(*II)
610610
: std::nullopt;
611+
std::optional<uint32_t> Size = BC.MIB->getSize(*II);
611612
MCSymbol *Label = BC.MIB->getLabel(*II);
612613

613614
BC.MIB->stripAnnotations(*II);
614615

615616
if (Offset)
616617
BC.MIB->setOffset(*II, *Offset);
618+
if (Size)
619+
BC.MIB->setSize(*II, *Size);
617620
if (Label)
618621
BC.MIB->setLabel(*II, Label);
619622
}

bolt/lib/Profile/DataReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ bool DataReader::recordBranch(BinaryFunction &BF, uint64_t From, uint64_t To,
698698
if (!BC.MIB->isNoop(Instr))
699699
break;
700700

701-
Offset += BC.MIB->getAnnotationWithDefault<uint32_t>(Instr, "Size");
701+
if (std::optional<uint32_t> Size = BC.MIB->getSize(Instr))
702+
Offset += *Size;
702703
}
703704

704705
if (To == Offset)

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,6 @@ void RewriteInstance::buildFunctionsCFG() {
32123212
// Create annotation indices to allow lock-free execution
32133213
BC->MIB->getOrCreateAnnotationIndex("JTIndexReg");
32143214
BC->MIB->getOrCreateAnnotationIndex("NOP");
3215-
BC->MIB->getOrCreateAnnotationIndex("Size");
32163215

32173216
ParallelUtilities::WorkFuncWithAllocTy WorkFun =
32183217
[&](BinaryFunction &BF, MCPlusBuilder::AllocatorIdTy AllocId) {

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ cl::opt<bool>
129129
cl::desc("instrument code to generate accurate profile data"),
130130
cl::cat(BoltOptCategory));
131131

132+
cl::opt<bool>
133+
KeepNops("keep-nops",
134+
cl::desc("keep no-op instructions. By default they are removed."),
135+
cl::Hidden, cl::cat(BoltOptCategory));
136+
132137
cl::opt<std::string>
133138
OutputFilename("o",
134139
cl::desc("<output file>"),

bolt/test/X86/keep-nops.s

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Check that BOLT preserves NOP instructions of different sizes correctly.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
6+
# RUN: ld.lld %t.o -o %t.exe -q
7+
# RUN: llvm-bolt %t.exe -o %t.bolt.exe --keep-nops --relocs --print-finalized \
8+
# RUN: |& FileCheck --check-prefix=CHECK-BOLT %s
9+
# RUN: llvm-objdump -d %t.bolt.exe | FileCheck %s
10+
11+
.text
12+
.globl _start
13+
.type _start,@function
14+
_start:
15+
.cfi_startproc
16+
.nops 1
17+
.nops 2
18+
.nops 3
19+
.nops 4
20+
.nops 5
21+
.nops 6
22+
.nops 7
23+
.nops 8
24+
.nops 9
25+
.nops 10
26+
.nops 11
27+
.nops 12
28+
.nops 13
29+
.nops 14
30+
.nops 15
31+
32+
# CHECK: <_start>:
33+
# CHECK-NEXT: 90
34+
# CHECK-NEXT: 66 90
35+
# CHECK-NEXT: 0f 1f 00
36+
# CHECK-NEXT: 0f 1f 40 00
37+
# CHECK-NEXT: 0f 1f 44 00 00
38+
# CHECK-NEXT: 66 0f 1f 44 00 00
39+
# CHECK-NEXT: 0f 1f 80 00 00 00 00
40+
# CHECK-NEXT: 0f 1f 84 00 00 00 00 00
41+
# CHECK-NEXT: 66 0f 1f 84 00 00 00 00 00
42+
# CHECK-NEXT: 66 2e 0f 1f 84 00 00 00 00 00
43+
# CHECK-NEXT: 66 66 2e 0f 1f 84 00 00 00 00 00
44+
# CHECK-NEXT: 66 66 66 2e 0f 1f 84 00 00 00 00 00
45+
# CHECK-NEXT: 66 66 66 66 2e 0f 1f 84 00 00 00 00 00
46+
# CHECK-NEXT: 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00
47+
# CHECK-NEXT: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00
48+
49+
# CHECK-BOLT: Size: 1
50+
# CHECK-BOLT-NEXT: Size: 2
51+
# CHECK-BOLT-NEXT: Size: 3
52+
# CHECK-BOLT-NEXT: Size: 4
53+
# CHECK-BOLT-NEXT: Size: 5
54+
# CHECK-BOLT-NEXT: Size: 6
55+
# CHECK-BOLT-NEXT: Size: 7
56+
# CHECK-BOLT-NEXT: Size: 8
57+
# CHECK-BOLT-NEXT: Size: 9
58+
# CHECK-BOLT-NEXT: Size: 10
59+
# CHECK-BOLT-NEXT: Size: 11
60+
# CHECK-BOLT-NEXT: Size: 12
61+
# CHECK-BOLT-NEXT: Size: 13
62+
# CHECK-BOLT-NEXT: Size: 14
63+
# CHECK-BOLT-NEXT: Size: 15
64+
65+
# Needed for relocation mode.
66+
.reloc 0, R_X86_64_NONE
67+
68+
.size _start, .-_start
69+
.cfi_endproc

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
668668
{"bits/syslog-path.h", "<sys/syslog.h>"},
669669
{"bits/termios.h", "<termios.h>"},
670670
{"bits/types.h", "<sys/types.h>"},
671+
{"bits/types/siginfo_t.h", "<sys/siginfo.h>"},
672+
{"bits/types/struct_itimerspec.h", "<sys/time.h>"},
671673
{"bits/uio.h", "<sys/uio.h>"},
672674
{"bits/ustat.h", "<sys/ustat.h>"},
673675
{"bits/utmp.h", "<utmp.h>"},

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "clang/AST/ASTFwd.h"
1212
#include "clang/AST/Decl.h"
1313
#include "clang/AST/DeclCXX.h"
14+
#include "clang/AST/DeclFriend.h"
1415
#include "clang/AST/DeclTemplate.h"
1516
#include "clang/AST/Expr.h"
1617
#include "clang/AST/ExprCXX.h"
@@ -243,6 +244,14 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
243244
return true;
244245
}
245246

247+
bool VisitFriendDecl(FriendDecl *D) {
248+
// We already visit the TypeLoc properly, but need to special case the decl
249+
// case.
250+
if (auto *FD = D->getFriendDecl())
251+
report(D->getLocation(), FD);
252+
return true;
253+
}
254+
246255
bool VisitConceptReference(const ConceptReference *CR) {
247256
report(CR->getConceptNameLoc(), CR->getFoundDecl());
248257
return true;

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,5 +550,10 @@ TEST(WalkAST, Concepts) {
550550
// FIXME: Foo should be explicitly referenced.
551551
testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }");
552552
}
553+
554+
TEST(WalkAST, FriendDecl) {
555+
testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };");
556+
testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };");
557+
}
553558
} // namespace
554559
} // namespace clang::include_cleaner

clang/docs/AutomaticReferenceCounting.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,21 @@ and non-ownership qualification.
839839
object lvalue.
840840

841841
* For ``__weak`` objects, the current pointee is retained and then released at
842-
the end of the current full-expression. This must execute atomically with
843-
respect to assignments and to the final release of the pointee.
842+
the end of the current full-expression. In particular, messaging a ``__weak``
843+
object keeps the object retained until the end of the full expression.
844+
845+
.. code-block:: objc
846+
847+
__weak MyObject *weakObj;
848+
849+
void foo() {
850+
// weakObj is retained before the message send and released at the end of
851+
// the full expression.
852+
[weakObj m];
853+
}
854+
855+
This must execute atomically with respect to assignments and to the final
856+
release of the pointee.
844857
* For all other objects, the lvalue is loaded with primitive semantics.
845858

846859
:arc-term:`Assignment` occurs when evaluating an assignment operator. The

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ Miscellaneous Clang Crashes Fixed
726726
(`#68001 <https://github.com/llvm/llvm-project/pull/68001>`_)
727727
- Fixed a crash in C when redefined struct is another nested redefinition.
728728
`Issue 41302 <https://github.com/llvm/llvm-project/issues/41302>`_
729+
- Fixed a crash when ``-ast-dump=json`` was used for code using class
730+
template deduction guides.
729731

730732
Target Specific Changes
731733
-----------------------

clang/include/clang/APINotes/APINotesYAMLCompiler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@
1010
#define LLVM_CLANG_APINOTES_APINOTESYAMLCOMPILER_H
1111

1212
#include "llvm/ADT/StringRef.h"
13+
#include "llvm/Support/SourceMgr.h"
1314
#include "llvm/Support/raw_ostream.h"
1415

16+
namespace clang {
17+
class FileEntry;
18+
} // namespace clang
19+
1520
namespace clang {
1621
namespace api_notes {
1722
/// Parses the APINotes YAML content and writes the representation back to the
1823
/// specified stream. This provides a means of testing the YAML processing of
1924
/// the APINotes format.
2025
bool parseAndDumpAPINotes(llvm::StringRef YI, llvm::raw_ostream &OS);
26+
27+
/// Converts API notes from YAML format to binary format.
28+
bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile,
29+
llvm::raw_ostream &OS,
30+
llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
31+
void *DiagHandlerCtxt = nullptr);
2132
} // namespace api_notes
2233
} // namespace clang
2334

clang/include/clang/APINotes/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ struct Context {
766766
/// data they contain; it is up to the user to ensure that the data
767767
/// referenced by the identifier list persists.
768768
struct ObjCSelectorRef {
769+
unsigned NumArgs;
769770
llvm::ArrayRef<llvm::StringRef> Identifiers;
770771
};
771772
} // namespace api_notes

0 commit comments

Comments
 (0)