Skip to content

Commit eda7d3b

Browse files
committed
merge main into amd-staging
Change-Id: Iedc03666e4c28bea09ee8423884b7db0281ffbb7
2 parents c57c373 + 9e87061 commit eda7d3b

File tree

310 files changed

+10805
-6773
lines changed

Some content is hidden

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

310 files changed

+10805
-6773
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ b32931c5b32eb0d2cf37d688b34f8548c9674c19
9393
b6262880b34629e9d7a72b5a42f315a3c9ed8139
9494
39c7dc7207e76e72da21cf4fedda21b5311bf62d
9595
e80bc777749331e9519575f416c342f7626dd14d
96+
7e5cd8f1b6c5263ed5e2cc03d60c8779a8d3e9f7

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- main
10+
- 'users/**'
1011

1112
jobs:
1213
code_formatter:

bolt/test/permission.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This test performs a logical AND operation on the results of the `stat -c %a
55
# %t.bolt` and `umask` commands (both results are displayed in octal), and
66
# checks whether the result is equal to 0.
7-
REQUIRES: system-linux
7+
REQUIRES: shell, system-linux
88

99
RUN: %clang %cflags %p/Inputs/hello.c -o %t -Wl,-q
1010
RUN: llvm-bolt %t -o %t.bolt

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@ The following type trait primitives are supported by Clang. Those traits marked
15471547
* ``__array_extent(type, dim)`` (Embarcadero):
15481548
The ``dim``'th array bound in the type ``type``, or ``0`` if
15491549
``dim >= __array_rank(type)``.
1550+
* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
15501551
* ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
15511552
* ``__can_pass_in_regs`` (C++)
15521553
Returns whether a class can be passed in registers under the current

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ C++2c Feature Support
100100
The changes to attributes declarations are not part of this release.
101101
- Implemented `P2741R3: user-generated static_assert messages <https://wg21.link/P2741R3>`_.
102102

103+
- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
104+
`P2647R1 A trait for implicit lifetime types <https://wg21.link/p2674r1>`_
105+
103106
- Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
104107
`P2985R0 A type trait for detecting virtual base classes <https://wg21.link/p2985r0>`_
105108

@@ -222,8 +225,10 @@ Bug Fixes to C++ Support
222225
- Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
223226
(#GH99877).
224227
- Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions.
225-
- Fixed an assertion failure when selecting a function from an overload set that includes a
228+
- Fixed an assertion failure when selecting a function from an overload set that includes a
226229
specialization of a conversion function template.
230+
- Correctly diagnose attempts to use a concept name in its own definition;
231+
A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875)
227232

228233
Bug Fixes to AST Handling
229234
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -352,6 +357,11 @@ Improvements
352357
Moved checkers
353358
^^^^^^^^^^^^^^
354359

360+
- The checker ``alpha.security.MallocOverflow`` was deleted because it was
361+
badly implemented and its agressive logic produced too many false positives.
362+
To detect too large arguments passed to malloc, consider using the checker
363+
``alpha.taint.TaintedAlloc``.
364+
355365
.. _release-notes-sanitizers:
356366

357367
Sanitizers

clang/docs/analyzer/checkers.rst

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,49 +2951,6 @@ Warn about buffer overflows (newer checker).
29512951
char c = s[x]; // warn: index is tainted
29522952
}
29532953
2954-
.. _alpha-security-MallocOverflow:
2955-
2956-
alpha.security.MallocOverflow (C)
2957-
"""""""""""""""""""""""""""""""""
2958-
Check for overflows in the arguments to ``malloc()``.
2959-
It tries to catch ``malloc(n * c)`` patterns, where:
2960-
2961-
- ``n``: a variable or member access of an object
2962-
- ``c``: a constant foldable integral
2963-
2964-
This checker was designed for code audits, so expect false-positive reports.
2965-
One is supposed to silence this checker by ensuring proper bounds checking on
2966-
the variable in question using e.g. an ``assert()`` or a branch.
2967-
2968-
.. code-block:: c
2969-
2970-
void test(int n) {
2971-
void *p = malloc(n * sizeof(int)); // warn
2972-
}
2973-
2974-
void test2(int n) {
2975-
if (n > 100) // gives an upper-bound
2976-
return;
2977-
void *p = malloc(n * sizeof(int)); // no warning
2978-
}
2979-
2980-
void test3(int n) {
2981-
assert(n <= 100 && "Contract violated.");
2982-
void *p = malloc(n * sizeof(int)); // no warning
2983-
}
2984-
2985-
Limitations:
2986-
2987-
- The checker won't warn for variables involved in explicit casts,
2988-
since that might limit the variable's domain.
2989-
E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
2990-
The checker will miss the true-positive cases when the explicit cast would
2991-
not tighten the domain to prevent the overflow in the subsequent
2992-
multiplication operation.
2993-
2994-
- It is an AST-based checker, thus it does not make use of the
2995-
path-sensitive taint-analysis.
2996-
29972954
.. _alpha-security-MmapWriteExec:
29982955
29992956
alpha.security.MmapWriteExec (C)

clang/include/clang/AST/DeclTemplate.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,19 +3146,24 @@ class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
31463146
: TemplateDecl(Concept, DC, L, Name, Params),
31473147
ConstraintExpr(ConstraintExpr) {};
31483148
public:
3149-
static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
3150-
SourceLocation L, DeclarationName Name,
3149+
static ConceptDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
3150+
DeclarationName Name,
31513151
TemplateParameterList *Params,
3152-
Expr *ConstraintExpr);
3152+
Expr *ConstraintExpr = nullptr);
31533153
static ConceptDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
31543154

31553155
Expr *getConstraintExpr() const {
31563156
return ConstraintExpr;
31573157
}
31583158

3159+
bool hasDefinition() const { return ConstraintExpr != nullptr; }
3160+
3161+
void setDefinition(Expr *E) { ConstraintExpr = E; }
3162+
31593163
SourceRange getSourceRange() const override LLVM_READONLY {
31603164
return SourceRange(getTemplateParameters()->getTemplateLoc(),
3161-
ConstraintExpr->getEndLoc());
3165+
ConstraintExpr ? ConstraintExpr->getEndLoc()
3166+
: SourceLocation());
31623167
}
31633168

31643169
bool isTypeConcept() const {

clang/include/clang/Basic/Attr.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ def ReleaseHandle : InheritableParamAttr {
44674467

44684468
def UnsafeBufferUsage : InheritableAttr {
44694469
let Spellings = [Clang<"unsafe_buffer_usage">];
4470-
let Subjects = SubjectList<[Function]>;
4470+
let Subjects = SubjectList<[Function, Field]>;
44714471
let Documentation = [UnsafeBufferUsageDocs];
44724472
}
44734473

@@ -4599,12 +4599,18 @@ def HLSLResource : InheritableAttr {
45994599
"CBuffer", "Sampler", "TBuffer", "RTAccelerationStructure",
46004600
"FeedbackTexture2D", "FeedbackTexture2DArray"
46014601
],
4602-
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>,
4603-
DefaultBoolArgument<"isROV", /*default=*/0>
4602+
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>
46044603
];
46054604
let Documentation = [InternalOnly];
46064605
}
46074606

4607+
def HLSLROV : InheritableAttr {
4608+
let Spellings = [CXX11<"hlsl", "is_rov">];
4609+
let Subjects = SubjectList<[Struct]>;
4610+
let LangOpts = [HLSL];
4611+
let Documentation = [InternalOnly];
4612+
}
4613+
46084614
def HLSLResourceClass : InheritableAttr {
46094615
let Spellings = [CXX11<"hlsl", "resource_class">];
46104616
let Subjects = SubjectList<[Struct]>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6802,77 +6802,103 @@ def UnsafeBufferUsageDocs : Documentation {
68026802
let Category = DocCatFunction;
68036803
let Content = [{
68046804
The attribute ``[[clang::unsafe_buffer_usage]]`` should be placed on functions
6805-
that need to be avoided as they are prone to buffer overflows. It is designed to
6806-
work together with the off-by-default compiler warning ``-Wunsafe-buffer-usage``
6807-
to help codebases transition away from raw pointer based buffer management,
6808-
in favor of safer abstractions such as C++20 ``std::span``. The attribute causes
6809-
``-Wunsafe-buffer-usage`` to warn on every use of the function, and it may
6810-
enable ``-Wunsafe-buffer-usage`` to emit automatic fix-it hints
6811-
which would help the user replace such unsafe functions with safe
6805+
that need to be avoided as they are prone to buffer overflows or unsafe buffer
6806+
struct fields. It is designed to work together with the off-by-default compiler
6807+
warning ``-Wunsafe-buffer-usage``to help codebases transition away from raw pointer
6808+
based buffer management, in favor of safer abstractions such as C++20 ``std::span``.
6809+
The attribute causes ``-Wunsafe-buffer-usage`` to warn on every use of the function or
6810+
the field it is attached to, and it may also lead to emission of automatic fix-it
6811+
hints which would help the user replace the use of unsafe functions(/fields) with safe
68126812
alternatives, though the attribute can be used even when the fix can't be automated.
68136813

6814-
The attribute does not suppress ``-Wunsafe-buffer-usage`` inside the function
6815-
to which it is attached. These warnings still need to be addressed.
6814+
* Attribute attached to functions: The attribute does not suppress
6815+
``-Wunsafe-buffer-usage`` inside the function to which it is attached.
6816+
These warnings still need to be addressed.
68166817

6817-
The attribute is warranted even if the only way a function can overflow
6818-
the buffer is by violating the function's preconditions. For example, it
6819-
would make sense to put the attribute on function ``foo()`` below because
6820-
passing an incorrect size parameter would cause a buffer overflow:
6818+
The attribute is warranted even if the only way a function can overflow
6819+
the buffer is by violating the function's preconditions. For example, it
6820+
would make sense to put the attribute on function ``foo()`` below because
6821+
passing an incorrect size parameter would cause a buffer overflow:
68216822

6822-
.. code-block:: c++
6823+
.. code-block:: c++
68236824

6824-
[[clang::unsafe_buffer_usage]]
6825-
void foo(int *buf, size_t size) {
6826-
for (size_t i = 0; i < size; ++i) {
6827-
buf[i] = i;
6825+
[[clang::unsafe_buffer_usage]]
6826+
void foo(int *buf, size_t size) {
6827+
for (size_t i = 0; i < size; ++i) {
6828+
buf[i] = i;
6829+
}
68286830
}
6829-
}
68306831

6831-
The attribute is NOT warranted when the function uses safe abstractions,
6832-
assuming that these abstractions weren't misused outside the function.
6833-
For example, function ``bar()`` below doesn't need the attribute,
6834-
because assuming that the container ``buf`` is well-formed (has size that
6835-
fits the original buffer it refers to), overflow cannot occur:
6832+
The attribute is NOT warranted when the function uses safe abstractions,
6833+
assuming that these abstractions weren't misused outside the function.
6834+
For example, function ``bar()`` below doesn't need the attribute,
6835+
because assuming that the container ``buf`` is well-formed (has size that
6836+
fits the original buffer it refers to), overflow cannot occur:
68366837

6837-
.. code-block:: c++
6838+
.. code-block:: c++
68386839

6839-
void bar(std::span<int> buf) {
6840-
for (size_t i = 0; i < buf.size(); ++i) {
6841-
buf[i] = i;
6840+
void bar(std::span<int> buf) {
6841+
for (size_t i = 0; i < buf.size(); ++i) {
6842+
buf[i] = i;
6843+
}
68426844
}
6843-
}
68446845

6845-
In this case function ``bar()`` enables the user to keep the buffer
6846-
"containerized" in a span for as long as possible. On the other hand,
6847-
Function ``foo()`` in the previous example may have internal
6848-
consistency, but by accepting a raw buffer it requires the user to unwrap
6849-
their span, which is undesirable according to the programming model
6850-
behind ``-Wunsafe-buffer-usage``.
6846+
In this case function ``bar()`` enables the user to keep the buffer
6847+
"containerized" in a span for as long as possible. On the other hand,
6848+
Function ``foo()`` in the previous example may have internal
6849+
consistency, but by accepting a raw buffer it requires the user to unwrap
6850+
their span, which is undesirable according to the programming model
6851+
behind ``-Wunsafe-buffer-usage``.
68516852

6852-
The attribute is warranted when a function accepts a raw buffer only to
6853-
immediately put it into a span:
6853+
The attribute is warranted when a function accepts a raw buffer only to
6854+
immediately put it into a span:
68546855

6855-
.. code-block:: c++
6856+
.. code-block:: c++
68566857

6857-
[[clang::unsafe_buffer_usage]]
6858-
void baz(int *buf, size_t size) {
6859-
std::span<int> sp{ buf, size };
6860-
for (size_t i = 0; i < sp.size(); ++i) {
6861-
sp[i] = i;
6858+
[[clang::unsafe_buffer_usage]]
6859+
void baz(int *buf, size_t size) {
6860+
std::span<int> sp{ buf, size };
6861+
for (size_t i = 0; i < sp.size(); ++i) {
6862+
sp[i] = i;
6863+
}
68626864
}
6863-
}
68646865

6865-
In this case ``baz()`` does not contain any unsafe operations, but the awkward
6866-
parameter type causes the caller to unwrap the span unnecessarily.
6867-
Note that regardless of the attribute, code inside ``baz()`` isn't flagged
6868-
by ``-Wunsafe-buffer-usage`` as unsafe. It is definitely undesirable,
6869-
but if ``baz()`` is on an API surface, there is no way to improve it
6870-
to make it as safe as ``bar()`` without breaking the source and binary
6871-
compatibility with existing users of the function. In such cases
6872-
the proper solution would be to create a different function (possibly
6873-
an overload of ``baz()``) that accepts a safe container like ``bar()``,
6874-
and then use the attribute on the original ``baz()`` to help the users
6875-
update their code to use the new function.
6866+
In this case ``baz()`` does not contain any unsafe operations, but the awkward
6867+
parameter type causes the caller to unwrap the span unnecessarily.
6868+
Note that regardless of the attribute, code inside ``baz()`` isn't flagged
6869+
by ``-Wunsafe-buffer-usage`` as unsafe. It is definitely undesirable,
6870+
but if ``baz()`` is on an API surface, there is no way to improve it
6871+
to make it as safe as ``bar()`` without breaking the source and binary
6872+
compatibility with existing users of the function. In such cases
6873+
the proper solution would be to create a different function (possibly
6874+
an overload of ``baz()``) that accepts a safe container like ``bar()``,
6875+
and then use the attribute on the original ``baz()`` to help the users
6876+
update their code to use the new function.
6877+
6878+
* Attribute attached to fields: The attribute should only be attached to
6879+
struct fields, if the fields can not be updated to a safe type with bounds
6880+
check, such as std::span. In other words, the buffers prone to unsafe accesses
6881+
should always be updated to use safe containers/views and attaching the attribute
6882+
must be last resort when such an update is infeasible.
6883+
6884+
The attribute can be placed on individual fields or a set of them as shown below.
6885+
6886+
.. code-block:: c++
6887+
6888+
struct A {
6889+
[[clang::unsafe_buffer_usage]]
6890+
int *ptr1;
6891+
6892+
[[clang::unsafe_buffer_usage]]
6893+
int *ptr2, buf[10];
6894+
6895+
[[clang::unsafe_buffer_usage]]
6896+
size_t sz;
6897+
};
6898+
6899+
Here, every read/write to the fields ptr1, ptr2, buf and sz will trigger a warning
6900+
that the field has been explcitly marked as unsafe due to unsafe-buffer operations.
6901+
68766902
}];
68776903
}
68786904

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,8 @@ def err_concept_no_parameters : Error<
30123012
"specialization of concepts is not allowed">;
30133013
def err_concept_extra_headers : Error<
30143014
"extraneous template parameter list in concept definition">;
3015+
def err_recursive_concept : Error<
3016+
"a concept definition cannot refer to itself">;
30153017
def err_concept_no_associated_constraints : Error<
30163018
"concept cannot have associated constraints">;
30173019
def err_non_constant_constraint_expression : Error<
@@ -8971,6 +8973,8 @@ def err_atomic_op_has_invalid_synch_scope : Error<
89718973
def warn_atomic_implicit_seq_cst : Warning<
89728974
"implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary">,
89738975
InGroup<DiagGroup<"atomic-implicit-seq-cst">>, DefaultIgnore;
8976+
def err_atomic_unsupported : Error<
8977+
"atomic types are not supported in '%0'">;
89748978

89758979
def err_overflow_builtin_must_be_int : Error<
89768980
"operand argument to %select{overflow builtin|checked integer operation}0 "
@@ -12382,7 +12386,8 @@ def warn_unsafe_buffer_variable : Warning<
1238212386
InGroup<UnsafeBufferUsage>, DefaultIgnore;
1238312387
def warn_unsafe_buffer_operation : Warning<
1238412388
"%select{unsafe pointer operation|unsafe pointer arithmetic|"
12385-
"unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data}0">,
12389+
"unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data|"
12390+
"field %1 prone to unsafe buffer manipulation}0">,
1238612391
InGroup<UnsafeBufferUsage>, DefaultIgnore;
1238712392
def note_unsafe_buffer_operation : Note<
1238812393
"used%select{| in pointer arithmetic| in buffer access}0 here">;

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYCXX)
502502
TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
503503

504504
// GNU and MS Type Traits
505+
TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
505506
TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
506507
TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
507508
TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12033,14 +12033,17 @@ class Sema final : public SemaBase {
1203312033

1203412034
void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
1203512035

12036-
Decl *ActOnConceptDefinition(Scope *S,
12037-
MultiTemplateParamsArg TemplateParameterLists,
12038-
const IdentifierInfo *Name,
12039-
SourceLocation NameLoc, Expr *ConstraintExpr,
12040-
const ParsedAttributesView &Attrs);
12036+
ConceptDecl *ActOnStartConceptDefinition(
12037+
Scope *S, MultiTemplateParamsArg TemplateParameterLists,
12038+
const IdentifierInfo *Name, SourceLocation NameLoc);
12039+
12040+
ConceptDecl *ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C,
12041+
Expr *ConstraintExpr,
12042+
const ParsedAttributesView &Attrs);
1204112043

1204212044
void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
1204312045
bool &AddToScope);
12046+
bool CheckConceptUseInDefinition(ConceptDecl *Concept, SourceLocation Loc);
1204412047

1204512048
TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1204612049
const CXXScopeSpec &SS,

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class SemaHLSL : public SemaBase {
5656
void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
5757
void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
5858
void handleShaderAttr(Decl *D, const ParsedAttr &AL);
59+
void handleROVAttr(Decl *D, const ParsedAttr &AL);
5960
void handleResourceClassAttr(Decl *D, const ParsedAttr &AL);
6061
void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL);
6162
void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);

0 commit comments

Comments
 (0)