Skip to content

Commit cce60ce

Browse files
committed
Rebase
Created using spr 1.3.5
2 parents efe2e4d + b157599 commit cce60ce

File tree

152 files changed

+3933
-2090
lines changed

Some content is hidden

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

152 files changed

+3933
-2090
lines changed

.github/workflows/bazel-checks.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Bazel Checks
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
paths:
9+
- '.github/workflows/bazel-checks.yml'
10+
- 'utils/bazel/**'
11+
branches:
12+
- main
13+
pull_request:
14+
paths:
15+
- '.github/workflows/bazel-checks.yml'
16+
- 'utils/bazel/**'
17+
18+
jobs:
19+
buildifier:
20+
name: "Buildifier"
21+
runs-on: ubuntu-24.04
22+
if: github.repository == 'llvm/llvm-project'
23+
steps:
24+
- name: Fetch LLVM sources
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
- name: Setup Buildifier
27+
run: |
28+
sudo curl -L https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-linux-amd64 -o /usr/bin/buildifier
29+
sudo chmod +x /usr/bin/buildifier
30+
- name: Run Buildifier
31+
run: |
32+
buildifier --mode=check $(find ./utils/bazel -name *BUILD*)

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ autoconf/autom4te.cache
5252
# CLion project configuration
5353
/.idea
5454
/cmake-build*
55+
# Coding assistants' stuff
56+
/CLAUDE.md
57+
/.claude/
58+
/GEMINI.md
59+
/.gemini/
5560

5661
#==============================================================================#
5762
# Directories to ignore (do not add trailing '/'s, they skip symlinks).

clang/docs/LanguageExtensions.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,11 +1715,40 @@ Variadic Friends __cpp_variadic_friend C
17151715
Trivial Relocatability __cpp_trivial_relocatability C++26 C++03
17161716
--------------------------------------------- -------------------------------- ------------- -------------
17171717
Designated initializers (N494) C99 C89
1718+
``_Complex`` (N693) C99 C89, C++
1719+
``_Bool`` (N815) C99 C89
1720+
Variable-length arrays (N683) C99 C89, C++
1721+
Flexible array members C99 C89, C++
1722+
static and type quals in arrays C99 C89
1723+
``long long`` (N601) C99 C89
1724+
Hexadecimal floating constants (N308) C99 C89
1725+
Compound literals (N716) C99 C89, C++
1726+
``//`` comments (N644) C99 C89
1727+
Mixed declarations and code (N740) C99 C89
1728+
Variadic macros (N707) C99 C89
1729+
Empty macro arguments (N570) C99 C89
1730+
Trailing comma in enum declaration C99 C89
1731+
Implicit ``return 0`` in ``main`` C99 C89
1732+
``__func__`` (N611) C99 C89
1733+
``_Generic`` (N1441) C11 C89, C++
1734+
``_Static_assert`` (N1330) C11 C89, C++
1735+
``_Atomic`` (N1485) C11 C89, C++
1736+
``_Thread_local`` (N1364) C11 C89, C++
17181737
Array & element qualification (N2607) C23 C89
17191738
Attributes (N2335) C23 C89
17201739
``#embed`` (N3017) C23 C89, C++
1740+
Enum with fixed underlying type (N3030) C23 C89
1741+
``#warning`` (N2686) C23 C89
1742+
``_BitInt`` (N3035) C23 C89, C++
1743+
Binary literals (N2549) C23 C89
1744+
Unnamed parameters in a function definition C23 C89
1745+
Free positioning of labels (N2508) C23 C89
1746+
``#elifdef`` (N2645) C23 C89
1747+
``__has_include`` (N2799) C23 C89
17211748
Octal literals prefixed with ``0o`` or ``0O`` C2y C89, C++
17221749
``_Countof`` (N3369, N3469) C2y C89
1750+
``_Generic`` with a type operand (N3260) C2y C89, C++
1751+
``++``/``--`` on ``_Complex`` value (N3259) C2y C89, C++
17231752
============================================= ================================ ============= =============
17241753

17251754
Builtin type aliases

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ AST Dumping Potentially Breaking Changes
7777

7878
Clang Frontend Potentially Breaking Changes
7979
-------------------------------------------
80+
- Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``
81+
into the enclosing record even if their names conflict with other names in the
82+
scope. These ``IndirectFieldDecl`` are marked invalid.
8083

8184
Clang Python Bindings Potentially Breaking Changes
8285
--------------------------------------------------
@@ -217,6 +220,8 @@ Bug Fixes to C++ Support
217220
- Fix the dynamic_cast to final class optimization to correctly handle
218221
casts that are guaranteed to fail (#GH137518).
219222
- Fix bug rejecting partial specialization of variable templates with auto NTTPs (#GH118190).
223+
- Fix a crash if errors "member of anonymous [...] redeclares" and
224+
"intializing multiple members of union" coincide (#GH149985).
220225
- Fix a crash when using ``explicit(bool)`` in pre-C++11 language modes. (#GH152729)
221226
- Fix the parsing of variadic member functions when the ellipis immediately follows a default argument.(#GH153445)
222227

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
23382338
llvm_unreachable("Wrong builtin ID");
23392339
}
23402340

2341-
pushInteger(S, APSInt(Result, !LHS.isSigned()), Call->getType());
2341+
pushInteger(S, APSInt(std::move(Result), !LHS.isSigned()), Call->getType());
23422342
return true;
23432343
}
23442344

clang/lib/Headers/emmintrin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717
#include <xmmintrin.h>
1818

1919
typedef double __m128d __attribute__((__vector_size__(16), __aligned__(16)));
20-
typedef long long __m128i __attribute__((__vector_size__(16), __aligned__(16)));
2120

2221
typedef double __m128d_u __attribute__((__vector_size__(16), __aligned__(1)));
2322
typedef long long __m128i_u
2423
__attribute__((__vector_size__(16), __aligned__(1)));
2524

2625
/* Type defines. */
2726
typedef double __v2df __attribute__((__vector_size__(16)));
28-
typedef long long __v2di __attribute__((__vector_size__(16)));
29-
typedef short __v8hi __attribute__((__vector_size__(16)));
30-
typedef char __v16qi __attribute__((__vector_size__(16)));
3127

3228
/* Unsigned types */
3329
typedef unsigned long long __v2du __attribute__((__vector_size__(16)));

clang/lib/Headers/xmmintrin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <mmintrin.h>
1818

19-
typedef int __v4si __attribute__((__vector_size__(16)));
2019
typedef float __v4sf __attribute__((__vector_size__(16)));
2120
typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
2221

clang/lib/Sema/SemaDecl.cpp

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5503,48 +5503,54 @@ InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner,
55035503
if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) &&
55045504
cast<NamedDecl>(D)->getDeclName()) {
55055505
ValueDecl *VD = cast<ValueDecl>(D);
5506-
if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(),
5507-
VD->getLocation(), AnonRecord->isUnion(),
5508-
SC)) {
5509-
// C++ [class.union]p2:
5510-
// The names of the members of an anonymous union shall be
5511-
// distinct from the names of any other entity in the
5512-
// scope in which the anonymous union is declared.
5506+
// C++ [class.union]p2:
5507+
// The names of the members of an anonymous union shall be
5508+
// distinct from the names of any other entity in the
5509+
// scope in which the anonymous union is declared.
5510+
5511+
bool FieldInvalid = CheckAnonMemberRedeclaration(
5512+
SemaRef, S, Owner, VD->getDeclName(), VD->getLocation(),
5513+
AnonRecord->isUnion(), SC);
5514+
if (FieldInvalid)
55135515
Invalid = true;
5514-
} else {
5515-
// C++ [class.union]p2:
5516-
// For the purpose of name lookup, after the anonymous union
5517-
// definition, the members of the anonymous union are
5518-
// considered to have been defined in the scope in which the
5519-
// anonymous union is declared.
5520-
unsigned OldChainingSize = Chaining.size();
5521-
if (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(VD))
5522-
Chaining.append(IF->chain_begin(), IF->chain_end());
5523-
else
5524-
Chaining.push_back(VD);
55255516

5526-
assert(Chaining.size() >= 2);
5527-
NamedDecl **NamedChain =
5528-
new (SemaRef.Context)NamedDecl*[Chaining.size()];
5529-
for (unsigned i = 0; i < Chaining.size(); i++)
5530-
NamedChain[i] = Chaining[i];
5517+
// Inject the IndirectFieldDecl even if invalid, because later
5518+
// diagnostics may depend on it being present, see findDefaultInitializer.
5519+
5520+
// C++ [class.union]p2:
5521+
// For the purpose of name lookup, after the anonymous union
5522+
// definition, the members of the anonymous union are
5523+
// considered to have been defined in the scope in which the
5524+
// anonymous union is declared.
5525+
unsigned OldChainingSize = Chaining.size();
5526+
if (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(VD))
5527+
Chaining.append(IF->chain_begin(), IF->chain_end());
5528+
else
5529+
Chaining.push_back(VD);
55315530

5532-
IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create(
5533-
SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(),
5534-
VD->getType(), {NamedChain, Chaining.size()});
5531+
assert(Chaining.size() >= 2);
5532+
NamedDecl **NamedChain =
5533+
new (SemaRef.Context) NamedDecl *[Chaining.size()];
5534+
for (unsigned i = 0; i < Chaining.size(); i++)
5535+
NamedChain[i] = Chaining[i];
55355536

5536-
for (const auto *Attr : VD->attrs())
5537-
IndirectField->addAttr(Attr->clone(SemaRef.Context));
5537+
IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create(
5538+
SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(),
5539+
VD->getType(), {NamedChain, Chaining.size()});
55385540

5539-
IndirectField->setAccess(AS);
5540-
IndirectField->setImplicit();
5541-
SemaRef.PushOnScopeChains(IndirectField, S);
5541+
for (const auto *Attr : VD->attrs())
5542+
IndirectField->addAttr(Attr->clone(SemaRef.Context));
55425543

5543-
// That includes picking up the appropriate access specifier.
5544-
if (AS != AS_none) IndirectField->setAccess(AS);
5544+
IndirectField->setAccess(AS);
5545+
IndirectField->setImplicit();
5546+
IndirectField->setInvalidDecl(FieldInvalid);
5547+
SemaRef.PushOnScopeChains(IndirectField, S);
55455548

5546-
Chaining.resize(OldChainingSize);
5547-
}
5549+
// That includes picking up the appropriate access specifier.
5550+
if (AS != AS_none)
5551+
IndirectField->setAccess(AS);
5552+
5553+
Chaining.resize(OldChainingSize);
55485554
}
55495555
}
55505556

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7012,9 +7012,12 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
70127012
for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
70137013
++I) {
70147014
NamedDecl *D = (*I)->getUnderlyingDecl();
7015+
// Invalid IndirectFieldDecls have already been diagnosed with
7016+
// err_anonymous_record_member_redecl in
7017+
// SemaDecl.cpp:CheckAnonMemberRedeclaration.
70157018
if (((isa<FieldDecl>(D) || isa<UnresolvedUsingValueDecl>(D)) &&
70167019
Record->hasUserDeclaredConstructor()) ||
7017-
isa<IndirectFieldDecl>(D)) {
7020+
(isa<IndirectFieldDecl>(D) && !D->isInvalidDecl())) {
70187021
Diag((*I)->getLocation(), diag::err_member_name_of_class)
70197022
<< D->getDeclName();
70207023
break;

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,31 +2604,120 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK, const Expr *VarExpr) {
26042604
QualType VarTy =
26052605
VarExpr->getType().getNonReferenceType().getUnqualifiedType();
26062606

2607+
IdentifierInfo *VarName = [&]() {
2608+
switch (CK) {
2609+
case OpenACCClauseKind::Private:
2610+
return &getASTContext().Idents.get("openacc.private.init");
2611+
case OpenACCClauseKind::FirstPrivate:
2612+
return &getASTContext().Idents.get("openacc.firstprivate.init");
2613+
case OpenACCClauseKind::Reduction:
2614+
return &getASTContext().Idents.get("openacc.reduction.init");
2615+
default:
2616+
llvm_unreachable("Unknown clause kind?");
2617+
}
2618+
}();
2619+
26072620
VarDecl *Recipe = VarDecl::Create(
26082621
getASTContext(), SemaRef.getCurContext(), VarExpr->getBeginLoc(),
2609-
VarExpr->getBeginLoc(),
2610-
&getASTContext().Idents.get("openacc.private.init"), VarTy,
2622+
VarExpr->getBeginLoc(), VarName, VarTy,
26112623
getASTContext().getTrivialTypeSourceInfo(VarTy), SC_Auto);
26122624

26132625
ExprResult Init;
26142626
VarDecl *Temporary = nullptr;
2615-
2616-
if (CK == OpenACCClauseKind::Private) {
2627+
{
26172628
// Trap errors so we don't get weird ones here. If we can't init, we'll just
26182629
// swallow the errors.
26192630
Sema::TentativeAnalysisScope Trap{SemaRef};
26202631
InitializedEntity Entity = InitializedEntity::InitializeVariable(Recipe);
2621-
InitializationKind Kind =
2622-
InitializationKind::CreateDefault(Recipe->getLocation());
26232632

2624-
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, {});
2625-
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, {});
2626-
} else if (CK == OpenACCClauseKind::FirstPrivate) {
2627-
// TODO: OpenACC: Implement this to do a 'copy' operation.
2628-
} else if (CK == OpenACCClauseKind::Reduction) {
2629-
// TODO: OpenACC: Implement this for whatever reduction needs.
2630-
} else {
2631-
llvm_unreachable("Unknown clause kind in CreateInitRecipe");
2633+
if (CK == OpenACCClauseKind::Private) {
2634+
InitializationKind Kind =
2635+
InitializationKind::CreateDefault(Recipe->getLocation());
2636+
2637+
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, {});
2638+
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, {});
2639+
2640+
} else if (CK == OpenACCClauseKind::FirstPrivate) {
2641+
// Create a VarDecl to be the 'copied-from' for the copy section of the
2642+
// recipe. This allows us to make the association so that we can use the
2643+
// standard 'generation' ability of the init.
2644+
Temporary = VarDecl::Create(
2645+
getASTContext(), SemaRef.getCurContext(), VarExpr->getBeginLoc(),
2646+
VarExpr->getBeginLoc(), &getASTContext().Idents.get("openacc.temp"),
2647+
VarTy, getASTContext().getTrivialTypeSourceInfo(VarTy), SC_Auto);
2648+
auto *TemporaryDRE = DeclRefExpr::Create(
2649+
getASTContext(), NestedNameSpecifierLoc{}, SourceLocation{},
2650+
Temporary,
2651+
/*ReferstoEnclosingVariableOrCapture=*/false,
2652+
DeclarationNameInfo{DeclarationName{Temporary->getDeclName()},
2653+
VarExpr->getBeginLoc()},
2654+
VarTy, clang::VK_LValue, Temporary, nullptr, NOUR_None);
2655+
2656+
Expr *InitExpr = nullptr;
2657+
2658+
if (const auto *ArrTy = getASTContext().getAsConstantArrayType(VarTy)) {
2659+
// Arrays need to have each individual element initialized as there
2660+
// isn't a normal 'equals' feature in C/C++. This section sets these up
2661+
// as an init list after 'initializing' each individual element.
2662+
llvm::SmallVector<Expr *> Args;
2663+
2664+
// Decay to pointer for the array subscript expression.
2665+
auto *CastToPtr = ImplicitCastExpr::Create(
2666+
getASTContext(),
2667+
getASTContext().getPointerType(ArrTy->getElementType()),
2668+
CK_ArrayToPointerDecay, TemporaryDRE, /*BasePath=*/nullptr,
2669+
clang::VK_LValue, FPOptionsOverride{});
2670+
2671+
for (std::size_t I = 0; I < ArrTy->getLimitedSize(); ++I) {
2672+
// Each element needs to be some sort of copy initialization from an
2673+
// array-index of the original temporary (referenced via a
2674+
// DeclRefExpr).
2675+
2676+
auto *Idx = IntegerLiteral::Create(
2677+
getASTContext(), llvm::APInt(sizeof(std::size_t) * 8, I),
2678+
getASTContext().getSizeType(), VarExpr->getBeginLoc());
2679+
2680+
Expr *Subscript = new (getASTContext()) ArraySubscriptExpr(
2681+
CastToPtr, Idx, ArrTy->getElementType(), clang::VK_LValue,
2682+
OK_Ordinary, VarExpr->getBeginLoc());
2683+
2684+
// Generate a simple copy from the result of the subscript. This will
2685+
// do a bitwise copy or a copy-constructor, as necessary.
2686+
InitializedEntity CopyEntity =
2687+
InitializedEntity::InitializeElement(getASTContext(), I, Entity);
2688+
InitializationKind CopyKind =
2689+
InitializationKind::CreateCopy(VarExpr->getBeginLoc(), {});
2690+
InitializationSequence CopySeq(SemaRef.SemaRef, CopyEntity, CopyKind,
2691+
Subscript,
2692+
/*TopLevelOfInitList=*/true);
2693+
2694+
ExprResult ElemRes =
2695+
CopySeq.Perform(SemaRef.SemaRef, CopyEntity, CopyKind, Subscript);
2696+
Args.push_back(ElemRes.get());
2697+
}
2698+
2699+
InitExpr = new (getASTContext())
2700+
InitListExpr(getASTContext(), VarExpr->getBeginLoc(), Args,
2701+
VarExpr->getEndLoc());
2702+
InitExpr->setType(VarTy);
2703+
2704+
} else {
2705+
// If this isn't an array, we can just do normal copy init from a simple
2706+
// variable reference, so set that up.
2707+
InitExpr = TemporaryDRE;
2708+
}
2709+
2710+
InitializationKind Kind = InitializationKind::CreateForInit(
2711+
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
2712+
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, InitExpr,
2713+
/*TopLevelOfInitList=*/false,
2714+
/*TreatUnavailableAsInvalid=*/false);
2715+
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
2716+
} else if (CK == OpenACCClauseKind::Reduction) {
2717+
// TODO: OpenACC: Implement this for whatever reduction needs.
2718+
} else {
2719+
llvm_unreachable("Unknown clause kind in CreateInitRecipe");
2720+
}
26322721
}
26332722

26342723
if (Init.get()) {

0 commit comments

Comments
 (0)