Skip to content

Commit a9f48dd

Browse files
authored
Merge branch 'main' into users/kparzysz/spr/m01-applymem
2 parents de4be10 + 0d9cf26 commit a9f48dd

File tree

332 files changed

+11680
-4852
lines changed

Some content is hidden

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

332 files changed

+11680
-4852
lines changed

bolt/lib/Core/BinaryEmitter.cpp

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

49-
cl::list<std::string>
50-
FunctionPadSpec("pad-funcs", cl::CommaSeparated,
51-
cl::desc("list of functions to pad with amount of bytes"),
52-
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."),
53-
cl::Hidden, cl::cat(BoltCategory));
54-
55-
cl::list<std::string> FunctionPadBeforeSpec(
56-
"pad-funcs-before", cl::CommaSeparated,
57-
cl::desc("list of functions to pad with amount of bytes"),
58-
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."), cl::Hidden,
59-
cl::cat(BoltCategory));
49+
static cl::list<std::string>
50+
FunctionPadSpec("pad-funcs",
51+
cl::CommaSeparated,
52+
cl::desc("list of functions to pad with amount of bytes"),
53+
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."),
54+
cl::Hidden,
55+
cl::cat(BoltCategory));
6056

6157
static cl::opt<bool> MarkFuncs(
6258
"mark-funcs",
@@ -74,12 +70,11 @@ X86AlignBranchBoundaryHotOnly("x86-align-branch-boundary-hot-only",
7470
cl::init(true),
7571
cl::cat(BoltOptCategory));
7672

77-
size_t padFunction(const cl::list<std::string> &Spec,
78-
const BinaryFunction &Function) {
73+
size_t padFunction(const BinaryFunction &Function) {
7974
static std::map<std::string, size_t> FunctionPadding;
8075

81-
if (FunctionPadding.empty() && !Spec.empty()) {
82-
for (const std::string &Spec : Spec) {
76+
if (FunctionPadding.empty() && !FunctionPadSpec.empty()) {
77+
for (std::string &Spec : FunctionPadSpec) {
8378
size_t N = Spec.find(':');
8479
if (N == std::string::npos)
8580
continue;
@@ -324,32 +319,6 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
324319
Streamer.emitCodeAlignment(Function.getAlign(), &*BC.STI);
325320
}
326321

327-
if (size_t Padding =
328-
opts::padFunction(opts::FunctionPadBeforeSpec, Function)) {
329-
// Handle padFuncsBefore after the above alignment logic but before
330-
// symbol addresses are decided.
331-
if (!BC.HasRelocations) {
332-
BC.errs() << "BOLT-ERROR: -pad-before-funcs is not supported in "
333-
<< "non-relocation mode\n";
334-
exit(1);
335-
}
336-
337-
// Preserve Function.getMinAlign().
338-
if (!isAligned(Function.getMinAlign(), Padding)) {
339-
BC.errs() << "BOLT-ERROR: user-requested " << Padding
340-
<< " padding bytes before function " << Function
341-
<< " is not a multiple of the minimum function alignment ("
342-
<< Function.getMinAlign().value() << ").\n";
343-
exit(1);
344-
}
345-
346-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding before function " << Function
347-
<< " with " << Padding << " bytes\n");
348-
349-
// Since the padding is not executed, it can be null bytes.
350-
Streamer.emitFill(Padding, 0);
351-
}
352-
353322
MCContext &Context = Streamer.getContext();
354323
const MCAsmInfo *MAI = Context.getAsmInfo();
355324

@@ -404,7 +373,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
404373
emitFunctionBody(Function, FF, /*EmitCodeOnly=*/false);
405374

406375
// Emit padding if requested.
407-
if (size_t Padding = opts::padFunction(opts::FunctionPadSpec, Function)) {
376+
if (size_t Padding = opts::padFunction(Function)) {
408377
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding function " << Function << " with "
409378
<< Padding << " bytes\n");
410379
Streamer.emitFill(Padding, MAI->getTextAlignFillValue());

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ 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 padFunction(const bolt::BinaryFunction &Function);
3432

3533
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
3634
cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions(
@@ -306,12 +304,8 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
306304
return false;
307305
if (B->isIgnored())
308306
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);
307+
const size_t PadA = opts::padFunction(*A);
308+
const size_t PadB = opts::padFunction(*B);
315309
if (!PadA || !PadB) {
316310
if (PadA)
317311
return true;

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

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
--------------

clang/docs/analyzer/checkers.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ cplusplus.NewDelete (C++)
476476
"""""""""""""""""""""""""
477477
Check for double-free and use-after-free problems. Traces memory managed by new/delete.
478478
479+
Custom allocation/deallocation functions can be defined using
480+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
481+
479482
.. literalinclude:: checkers/newdelete_example.cpp
480483
:language: cpp
481484
@@ -485,6 +488,9 @@ cplusplus.NewDeleteLeaks (C++)
485488
""""""""""""""""""""""""""""""
486489
Check for memory leaks. Traces memory managed by new/delete.
487490
491+
Custom allocation/deallocation functions can be defined using
492+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
493+
488494
.. code-block:: cpp
489495
490496
void test() {
@@ -1263,6 +1269,9 @@ You can silence this warning either by bound checking the ``size`` parameter, or
12631269
by explicitly marking the ``size`` parameter as sanitized. See the
12641270
:ref:`optin-taint-GenericTaint` checker for an example.
12651271
1272+
Custom allocation/deallocation functions can be defined using
1273+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
1274+
12661275
.. code-block:: c
12671276
12681277
void vulnerable(void) {
@@ -1857,6 +1866,9 @@ unix.Malloc (C)
18571866
"""""""""""""""
18581867
Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free().
18591868
1869+
Custom allocation/deallocation functions can be defined using
1870+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
1871+
18601872
.. literalinclude:: checkers/unix_malloc_example.c
18611873
:language: c
18621874
@@ -1866,6 +1878,9 @@ unix.MallocSizeof (C)
18661878
"""""""""""""""""""""
18671879
Check for dubious ``malloc`` arguments involving ``sizeof``.
18681880
1881+
Custom allocation/deallocation functions can be defined using
1882+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
1883+
18691884
.. code-block:: c
18701885
18711886
void test() {
@@ -1881,6 +1896,9 @@ unix.MismatchedDeallocator (C, C++)
18811896
"""""""""""""""""""""""""""""""""""
18821897
Check for mismatched deallocators.
18831898
1899+
Custom allocation/deallocation functions can be defined using
1900+
:ref:`ownership attributes<analyzer-ownership-attrs>`.
1901+
18841902
.. literalinclude:: checkers/mismatched_deallocator_example.cpp
18851903
:language: c
18861904

0 commit comments

Comments
 (0)