Skip to content

Commit 2448b78

Browse files
committed
merge main into amd-staging
Change-Id: I8c52874236360833615d6d6e561733cb6770603a
2 parents 4b36779 + ac604b2 commit 2448b78

File tree

208 files changed

+9577
-4155
lines changed

Some content is hidden

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

208 files changed

+9577
-4155
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ BreakFunctionNames("break-funcs",
4747
cl::cat(BoltCategory));
4848

4949
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));
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+
static 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));
5660

5761
static cl::opt<bool> MarkFuncs(
5862
"mark-funcs",
@@ -70,11 +74,11 @@ X86AlignBranchBoundaryHotOnly("x86-align-branch-boundary-hot-only",
7074
cl::init(true),
7175
cl::cat(BoltOptCategory));
7276

73-
size_t padFunction(const BinaryFunction &Function) {
74-
static std::map<std::string, size_t> FunctionPadding;
75-
76-
if (FunctionPadding.empty() && !FunctionPadSpec.empty()) {
77-
for (std::string &Spec : FunctionPadSpec) {
77+
size_t padFunction(std::map<std::string, size_t> &FunctionPadding,
78+
const cl::list<std::string> &Spec,
79+
const BinaryFunction &Function) {
80+
if (FunctionPadding.empty() && !Spec.empty()) {
81+
for (const std::string &Spec : Spec) {
7882
size_t N = Spec.find(':');
7983
if (N == std::string::npos)
8084
continue;
@@ -94,6 +98,15 @@ size_t padFunction(const BinaryFunction &Function) {
9498
return 0;
9599
}
96100

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+
97110
} // namespace opts
98111

99112
namespace {
@@ -319,6 +332,31 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
319332
Streamer.emitCodeAlignment(Function.getAlign(), &*BC.STI);
320333
}
321334

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

@@ -373,7 +411,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
373411
emitFunctionBody(Function, FF, /*EmitCodeOnly=*/false);
374412

375413
// Emit padding if requested.
376-
if (size_t Padding = opts::padFunction(Function)) {
414+
if (size_t Padding = opts::padFunctionAfter(Function)) {
377415
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding function " << Function << " with "
378416
<< Padding << " bytes\n");
379417
Streamer.emitFill(Padding, MAI->getTextAlignFillValue());

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +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 bolt::BinaryFunction &Function);
31+
extern size_t padFunctionBefore(const bolt::BinaryFunction &Function);
32+
extern size_t padFunctionAfter(const bolt::BinaryFunction &Function);
3233

3334
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
3435
cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions(
@@ -304,8 +305,10 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
304305
return false;
305306
if (B->isIgnored())
306307
return true;
307-
const size_t PadA = opts::padFunction(*A);
308-
const size_t PadB = opts::padFunction(*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);
309312
if (!PadA || !PadB) {
310313
if (PadA)
311314
return true;

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test checks that --pad-before-funcs is working as expected.
2+
# It should be able to introduce a configurable offset for the _start symbol.
3+
# It should reject requests which don't obey the code alignment requirement.
4+
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+
10+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
11+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -Wl,--section-start=.text=0x4000
12+
# RUN: llvm-bolt %t.exe -o %t.bolt.0 --pad-funcs-before=_start:0
13+
# RUN: llvm-bolt %t.exe -o %t.bolt.4 --pad-funcs-before=_start:4
14+
# 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
17+
18+
# RUN: not llvm-bolt %t.exe -o %t.bolt.8 --pad-funcs-before=_start:1 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGN %s
19+
20+
# CHECK-BAD-ALIGN: user-requested 1 padding bytes before function _start(*2) is not a multiple of the minimum function alignment (4).
21+
22+
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.0 | FileCheck --check-prefix=CHECK-0 %s
23+
# RUN: llvm-objdump --section=.text --disassemble %t.bolt.4 | FileCheck --check-prefix=CHECK-4 %s
24+
# 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
27+
28+
# Trigger relocation mode in bolt.
29+
.reloc 0, R_AARCH64_NONE
30+
31+
.section .text
32+
33+
# CHECK-0: 0000000000400000 <_start>
34+
# CHECK-4: 0000000000400004 <_start>
35+
# CHECK-4-4: 0000000000400004 <_start>
36+
# CHECK-8: 0000000000400008 <_start>
37+
.globl _start
38+
_start:
39+
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/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,16 @@ Improvements to Clang's diagnostics
734734
return ptr + index < ptr; // warning
735735
}
736736
737+
- Clang now emits a ``-Wvarargs`` diagnostic when the second argument
738+
to ``va_arg`` is of array type, which is an undefined behavior (#GH119360).
739+
740+
.. code-block:: c++
741+
742+
void test() {
743+
va_list va;
744+
va_arg(va, int[10]); // warning
745+
}
746+
737747
- Fix -Wdangling false positives on conditional operators (#120206).
738748

739749
- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing
@@ -786,6 +796,7 @@ Bug Fixes in This Version
786796
the unsupported type instead of the ``register`` keyword (#GH109776).
787797
- Fixed a crash when emit ctor for global variant with flexible array init (#GH113187).
788798
- Fixed a crash when GNU statement expression contains invalid statement (#GH113468).
799+
- Fixed a crash when passing the variable length array type to ``va_arg`` (#GH119360).
789800
- Fixed a failed assertion when using ``__attribute__((noderef))`` on an
790801
``_Atomic``-qualified type (#GH116124).
791802
- No longer return ``false`` for ``noexcept`` expressions involving a

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

clang/include/clang-c/Index.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,11 @@ enum CXCursorKind {
22022202
*/
22032203
CXCursor_OpenACCSetConstruct = 330,
22042204

2205-
CXCursor_LastStmt = CXCursor_OpenACCSetConstruct,
2205+
/** OpenACC update Construct.
2206+
*/
2207+
CXCursor_OpenACCUpdateConstruct = 331,
2208+
2209+
CXCursor_LastStmt = CXCursor_OpenACCUpdateConstruct,
22062210

22072211
/**
22082212
* Cursor that represents the translation unit itself.

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,8 @@ DEF_TRAVERSE_STMT(OpenACCShutdownConstruct,
40824082
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40834083
DEF_TRAVERSE_STMT(OpenACCSetConstruct,
40844084
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4085+
DEF_TRAVERSE_STMT(OpenACCUpdateConstruct,
4086+
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40854087

40864088
// Traverse HLSL: Out argument expression
40874089
DEF_TRAVERSE_STMT(HLSLOutArgExpr, {})

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,5 +712,44 @@ class OpenACCSetConstruct final
712712
SourceLocation End,
713713
ArrayRef<const OpenACCClause *> Clauses);
714714
};
715+
// This class represents an 'update' construct, which has just a clause list.
716+
class OpenACCUpdateConstruct final
717+
: public OpenACCConstructStmt,
718+
private llvm::TrailingObjects<OpenACCUpdateConstruct,
719+
const OpenACCClause *> {
720+
friend TrailingObjects;
721+
OpenACCUpdateConstruct(unsigned NumClauses)
722+
: OpenACCConstructStmt(OpenACCUpdateConstructClass,
723+
OpenACCDirectiveKind::Update, SourceLocation{},
724+
SourceLocation{}, SourceLocation{}) {
725+
std::uninitialized_value_construct(
726+
getTrailingObjects<const OpenACCClause *>(),
727+
getTrailingObjects<const OpenACCClause *>() + NumClauses);
728+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
729+
NumClauses));
730+
}
731+
732+
OpenACCUpdateConstruct(SourceLocation Start, SourceLocation DirectiveLoc,
733+
SourceLocation End,
734+
ArrayRef<const OpenACCClause *> Clauses)
735+
: OpenACCConstructStmt(OpenACCUpdateConstructClass,
736+
OpenACCDirectiveKind::Update, Start, DirectiveLoc,
737+
End) {
738+
std::uninitialized_copy(Clauses.begin(), Clauses.end(),
739+
getTrailingObjects<const OpenACCClause *>());
740+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
741+
Clauses.size()));
742+
}
743+
744+
public:
745+
static bool classof(const Stmt *T) {
746+
return T->getStmtClass() == OpenACCUpdateConstructClass;
747+
}
748+
static OpenACCUpdateConstruct *CreateEmpty(const ASTContext &C,
749+
unsigned NumClauses);
750+
static OpenACCUpdateConstruct *
751+
Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
752+
SourceLocation End, ArrayRef<const OpenACCClause *> Clauses);
753+
};
715754
} // namespace clang
716755
#endif // LLVM_CLANG_AST_STMTOPENACC_H

clang/include/clang/AST/TextNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ class TextNodeDumper
419419
void VisitOpenACCInitConstruct(const OpenACCInitConstruct *S);
420420
void VisitOpenACCSetConstruct(const OpenACCSetConstruct *S);
421421
void VisitOpenACCShutdownConstruct(const OpenACCShutdownConstruct *S);
422+
void VisitOpenACCUpdateConstruct(const OpenACCUpdateConstruct *S);
422423
void VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *S);
423424
void VisitEmbedExpr(const EmbedExpr *S);
424425
void VisitAtomicExpr(const AtomicExpr *AE);

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ def OwnershipDocs : Documentation {
13931393
let Heading = "ownership_holds, ownership_returns, ownership_takes (Clang "
13941394
"Static Analyzer)";
13951395
let Category = DocCatFunction;
1396+
let Label = "analyzer-ownership-attrs";
13961397
let Content = [{
13971398

13981399
.. note::

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10515,6 +10515,10 @@ def warn_second_parameter_to_va_arg_ownership_qualified : Warning<
1051510515
def warn_second_parameter_to_va_arg_never_compatible : Warning<
1051610516
"second argument to 'va_arg' is of promotable type %0; this va_arg has "
1051710517
"undefined behavior because arguments will be promoted to %1">, InGroup<Varargs>;
10518+
def warn_second_parameter_to_va_arg_array : Warning<
10519+
"second argument to 'va_arg' is of array type %0; "
10520+
"this va_arg has undefined behavior because arguments "
10521+
"will never be compatible with array type">, InGroup<Varargs>;
1051810522

1051910523
def warn_return_missing_expr : Warning<
1052010524
"non-void %select{function|method}1 %0 should return a value">, DefaultError,
@@ -12828,6 +12832,10 @@ def err_acc_loop_not_monotonic
1282812832
"('++', '--', or compound assignment)">;
1282912833
def err_acc_construct_one_clause_of
1283012834
: Error<"OpenACC '%0' construct must have at least one %1 clause">;
12835+
def err_acc_update_as_body
12836+
: Error<"OpenACC 'update' construct may not appear in place of the "
12837+
"statement following a%select{n if statement| while statement| do "
12838+
"statement| switch statement| label statement}0">;
1283112839

1283212840
// AMDGCN builtins diagnostics
1283312841
def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size value">;

0 commit comments

Comments
 (0)