Skip to content

Commit 2ec9940

Browse files
committed
Merge from 'main' to 'sycl-web' (207 commits)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGOpenCLRuntime.cpp
2 parents 52014cb + c66844d commit 2ec9940

File tree

879 files changed

+28780
-16691
lines changed

Some content is hidden

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

879 files changed

+28780
-16691
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/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: 7 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;

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/BinaryPassManager.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ static cl::opt<bool> JTFootprintReductionFlag(
7272
"instructions at jump sites"),
7373
cl::cat(BoltOptCategory));
7474

75+
static cl::opt<bool>
76+
KeepNops("keep-nops",
77+
cl::desc("keep no-op instructions. By default they are removed."),
78+
cl::Hidden, cl::cat(BoltOptCategory));
79+
7580
cl::opt<bool> NeverPrint("never-print", cl::desc("never print"),
7681
cl::ReallyHidden, cl::cat(BoltOptCategory));
7782

@@ -359,7 +364,8 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
359364

360365
Manager.registerPass(std::make_unique<ShortenInstructions>(NeverPrint));
361366

362-
Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint));
367+
Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint),
368+
!opts::KeepNops);
363369

364370
Manager.registerPass(std::make_unique<NormalizeCFG>(PrintNormalized));
365371

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/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/clang-tidy/abseil/StringFindStartswithCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ using namespace clang::ast_matchers;
1919

2020
namespace clang::tidy::abseil {
2121

22+
const auto DefaultStringLikeClasses =
23+
"::std::basic_string;::std::basic_string_view";
24+
2225
StringFindStartswithCheck::StringFindStartswithCheck(StringRef Name,
2326
ClangTidyContext *Context)
2427
: ClangTidyCheck(Name, Context),
2528
StringLikeClasses(utils::options::parseStringList(
26-
Options.get("StringLikeClasses", "::std::basic_string"))),
29+
Options.get("StringLikeClasses", DefaultStringLikeClasses))),
2730
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
2831
utils::IncludeSorter::IS_LLVM),
2932
areDiagsSelfContained()),

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
152152
return "false";
153153
}
154154

155-
if (const auto *IntLit = dyn_cast<IntegerLiteral>(Expression)) {
155+
if (const auto *IntLit =
156+
dyn_cast<IntegerLiteral>(Expression->IgnoreParens())) {
156157
return (IntLit->getValue() == 0) ? "false" : "true";
157158
}
158159

@@ -385,7 +386,7 @@ void ImplicitBoolConversionCheck::handleCastFromBool(
385386
<< DestType;
386387

387388
if (const auto *BoolLiteral =
388-
dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr())) {
389+
dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr()->IgnoreParens())) {
389390
Diag << tooling::fixit::createReplacement(
390391
*Cast, getEquivalentForBoolLiteral(BoolLiteral, DestType, Context));
391392
} else {

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/docs/ReleaseNotes.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ New check aliases
208208
Changes in existing checks
209209
^^^^^^^^^^^^^^^^^^^^^^^^^^
210210

211+
- Improved :doc:`abseil-string-find-startswith
212+
<clang-tidy/checks/abseil/string-find-startswith>` check to also consider
213+
``std::basic_string_view`` in addition to ``std::basic_string`` by default.
214+
211215
- Improved :doc:`bugprone-dangling-handle
212216
<clang-tidy/checks/bugprone/dangling-handle>` check to support functional
213217
casting during type conversions at variable initialization, now with improved
@@ -315,7 +319,9 @@ Changes in existing checks
315319

316320
- Improved :doc:`misc-const-correctness
317321
<clang-tidy/checks/misc/const-correctness>` check to avoid false positive when
318-
using pointer to member function.
322+
using pointer to member function. Additionally, the check no longer emits
323+
a diagnostic when a variable that is not type-dependent is an operand of a
324+
type-dependent binary operator.
319325

320326
- Improved :doc:`misc-include-cleaner
321327
<clang-tidy/checks/misc/include-cleaner>` check by adding option
@@ -410,7 +416,8 @@ Changes in existing checks
410416
- Improved :doc:`readability-implicit-bool-conversion
411417
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
412418
do-while loops into account for the `AllowIntegerConditions` and
413-
`AllowPointerConditions` options.
419+
`AllowPointerConditions` options. It also now provides more consistent
420+
suggestions when parentheses are added to the return value.
414421

415422
- Improved :doc:`readability-non-const-parameter
416423
<clang-tidy/checks/readability/non-const-parameter>` check to ignore

clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
abseil-string-find-startswith
44
=============================
55

6-
Checks whether a ``std::string::find()`` or ``std::string::rfind()`` result is
7-
compared with 0, and suggests replacing with ``absl::StartsWith()``. This is
8-
both a readability and performance issue.
6+
Checks whether a ``std::string::find()`` or ``std::string::rfind()`` (and
7+
corresponding ``std::string_view`` methods) result is compared with 0, and
8+
suggests replacing with ``absl::StartsWith()``. This is both a readability and
9+
performance issue.
910

1011
.. code-block:: c++
1112

@@ -28,9 +29,9 @@ Options
2829

2930
.. option:: StringLikeClasses
3031

31-
Semicolon-separated list of names of string-like classes. By default only
32-
``std::basic_string`` is considered. The list of methods to considered is
33-
fixed.
32+
Semicolon-separated list of names of string-like classes. By default both
33+
``std::basic_string`` and ``std::basic_string_view`` are considered. The list
34+
of methods to be considered is fixed.
3435

3536
.. option:: IncludeStyle
3637

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;

0 commit comments

Comments
 (0)