Skip to content

Commit 950076c

Browse files
committed
Vendor import of llvm-project main llvmorg-18-init-16864-g3b3ee1f53424.
1 parent aca2e42 commit 950076c

241 files changed

Lines changed: 5209 additions & 2318 deletions

File tree

Some content is hidden

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

clang/include/clang/AST/DeclBase.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/SelectorLocationsKind.h"
2020
#include "clang/Basic/IdentifierTable.h"
2121
#include "clang/Basic/LLVM.h"
22+
#include "clang/Basic/LangOptions.h"
2223
#include "clang/Basic/SourceLocation.h"
2324
#include "clang/Basic/Specifiers.h"
2425
#include "llvm/ADT/ArrayRef.h"
@@ -488,6 +489,15 @@ class alignas(8) Decl {
488489
// Return true if this is a FileContext Decl.
489490
bool isFileContextDecl() const;
490491

492+
/// Whether it resembles a flexible array member. This is a static member
493+
/// because we want to be able to call it with a nullptr. That allows us to
494+
/// perform non-Decl specific checks based on the object's type and strict
495+
/// flex array level.
496+
static bool isFlexibleArrayMemberLike(
497+
ASTContext &Context, const Decl *D, QualType Ty,
498+
LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
499+
bool IgnoreTemplateOrMacroSubstitution);
500+
491501
ASTContext &getASTContext() const LLVM_READONLY;
492502

493503
/// Helper to get the language options from the ASTContext.

clang/include/clang/AST/DeclCXX.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
14251425
/// (C++11 [class]p6).
14261426
bool isTriviallyCopyable() const;
14271427

1428+
/// Determine whether this class is considered trivially copyable per
1429+
bool isTriviallyCopyConstructible() const;
1430+
14281431
/// Determine whether this class is considered trivial.
14291432
///
14301433
/// C++11 [class]p6:

clang/include/clang/AST/Stmt.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,10 @@ class CompoundStmt final
16311631
SourceLocation RB);
16321632

16331633
// Build an empty compound statement with a location.
1634-
explicit CompoundStmt(SourceLocation Loc)
1635-
: Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
1634+
explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
1635+
1636+
CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
1637+
: Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
16361638
CompoundStmtBits.NumStmts = 0;
16371639
CompoundStmtBits.HasFPFeatures = 0;
16381640
}

clang/include/clang/AST/Type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ class QualType {
917917
/// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
918918
bool isTriviallyCopyableType(const ASTContext &Context) const;
919919

920+
/// Return true if this is a trivially copyable type
921+
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
922+
920923
/// Return true if this is a trivially relocatable type.
921924
bool isTriviallyRelocatableType(const ASTContext &Context) const;
922925

clang/include/clang/Basic/Attr.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,3 +4372,21 @@ def CodeAlign: StmtAttr {
43724372
static constexpr int MaximumAlignment = 4096;
43734373
}];
43744374
}
4375+
4376+
def CountedBy : InheritableAttr {
4377+
let Spellings = [Clang<"counted_by">];
4378+
let Subjects = SubjectList<[Field]>;
4379+
let Args = [IdentifierArgument<"CountedByField">];
4380+
let Documentation = [CountedByDocs];
4381+
let LangOpts = [COnly];
4382+
// FIXME: This is ugly. Let using a DeclArgument would be nice, but a Decl
4383+
// isn't yet available due to the fact that we're still parsing the
4384+
// structure. Maybe that code could be changed sometime in the future.
4385+
code AdditionalMembers = [{
4386+
private:
4387+
SourceRange CountedByFieldLoc;
4388+
public:
4389+
SourceRange getCountedByFieldLoc() const { return CountedByFieldLoc; }
4390+
void setCountedByFieldLoc(SourceRange Loc) { CountedByFieldLoc = Loc; }
4391+
}];
4392+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7749,3 +7749,81 @@ but do not pass them to the underlying coroutine or pass them by value.
77497749
.. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
77507750
}];
77517751
}
7752+
7753+
def CountedByDocs : Documentation {
7754+
let Category = DocCatField;
7755+
let Content = [{
7756+
Clang supports the ``counted_by`` attribute on the flexible array member of a
7757+
structure in C. The argument for the attribute is the name of a field member
7758+
holding the count of elements in the flexible array. This information can be
7759+
used to improve the results of the array bound sanitizer and the
7760+
``__builtin_dynamic_object_size`` builtin. The ``count`` field member must be
7761+
within the same non-anonymous, enclosing struct as the flexible array member.
7762+
7763+
This example specifies that the flexible array member ``array`` has the number
7764+
of elements allocated for it in ``count``:
7765+
7766+
.. code-block:: c
7767+
7768+
struct bar;
7769+
7770+
struct foo {
7771+
size_t count;
7772+
char other;
7773+
struct bar *array[] __attribute__((counted_by(count)));
7774+
};
7775+
7776+
This establishes a relationship between ``array`` and ``count``. Specifically,
7777+
``array`` must have at least ``count`` number of elements available. It's the
7778+
user's responsibility to ensure that this relationship is maintained through
7779+
changes to the structure.
7780+
7781+
In the following example, the allocated array erroneously has fewer elements
7782+
than what's specified by ``p->count``. This would result in an out-of-bounds
7783+
access not being detected.
7784+
7785+
.. code-block:: c
7786+
7787+
#define SIZE_INCR 42
7788+
7789+
struct foo *p;
7790+
7791+
void foo_alloc(size_t count) {
7792+
p = malloc(MAX(sizeof(struct foo),
7793+
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7794+
p->count = count + SIZE_INCR;
7795+
}
7796+
7797+
The next example updates ``p->count``, but breaks the relationship requirement
7798+
that ``p->array`` must have at least ``p->count`` number of elements available:
7799+
7800+
.. code-block:: c
7801+
7802+
#define SIZE_INCR 42
7803+
7804+
struct foo *p;
7805+
7806+
void foo_alloc(size_t count) {
7807+
p = malloc(MAX(sizeof(struct foo),
7808+
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7809+
p->count = count;
7810+
}
7811+
7812+
void use_foo(int index, int val) {
7813+
p->count += SIZE_INCR + 1; /* 'count' is now larger than the number of elements of 'array'. */
7814+
p->array[index] = val; /* The sanitizer can't properly check this access. */
7815+
}
7816+
7817+
In this example, an update to ``p->count`` maintains the relationship
7818+
requirement:
7819+
7820+
.. code-block:: c
7821+
7822+
void use_foo(int index, int val) {
7823+
if (p->count == 0)
7824+
return;
7825+
--p->count;
7826+
p->array[index] = val;
7827+
}
7828+
}];
7829+
}

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def err_verify_no_such_marker : Error<
167167
def err_verify_missing_start : Error<
168168
"cannot find start ('{{') of expected %0">;
169169
def err_verify_missing_end : Error<
170-
"cannot find end ('}}') of expected %0">;
170+
"cannot find end ('%1') of expected %0">;
171171
def err_verify_invalid_content : Error<
172172
"invalid expected %0: %1">;
173173
def err_verify_missing_regex : Error<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
22532253
def err_reference_bind_to_bitfield : Error<
22542254
"%select{non-const|volatile}0 reference cannot bind to "
22552255
"bit-field%select{| %1}2">;
2256+
def err_reference_bind_to_bitfield_in_cce : Error<
2257+
"reference cannot bind to bit-field in converted constant expression">;
22562258
def err_reference_bind_to_vector_element : Error<
22572259
"%select{non-const|volatile}0 reference cannot bind to vector element">;
22582260
def err_reference_bind_to_matrix_element : Error<
@@ -6439,6 +6441,19 @@ def warn_superclass_variable_sized_type_not_at_end : Warning<
64396441
"field %0 can overwrite instance variable %1 with variable sized type %2"
64406442
" in superclass %3">, InGroup<ObjCFlexibleArray>;
64416443

6444+
def err_flexible_array_count_not_in_same_struct : Error<
6445+
"'counted_by' field %0 isn't within the same struct as the flexible array">;
6446+
def err_counted_by_attr_not_on_flexible_array_member : Error<
6447+
"'counted_by' only applies to C99 flexible array members">;
6448+
def err_counted_by_attr_refers_to_flexible_array : Error<
6449+
"'counted_by' cannot refer to the flexible array %0">;
6450+
def err_counted_by_must_be_in_structure : Error<
6451+
"field %0 in 'counted_by' not inside structure">;
6452+
def err_flexible_array_counted_by_attr_field_not_integer : Error<
6453+
"field %0 in 'counted_by' must be a non-boolean integer type">;
6454+
def note_flexible_array_counted_by_attr_field : Note<
6455+
"field %0 declared here">;
6456+
64426457
let CategoryName = "ARC Semantic Issue" in {
64436458

64446459
// ARC-mode diagnostics.

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ ENUM_LANGOPT(SignReturnAddressKey, SignReturnAddressKeyKind, 1, SignReturnAddres
457457
"Key used for return address signing")
458458
LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled")
459459
LANGOPT(BranchProtectionPAuthLR, 1, 0, "Use PC as a diversifier using PAuthLR NOP instructions.")
460+
LANGOPT(GuardedControlStack, 1, 0, "Guarded control stack enabled")
460461

461462
LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled")
462463

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ class TargetInfo : public TransferrableTargetInfo,
13731373
LangOptions::SignReturnAddressKeyKind::AKey;
13741374
bool BranchTargetEnforcement = false;
13751375
bool BranchProtectionPAuthLR = false;
1376+
bool GuardedControlStack = false;
13761377
};
13771378

13781379
/// Determine if the Architecture in this TargetInfo supports branch

0 commit comments

Comments
 (0)