Skip to content

Commit 81b8f19

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (173 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/OffloadBundler.cpp
2 parents 979d056 + 61b13e0 commit 81b8f19

File tree

997 files changed

+20127
-7754
lines changed

Some content is hidden

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

997 files changed

+20127
-7754
lines changed

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

+70-35
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ class LinuxKernelRewriter final : public MetadataRewriter {
157157
/// Alignment of paravirtual patch structures.
158158
static constexpr size_t PARA_PATCH_ALIGN = 8;
159159

160+
/// Section containing Linux bug table.
161+
ErrorOr<BinarySection &> BugTableSection = std::errc::bad_address;
162+
163+
/// Size of bug_entry struct.
164+
static constexpr size_t BUG_TABLE_ENTRY_SIZE = 12;
165+
160166
/// Insert an LKMarker for a given code pointer \p PC from a non-code section
161167
/// \p SectionName.
162168
void insertLKMarker(uint64_t PC, uint64_t SectionOffset,
@@ -172,9 +178,6 @@ class LinuxKernelRewriter final : public MetadataRewriter {
172178
/// Process __ksymtab and __ksymtab_gpl.
173179
void processLKKSymtab(bool IsGPL = false);
174180

175-
/// Process special linux kernel section, __bug_table.
176-
void processLKBugTable();
177-
178181
/// Process special linux kernel section, .smp_locks.
179182
void processLKSMPLocks();
180183

@@ -200,6 +203,8 @@ class LinuxKernelRewriter final : public MetadataRewriter {
200203
/// Paravirtual instruction patch sites.
201204
Error readParaInstructions();
202205

206+
Error readBugTable();
207+
203208
/// Mark instructions referenced by kernel metadata.
204209
Error markInstructions();
205210

@@ -224,6 +229,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
224229
if (Error E = readParaInstructions())
225230
return E;
226231

232+
if (Error E = readBugTable())
233+
return E;
234+
227235
return Error::success();
228236
}
229237

@@ -289,7 +297,6 @@ void LinuxKernelRewriter::processLKSections() {
289297
processLKPCIFixup();
290298
processLKKSymtab();
291299
processLKKSymtab(true);
292-
processLKBugTable();
293300
processLKSMPLocks();
294301
}
295302

@@ -356,37 +363,6 @@ void LinuxKernelRewriter::processLKKSymtab(bool IsGPL) {
356363
}
357364
}
358365

359-
/// Process __bug_table section.
360-
/// This section contains information useful for kernel debugging.
361-
/// Each entry in the section is a struct bug_entry that contains a pointer to
362-
/// the ud2 instruction corresponding to the bug, corresponding file name (both
363-
/// pointers use PC relative offset addressing), line number, and flags.
364-
/// The definition of the struct bug_entry can be found in
365-
/// `include/asm-generic/bug.h`
366-
void LinuxKernelRewriter::processLKBugTable() {
367-
ErrorOr<BinarySection &> SectionOrError =
368-
BC.getUniqueSectionByName("__bug_table");
369-
if (!SectionOrError)
370-
return;
371-
372-
const uint64_t SectionSize = SectionOrError->getSize();
373-
const uint64_t SectionAddress = SectionOrError->getAddress();
374-
assert((SectionSize % 12) == 0 &&
375-
"The size of the __bug_table section should be a multiple of 12");
376-
for (uint64_t I = 0; I < SectionSize; I += 12) {
377-
const uint64_t EntryAddress = SectionAddress + I;
378-
ErrorOr<uint64_t> Offset = BC.getSignedValueAtAddress(EntryAddress, 4);
379-
assert(Offset &&
380-
"Reading valid PC-relative offset for a __bug_table entry");
381-
const int32_t SignedOffset = *Offset;
382-
const uint64_t RefAddress = EntryAddress + SignedOffset;
383-
assert(BC.getBinaryFunctionContainingAddress(RefAddress) &&
384-
"__bug_table entries should point to a function");
385-
386-
insertLKMarker(RefAddress, I, SignedOffset, true, "__bug_table");
387-
}
388-
}
389-
390366
/// .smp_locks section contains PC-relative references to instructions with LOCK
391367
/// prefix. The prefix can be converted to NOP at boot time on non-SMP systems.
392368
void LinuxKernelRewriter::processLKSMPLocks() {
@@ -1097,6 +1073,65 @@ Error LinuxKernelRewriter::readParaInstructions() {
10971073
return Error::success();
10981074
}
10991075

1076+
/// Process __bug_table section.
1077+
/// This section contains information useful for kernel debugging.
1078+
/// Each entry in the section is a struct bug_entry that contains a pointer to
1079+
/// the ud2 instruction corresponding to the bug, corresponding file name (both
1080+
/// pointers use PC relative offset addressing), line number, and flags.
1081+
/// The definition of the struct bug_entry can be found in
1082+
/// `include/asm-generic/bug.h`
1083+
///
1084+
/// NB: find_bug() uses linear search to match an address to an entry in the bug
1085+
/// table. Hence there is no need to sort entries when rewriting the table.
1086+
Error LinuxKernelRewriter::readBugTable() {
1087+
BugTableSection = BC.getUniqueSectionByName("__bug_table");
1088+
if (!BugTableSection)
1089+
return Error::success();
1090+
1091+
if (BugTableSection->getSize() % BUG_TABLE_ENTRY_SIZE)
1092+
return createStringError(errc::executable_format_error,
1093+
"bug table size error");
1094+
1095+
const uint64_t SectionAddress = BugTableSection->getAddress();
1096+
DataExtractor DE(BugTableSection->getContents(), BC.AsmInfo->isLittleEndian(),
1097+
BC.AsmInfo->getCodePointerSize());
1098+
DataExtractor::Cursor Cursor(0);
1099+
uint32_t EntryID = 0;
1100+
while (Cursor && Cursor.tell() < BugTableSection->getSize()) {
1101+
const uint64_t Pos = Cursor.tell();
1102+
const uint64_t InstAddress =
1103+
SectionAddress + Pos + (int32_t)DE.getU32(Cursor);
1104+
Cursor.seek(Pos + BUG_TABLE_ENTRY_SIZE);
1105+
1106+
if (!Cursor)
1107+
return createStringError(errc::executable_format_error,
1108+
"out of bounds while reading __bug_table");
1109+
1110+
++EntryID;
1111+
1112+
BinaryFunction *BF = BC.getBinaryFunctionContainingAddress(InstAddress);
1113+
if (!BF && opts::Verbosity) {
1114+
BC.outs() << "BOLT-INFO: no function matches address 0x"
1115+
<< Twine::utohexstr(InstAddress)
1116+
<< " referenced by bug table\n";
1117+
}
1118+
1119+
if (BF && BC.shouldEmit(*BF)) {
1120+
MCInst *Inst = BF->getInstructionAtOffset(InstAddress - BF->getAddress());
1121+
if (!Inst)
1122+
return createStringError(errc::executable_format_error,
1123+
"no instruction at address 0x%" PRIx64
1124+
" referenced by bug table entry %d",
1125+
InstAddress, EntryID);
1126+
BC.MIB->addAnnotation(*Inst, "BugEntry", EntryID);
1127+
}
1128+
}
1129+
1130+
BC.outs() << "BOLT-INFO: parsed " << EntryID << " bug table entries\n";
1131+
1132+
return Error::success();
1133+
}
1134+
11001135
} // namespace
11011136

11021137
std::unique_ptr<MetadataRewriter>

bolt/test/X86/gotpcrelx.s

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
## kinds of handling of the relocation by the linker (no relaxation, pic, and
66
## non-pic).
77

8-
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux \
9-
# RUN: -relax-relocations %s -o %t.o
8+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
109
# RUN: ld.lld %t.o -o %t.exe -q
1110
# RUN: ld.lld %t.o -o %t.pie.exe -q -pie
1211
# RUN: ld.lld %t.o -o %t.no-relax.exe -q --no-relax

bolt/test/X86/linux-bug-table.s

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# REQUIRES: system-linux
2+
3+
## Check that BOLT correctly parses the Linux kernel __bug_table section.
4+
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
6+
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
7+
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
8+
9+
## Verify bug entry bindings to instructions.
10+
11+
# RUN: llvm-bolt %t.exe --print-normalized -o %t.out | FileCheck %s
12+
13+
# CHECK: BOLT-INFO: Linux kernel binary detected
14+
# CHECK: BOLT-INFO: parsed 2 bug table entries
15+
16+
.text
17+
.globl _start
18+
.type _start, %function
19+
_start:
20+
# CHECK: Binary Function "_start"
21+
nop
22+
.L0:
23+
ud2
24+
# CHECK: ud2
25+
# CHECK-SAME: BugEntry: 1
26+
nop
27+
.L1:
28+
ud2
29+
# CHECK: ud2
30+
# CHECK-SAME: BugEntry: 2
31+
ret
32+
.size _start, .-_start
33+
34+
35+
## Bug table.
36+
.section __bug_table,"a",@progbits
37+
1:
38+
.long .L0 - . # instruction
39+
.org 1b + 12
40+
2:
41+
.long .L1 - . # instruction
42+
.org 2b + 12
43+
44+
## Fake Linux Kernel sections.
45+
.section __ksymtab,"a",@progbits
46+
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/pt_gnu_relro.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Check that BOLT recognizes PT_GNU_RELRO segment and marks respective sections
44
# accordingly.
55

6-
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o -relax-relocations
6+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
77
# RUN: ld.lld %t.o -o %t.exe -q --no-relax
88
# RUN: llvm-readelf -We %t.exe | FileCheck --check-prefix=READELF %s
99
# Unfortunately there's no direct way to extract a segment to section mapping

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,26 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
6060
}
6161

6262
if (const auto *CExpr = dyn_cast<CallExpr>(E)) {
63-
bool Result = CheckFunctionCalls;
63+
if (!CheckFunctionCalls)
64+
return false;
6465
if (const auto *FuncDecl = CExpr->getDirectCallee()) {
6566
if (FuncDecl->getDeclName().isIdentifier() &&
6667
IgnoredFunctionsMatcher.matches(*FuncDecl, Finder,
6768
Builder)) // exceptions come here
68-
Result = false;
69-
else if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl))
70-
Result &= !MethodDecl->isConst();
69+
return false;
70+
for (size_t I = 0; I < FuncDecl->getNumParams(); I++) {
71+
const ParmVarDecl *P = FuncDecl->getParamDecl(I);
72+
const Expr *ArgExpr =
73+
I < CExpr->getNumArgs() ? CExpr->getArg(I) : nullptr;
74+
const QualType PT = P->getType().getCanonicalType();
75+
if (ArgExpr && !ArgExpr->isXValue() && PT->isReferenceType() &&
76+
!PT.getNonReferenceType().isConstQualified())
77+
return true;
78+
}
79+
if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl))
80+
return !MethodDecl->isConst();
7181
}
72-
return Result;
82+
return true;
7383
}
7484

7585
return isa<CXXNewExpr>(E) || isa<CXXDeleteExpr>(E) || isa<CXXThrowExpr>(E);

clang-tools-extra/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ New check aliases
128128
Changes in existing checks
129129
^^^^^^^^^^^^^^^^^^^^^^^^^^
130130

131+
- Improved :doc:`bugprone-assert-side-effect
132+
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
133+
effect from calling a method with non-const reference parameters.
134+
131135
- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
132136
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
133137
eliminating false positives resulting from direct usage of bitwise operators

clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,27 @@ int main() {
108108

109109
return 0;
110110
}
111+
112+
namespace parameter_anaylysis {
113+
114+
struct S {
115+
bool value(int) const;
116+
bool leftValueRef(int &) const;
117+
bool constRef(int const &) const;
118+
bool rightValueRef(int &&) const;
119+
};
120+
121+
void foo() {
122+
S s{};
123+
int i = 0;
124+
assert(s.value(0));
125+
assert(s.value(i));
126+
assert(s.leftValueRef(i));
127+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
128+
assert(s.constRef(0));
129+
assert(s.constRef(i));
130+
assert(s.rightValueRef(0));
131+
assert(s.rightValueRef(static_cast<int &&>(i)));
132+
}
133+
134+
} // namespace parameter_anaylysis

clang/CodeOwners.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Analysis & CFG
6060
Experimental new constant interpreter
6161
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6262
| Timm Bäder
63-
| [email protected] (email), tbaeder (Phabricator), tbaederr (GitHub)
63+
| tbaeder\@redhat.com (email), tbaeder (Phabricator), tbaederr (GitHub), tbaeder (Discourse), tbaeder (Discord)
6464
6565

6666
Modules & serialization

clang/docs/LanguageExtensions.rst

+28
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the user.
27992799
28002800
Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
28012801
2802+
``__builtin_cpu_supports``
2803+
--------------------------
2804+
2805+
**Syntax**:
2806+
2807+
.. code-block:: c++
2808+
2809+
int __builtin_cpu_supports(const char *features);
2810+
2811+
**Example of Use:**:
2812+
2813+
.. code-block:: c++
2814+
2815+
if (__builtin_cpu_supports("sve"))
2816+
sve_code();
2817+
2818+
**Description**:
2819+
2820+
The ``__builtin_cpu_supports`` function detects if the run-time CPU supports
2821+
features specified in string argument. It returns a positive integer if all
2822+
features are supported and 0 otherwise. Feature names are target specific. On
2823+
AArch64 features are combined using ``+`` like this
2824+
``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``.
2825+
If a feature name is not supported, Clang will issue a warning and replace
2826+
builtin by the constant 0.
2827+
2828+
Query for this feature with ``__has_builtin(__builtin_cpu_supports)``.
2829+
28022830
``__builtin_dump_struct``
28032831
-------------------------
28042832

clang/docs/ReleaseNotes.rst

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ C++23 Feature Support
9797
- Implemented `P2718R0: Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_. Also
9898
materialize temporary object which is a prvalue in discarded-value expression.
9999

100+
- Implemented `P2448R2: Relaxing some constexpr restrictions <https://wg21.link/P2448R2>`_.
101+
100102
C++2c Feature Support
101103
^^^^^^^^^^^^^^^^^^^^^
102104

@@ -319,6 +321,14 @@ Bug Fixes to C++ Support
319321
Fixes (#GH80630)
320322
- Fix a crash when an explicit template argument list is used with a name for which lookup
321323
finds a non-template function and a dependent using declarator.
324+
- Fixed an issue where the ``RequiresExprBody`` was involved in the lambda dependency
325+
calculation. (#GH56556), (#GH82849).
326+
- Fix a bug where overload resolution falsely reported an ambiguity when it was comparing
327+
a member-function against a non member function or a member-function with an
328+
explicit object parameter against a member function with no explicit object parameter
329+
when one of the function had more specialized templates.
330+
Fixes (`#82509 <https://github.com/llvm/llvm-project/issues/82509>`_)
331+
and (`#74494 <https://github.com/llvm/llvm-project/issues/74494>`_)
322332

323333
Bug Fixes to AST Handling
324334
^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)