Skip to content

Commit 882c429

Browse files
authored
Merge branch 'main' into p/libc-hdrgen-yaml-template
2 parents 0e7e8fe + 1855333 commit 882c429

File tree

433 files changed

+15465
-6123
lines changed

Some content is hidden

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

433 files changed

+15465
-6123
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- name: Install clang-format
6161
uses: aminya/setup-cpp@v1
6262
with:
63-
clangformat: 18.1.7
63+
clangformat: 19.1.6
6464

6565
- name: Setup Python env
6666
uses: actions/setup-python@v5

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ BreakFunctionNames("break-funcs",
4646
cl::Hidden,
4747
cl::cat(BoltCategory));
4848

49-
cl::list<std::string>
49+
static cl::list<std::string>
5050
FunctionPadSpec("pad-funcs", cl::CommaSeparated,
5151
cl::desc("list of functions to pad with amount of bytes"),
5252
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."),
5353
cl::Hidden, cl::cat(BoltCategory));
5454

55-
cl::list<std::string> FunctionPadBeforeSpec(
55+
static cl::list<std::string> FunctionPadBeforeSpec(
5656
"pad-funcs-before", cl::CommaSeparated,
5757
cl::desc("list of functions to pad with amount of bytes"),
5858
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."), cl::Hidden,
@@ -74,10 +74,9 @@ X86AlignBranchBoundaryHotOnly("x86-align-branch-boundary-hot-only",
7474
cl::init(true),
7575
cl::cat(BoltOptCategory));
7676

77-
size_t padFunction(const cl::list<std::string> &Spec,
77+
size_t padFunction(std::map<std::string, size_t> &FunctionPadding,
78+
const cl::list<std::string> &Spec,
7879
const BinaryFunction &Function) {
79-
static std::map<std::string, size_t> FunctionPadding;
80-
8180
if (FunctionPadding.empty() && !Spec.empty()) {
8281
for (const std::string &Spec : Spec) {
8382
size_t N = Spec.find(':');
@@ -99,6 +98,15 @@ size_t padFunction(const cl::list<std::string> &Spec,
9998
return 0;
10099
}
101100

101+
size_t padFunctionBefore(const BinaryFunction &Function) {
102+
static std::map<std::string, size_t> CacheFunctionPadding;
103+
return padFunction(CacheFunctionPadding, FunctionPadBeforeSpec, Function);
104+
}
105+
size_t padFunctionAfter(const BinaryFunction &Function) {
106+
static std::map<std::string, size_t> CacheFunctionPadding;
107+
return padFunction(CacheFunctionPadding, FunctionPadSpec, Function);
108+
}
109+
102110
} // namespace opts
103111

104112
namespace {
@@ -324,8 +332,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
324332
Streamer.emitCodeAlignment(Function.getAlign(), &*BC.STI);
325333
}
326334

327-
if (size_t Padding =
328-
opts::padFunction(opts::FunctionPadBeforeSpec, Function)) {
335+
if (size_t Padding = opts::padFunctionBefore(Function)) {
329336
// Handle padFuncsBefore after the above alignment logic but before
330337
// symbol addresses are decided.
331338
if (!BC.HasRelocations) {
@@ -404,7 +411,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
404411
emitFunctionBody(Function, FF, /*EmitCodeOnly=*/false);
405412

406413
// Emit padding if requested.
407-
if (size_t Padding = opts::padFunction(opts::FunctionPadSpec, Function)) {
414+
if (size_t Padding = opts::padFunctionAfter(Function)) {
408415
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding function " << Function << " with "
409416
<< Padding << " bytes\n");
410417
Streamer.emitFill(Padding, MAI->getTextAlignFillValue());

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ extern cl::OptionCategory BoltOptCategory;
2828
extern cl::opt<unsigned> Verbosity;
2929
extern cl::opt<uint32_t> RandomSeed;
3030

31-
extern size_t padFunction(const cl::list<std::string> &Spec,
32-
const bolt::BinaryFunction &Function);
33-
extern cl::list<std::string> FunctionPadSpec, FunctionPadBeforeSpec;
31+
extern size_t padFunctionBefore(const bolt::BinaryFunction &Function);
32+
extern size_t padFunctionAfter(const bolt::BinaryFunction &Function);
3433

3534
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
3635
cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions(
@@ -306,12 +305,10 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
306305
return false;
307306
if (B->isIgnored())
308307
return true;
309-
const size_t PadA =
310-
opts::padFunction(opts::FunctionPadSpec, *A) +
311-
opts::padFunction(opts::FunctionPadBeforeSpec, *A);
312-
const size_t PadB =
313-
opts::padFunction(opts::FunctionPadSpec, *B) +
314-
opts::padFunction(opts::FunctionPadBeforeSpec, *B);
308+
const size_t PadA = opts::padFunctionBefore(*A) +
309+
opts::padFunctionAfter(*A);
310+
const size_t PadB = opts::padFunctionBefore(*B) +
311+
opts::padFunctionAfter(*B);
315312
if (!PadA || !PadB) {
316313
if (PadA)
317314
return true;

bolt/test/AArch64/pad-before-funcs.s

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
# It should be able to introduce a configurable offset for the _start symbol.
33
# It should reject requests which don't obey the code alignment requirement.
44

5+
# Tests check inserting padding before _start; and additionally a test where
6+
# padding is inserted after start. In each case, check that the following
7+
# symbol ends up in the expected place as well.
8+
9+
510
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
611
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -Wl,--section-start=.text=0x4000
712
# RUN: llvm-bolt %t.exe -o %t.bolt.0 --pad-funcs-before=_start:0
813
# RUN: llvm-bolt %t.exe -o %t.bolt.4 --pad-funcs-before=_start:4
914
# RUN: llvm-bolt %t.exe -o %t.bolt.8 --pad-funcs-before=_start:8
15+
# RUN: llvm-bolt %t.exe -o %t.bolt.4.4 --pad-funcs-before=_start:4 --pad-funcs=_start:4
16+
# RUN: llvm-bolt %t.exe -o %t.bolt.4.8 --pad-funcs-before=_start:4 --pad-funcs=_start:8
1017

1118
# RUN: not llvm-bolt %t.exe -o %t.bolt.8 --pad-funcs-before=_start:1 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGN %s
1219

@@ -15,15 +22,27 @@
1522
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.0 | FileCheck --check-prefix=CHECK-0 %s
1623
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.4 | FileCheck --check-prefix=CHECK-4 %s
1724
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.8 | FileCheck --check-prefix=CHECK-8 %s
25+
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.4.4 | FileCheck --check-prefix=CHECK-4-4 %s
26+
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.4.8 | FileCheck --check-prefix=CHECK-4-8 %s
1827

1928
# Trigger relocation mode in bolt.
2029
.reloc 0, R_AARCH64_NONE
2130

2231
.section .text
23-
.globl _start
2432

2533
# CHECK-0: 0000000000400000 <_start>
2634
# CHECK-4: 0000000000400004 <_start>
35+
# CHECK-4-4: 0000000000400004 <_start>
2736
# CHECK-8: 0000000000400008 <_start>
37+
.globl _start
2838
_start:
2939
ret
40+
41+
# CHECK-0: 0000000000400004 <_subsequent>
42+
# CHECK-4: 0000000000400008 <_subsequent>
43+
# CHECK-4-4: 000000000040000c <_subsequent>
44+
# CHECK-4-8: 0000000000400010 <_subsequent>
45+
# CHECK-8: 000000000040000c <_subsequent>
46+
.globl _subsequent
47+
_subsequent:
48+
ret

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ void UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
7474
// Matcher for standard smart pointers.
7575
const auto SmartPointerType = qualType(hasUnqualifiedDesugaredType(
7676
recordType(hasDeclaration(classTemplateSpecializationDecl(
77-
hasAnyName("::std::shared_ptr", "::std::unique_ptr",
78-
"::std::weak_ptr", "::std::auto_ptr"),
79-
templateArgumentCountIs(1))))));
77+
anyOf(allOf(hasAnyName("::std::shared_ptr", "::std::weak_ptr",
78+
"::std::auto_ptr"),
79+
templateArgumentCountIs(1)),
80+
allOf(hasName("::std::unique_ptr"),
81+
templateArgumentCountIs(2))))))));
8082

8183
// We will warn only if the class has a pointer or a C array field which
8284
// probably causes a problem during self-assignment (e.g. first resetting

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ Changes in existing checks
233233
`bsl::optional` and `bdlb::NullableValue` from
234234
<https://github.com/bloomberg/bde>_.
235235

236+
- Improved :doc:`bugprone-unhandled-self-assignment
237+
<clang-tidy/checks/bugprone/unhandled-self-assignment>` check by fixing smart
238+
pointer check against std::unique_ptr type.
239+
236240
- Improved :doc:`bugprone-unsafe-functions
237241
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
238242
additional functions to match.

clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ template <class T>
1010
T &&move(T &x) {
1111
}
1212

13-
template <class T>
13+
template <typename T> class default_delete {};
14+
15+
template <class T, typename Deleter = std::default_delete<T>>
1416
class unique_ptr {
1517
};
1618

clang/bindings/python/clang/cindex.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,12 +2125,26 @@ def get_field_offsetof(self):
21252125

21262126
def is_anonymous(self):
21272127
"""
2128-
Check if the record is anonymous.
2128+
Check whether this is a record type without a name, or a field where
2129+
the type is a record type without a name.
2130+
2131+
Use is_anonymous_record_decl to check whether a record is an
2132+
"anonymous union" as defined in the C/C++ standard.
21292133
"""
21302134
if self.kind == CursorKind.FIELD_DECL:
21312135
return self.type.get_declaration().is_anonymous()
21322136
return conf.lib.clang_Cursor_isAnonymous(self) # type: ignore [no-any-return]
21332137

2138+
def is_anonymous_record_decl(self):
2139+
"""
2140+
Check if the record is an anonymous union as defined in the C/C++ standard
2141+
(or an "anonymous struct", the corresponding non-standard extension for
2142+
structs).
2143+
"""
2144+
if self.kind == CursorKind.FIELD_DECL:
2145+
return self.type.get_declaration().is_anonymous_record_decl()
2146+
return conf.lib.clang_Cursor_isAnonymousRecordDecl(self) # type: ignore [no-any-return]
2147+
21342148
def is_bitfield(self):
21352149
"""
21362150
Check if the field is a bitfield.
@@ -3902,12 +3916,13 @@ def write_main_file_to_stdout(self):
39023916
("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
39033917
("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
39043918
("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], c_ulonglong),
3905-
("clang_Cursor_isAnonymous", [Cursor], bool),
3906-
("clang_Cursor_isBitField", [Cursor], bool),
39073919
("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
39083920
("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
39093921
("clang_Cursor_getRawCommentText", [Cursor], _CXString),
39103922
("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
3923+
("clang_Cursor_isAnonymous", [Cursor], bool),
3924+
("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
3925+
("clang_Cursor_isBitField", [Cursor], bool),
39113926
("clang_Location_isInSystemHeader", [SourceLocation], bool),
39123927
("clang_Type_getAlignOf", [Type], c_longlong),
39133928
("clang_Type_getClassType", [Type], Type),

clang/bindings/python/tests/cindex/test_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,11 @@ def test_offset(self):
463463
self.assertNotEqual(children[0].spelling, "typeanon")
464464
self.assertEqual(children[1].spelling, "typeanon")
465465
self.assertEqual(fields[0].kind, CursorKind.FIELD_DECL)
466+
self.assertTrue(fields[0].is_anonymous())
467+
self.assertFalse(fields[0].is_anonymous_record_decl())
466468
self.assertEqual(fields[1].kind, CursorKind.FIELD_DECL)
467469
self.assertTrue(fields[1].is_anonymous())
470+
self.assertTrue(fields[1].is_anonymous_record_decl())
468471
self.assertEqual(teststruct.type.get_offset("typeanon"), f1)
469472
self.assertEqual(teststruct.type.get_offset("bariton"), bariton)
470473
self.assertEqual(teststruct.type.get_offset("foo"), foo)

clang/docs/ReleaseNotes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,16 @@ Improvements to Clang's diagnostics
704704
return ptr + index < ptr; // warning
705705
}
706706
707+
- Clang now emits a ``-Wvarargs`` diagnostic when the second argument
708+
to ``va_arg`` is of array type, which is an undefined behavior (#GH119360).
709+
710+
.. code-block:: c++
711+
712+
void test() {
713+
va_list va;
714+
va_arg(va, int[10]); // warning
715+
}
716+
707717
- Fix -Wdangling false positives on conditional operators (#120206).
708718

709719
- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing
@@ -754,6 +764,7 @@ Bug Fixes in This Version
754764
the unsupported type instead of the ``register`` keyword (#GH109776).
755765
- Fixed a crash when emit ctor for global variant with flexible array init (#GH113187).
756766
- Fixed a crash when GNU statement expression contains invalid statement (#GH113468).
767+
- Fixed a crash when passing the variable length array type to ``va_arg`` (#GH119360).
757768
- Fixed a failed assertion when using ``__attribute__((noderef))`` on an
758769
``_Atomic``-qualified type (#GH116124).
759770
- No longer return ``false`` for ``noexcept`` expressions involving a
@@ -1275,6 +1286,8 @@ Sanitizers
12751286
Python Binding Changes
12761287
----------------------
12771288
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
1289+
- Added binding for ``clang_Cursor_isAnonymousRecordDecl``, which allows checking if
1290+
a declaration is an anonymous union or anonymous struct.
12781291

12791292
OpenMP Support
12801293
--------------

0 commit comments

Comments
 (0)