Skip to content

Commit d9cd7cb

Browse files
authored
Merge branch 'main' into x86-mask-broadcast
2 parents 295bc7f + 9734aa8 commit d9cd7cb

File tree

126 files changed

+3842
-1354
lines changed

Some content is hidden

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

126 files changed

+3842
-1354
lines changed

clang/docs/PointerAuthentication.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,36 @@ The result value is never zero and always within range for both the
592592

593593
This can be used in constant expressions.
594594

595+
``ptrauth_type_discriminator``
596+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
597+
598+
.. code-block:: c
599+
600+
ptrauth_type_discriminator(type)
601+
602+
Compute the constant discriminator derived from the given type, as is computed
603+
for automatically type diversified schemas.
604+
605+
``type`` must be a type. The result has the type ``ptrauth_extra_data_t``.
606+
607+
This can be used in constant expressions.
608+
609+
``ptrauth_function_pointer_type_discriminator``
610+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
611+
612+
.. code-block:: c
613+
614+
ptrauth_function_pointer_type_discriminator(function_type)
615+
616+
Compute the constant discriminator derived from the provided function type, for
617+
use in contexts where the default function authentication schema. If function
618+
pointer type diversity is enabled, this is equivalent to
619+
`ptrauth_type_discriminator(function_type)`, if it is not enabled this is `0`.
620+
621+
``function_type`` must be a function type. The result has the type ``ptrauth_extra_data_t``.
622+
623+
This can be used in constant expressions.
624+
595625
``ptrauth_strip``
596626
^^^^^^^^^^^^^^^^^
597627

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ C23 Feature Support
191191
- Added ``FLT_SNAN``, ``DBL_SNAN``, and ``LDBL_SNAN`` to Clang's ``<float.h>``
192192
header in C23 and later modes. This implements
193193
`WG14 N2710 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2710.htm>`_.
194+
- Fixed accepting as compatible unnamed tag types with the same fields within
195+
the same translation unit but from different types.
194196

195197
Non-comprehensive list of changes in this release
196198
-------------------------------------------------
@@ -513,6 +515,7 @@ X86 Support
513515
driver.
514516
- Remove `[no-]evex512` feature request from intrinsics and builtins.
515517
- Change features `avx10.x-[256,512]` to `avx10.x`.
518+
- `-march=wildcatlake` is now supported.
516519

517520
Arm and AArch64 Support
518521
^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11581,6 +11581,12 @@ QualType ASTContext::mergeTagDefinitions(QualType LHS, QualType RHS) {
1158111581
if (LangOpts.CPlusPlus || !LangOpts.C23)
1158211582
return {};
1158311583

11584+
// Nameless tags are comparable only within outer definitions. At the top
11585+
// level they are not comparable.
11586+
const TagDecl *LTagD = LHS->castAsTagDecl(), *RTagD = RHS->castAsTagDecl();
11587+
if (!LTagD->getIdentifier() || !RTagD->getIdentifier())
11588+
return {};
11589+
1158411590
// C23, on the other hand, requires the members to be "the same enough", so
1158511591
// we use a structural equivalence check.
1158611592
StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls;

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,19 +1763,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
17631763
// another anonymous structure or union, respectively, if their members
17641764
// fulfill the preceding requirements. ... Otherwise, the structure, union,
17651765
// or enumerated types are incompatible.
1766-
1767-
// Note: "the same tag" refers to the identifier for the structure; two
1768-
// structures without names are not compatible within a TU. In C23, if either
1769-
// declaration has no name, they're not equivalent. However, the paragraph
1770-
// after the bulleted list goes on to talk about compatibility of anonymous
1771-
// structure and union members, so this prohibition only applies to top-level
1772-
// declarations; if either declaration is not a member, they cannot be
1773-
// compatible.
1774-
if (Context.LangOpts.C23 && (!D1->getIdentifier() || !D2->getIdentifier()) &&
1775-
(!D1->getDeclContext()->isRecord() || !D2->getDeclContext()->isRecord()))
1776-
return false;
1777-
1778-
// Otherwise, check the names for equivalence.
17791766
if (!NameIsStructurallyEquivalent(*D1, *D2))
17801767
return false;
17811768

clang/lib/AST/DeclBase.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Context,
7777
*PrefixPtr = ID.getRawValue();
7878

7979
// We leave the upper 16 bits to store the module IDs. 48 bits should be
80-
// sufficient to store a declaration ID.
81-
assert(*PrefixPtr < llvm::maskTrailingOnes<uint64_t>(48));
80+
// sufficient to store a declaration ID. See the comments in setOwningModuleID
81+
// for details.
82+
assert((*PrefixPtr < llvm::maskTrailingOnes<uint64_t>(48)) &&
83+
"Current Implementation limits the number of module files to not "
84+
"exceed 2^16. Contact Clang Developers to remove the limitation.");
8285

8386
return Result;
8487
}
@@ -122,6 +125,25 @@ unsigned Decl::getOwningModuleID() const {
122125

123126
void Decl::setOwningModuleID(unsigned ID) {
124127
assert(isFromASTFile() && "Only works on a deserialized declaration");
128+
// Currently, we use 64 bits to store the GlobalDeclID and the module ID
129+
// to save the space. See `Decl::operator new` for details. To make it,
130+
// we split the higher 32 bits to 2 16bits for the module file index of
131+
// GlobalDeclID and the module ID. This introduces a limitation that the
132+
// number of modules can't exceed 2^16. (The number of module files should be
133+
// less than the number of modules).
134+
//
135+
// It is counter-intuitive to store both the module file index and the
136+
// module ID as it seems redundant. However, this is not true.
137+
// The module ID may be different from the module file where it is serialized
138+
// from for implicit template instantiations. See
139+
// https://github.com/llvm/llvm-project/issues/101939
140+
//
141+
// If we reach the limitation, we have to remove the limitation by asking
142+
// every deserialized declaration to pay for yet another 32 bits, or we have
143+
// to review the above issue to decide what we should do for it.
144+
assert((ID < llvm::maskTrailingOnes<unsigned>(16)) &&
145+
"Current Implementation limits the number of modules to not exceed "
146+
"2^16. Contact Clang Developers to remove the limitation.");
125147
uint64_t *IDAddress = (uint64_t *)this - 1;
126148
*IDAddress &= llvm::maskTrailingOnes<uint64_t>(48);
127149
*IDAddress |= (uint64_t)ID << 48;

clang/lib/Basic/Targets/X86.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
625625
case CK_ArrowlakeS:
626626
case CK_Lunarlake:
627627
case CK_Pantherlake:
628+
case CK_Wildcatlake:
628629
case CK_Sierraforest:
629630
case CK_Grandridge:
630631
case CK_Graniterapids:
@@ -1613,6 +1614,7 @@ std::optional<unsigned> X86TargetInfo::getCPUCacheLineSize() const {
16131614
case CK_ArrowlakeS:
16141615
case CK_Lunarlake:
16151616
case CK_Pantherlake:
1617+
case CK_Wildcatlake:
16161618
case CK_Sierraforest:
16171619
case CK_Grandridge:
16181620
case CK_Graniterapids:

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl &d) {
536536
mlir::Block *currBlock = builder.getBlock();
537537
mlir::Block *labelBlock = currBlock;
538538

539-
if (!currBlock->empty()) {
539+
if (!currBlock->empty() || currBlock->isEntryBlock()) {
540540
{
541541
mlir::OpBuilder::InsertionGuard guard(builder);
542542
labelBlock = builder.createBlock(builder.getBlock()->getParent());

clang/lib/Headers/ptrauth.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
241241
#define ptrauth_type_discriminator(__type) \
242242
__builtin_ptrauth_type_discriminator(__type)
243243

244+
/* Compute the constant discriminator used by Clang to sign pointers with the
245+
given C function pointer type.
246+
247+
A call to this function is an integer constant expression. */
248+
#if __has_feature(ptrauth_function_pointer_type_discrimination)
249+
#define ptrauth_function_pointer_type_discriminator(__type) \
250+
__builtin_ptrauth_type_discriminator(__type)
251+
#else
252+
#define ptrauth_function_pointer_type_discriminator(__type) \
253+
((ptrauth_extra_data_t)0)
254+
#endif
255+
244256
/* Compute a signature for the given pair of pointer-sized values.
245257
The order of the arguments is significant.
246258
@@ -372,6 +384,8 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
372384
})
373385

374386
#define ptrauth_type_discriminator(__type) ((ptrauth_extra_data_t)0)
387+
#define ptrauth_function_pointer_type_discriminator(__type) \
388+
((ptrauth_extra_data_t)0)
375389

376390
#define ptrauth_sign_generic_data(__value, __data) \
377391
({ \

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bool tryToFindPtrOrigin(
2626
const Expr *E, bool StopAtFirstRefCountedObj,
2727
std::function<bool(const clang::CXXRecordDecl *)> isSafePtr,
2828
std::function<bool(const clang::QualType)> isSafePtrType,
29+
std::function<bool(const clang::Decl *)> isSafeGlobalDecl,
2930
std::function<bool(const clang::Expr *, bool)> callback) {
3031
while (E) {
3132
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -34,6 +35,8 @@ bool tryToFindPtrOrigin(
3435
auto IsImmortal = safeGetName(VD) == "NSApp";
3536
if (VD->hasGlobalStorage() && (IsImmortal || QT.isConstQualified()))
3637
return callback(E, true);
38+
if (VD->hasGlobalStorage() && isSafeGlobalDecl(VD))
39+
return callback(E, true);
3740
}
3841
}
3942
if (auto *tempExpr = dyn_cast<MaterializeTemporaryExpr>(E)) {
@@ -71,9 +74,11 @@ bool tryToFindPtrOrigin(
7174
}
7275
if (auto *Expr = dyn_cast<ConditionalOperator>(E)) {
7376
return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj,
74-
isSafePtr, isSafePtrType, callback) &&
77+
isSafePtr, isSafePtrType, isSafeGlobalDecl,
78+
callback) &&
7579
tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj,
76-
isSafePtr, isSafePtrType, callback);
80+
isSafePtr, isSafePtrType, isSafeGlobalDecl,
81+
callback);
7782
}
7883
if (auto *cast = dyn_cast<CastExpr>(E)) {
7984
if (StopAtFirstRefCountedObj) {

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bool tryToFindPtrOrigin(
5656
const clang::Expr *E, bool StopAtFirstRefCountedObj,
5757
std::function<bool(const clang::CXXRecordDecl *)> isSafePtr,
5858
std::function<bool(const clang::QualType)> isSafePtrType,
59+
std::function<bool(const clang::Decl *)> isSafeGlobalDecl,
5960
std::function<bool(const clang::Expr *, bool)> callback);
6061

6162
/// For \p E referring to a ref-countable/-counted pointer/reference we return

0 commit comments

Comments
 (0)