Skip to content

Commit 7512dfe

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2309)
2 parents ddec74c + 0b828c9 commit 7512dfe

39 files changed

+376
-189
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ C23 Feature Support
273273
be completed).
274274
- Fixed a failed assertion with an invalid parameter to the ``#embed``
275275
directive. Fixes #GH126940.
276+
- Fixed a crash when a declaration of a ``constexpr`` variable with an invalid
277+
type. Fixes #GH140887
276278

277279
C11 Feature Support
278280
^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
670670
if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
671671
VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
672672

673-
if (!S.getLangOpts().CPlusPlus23 && VD == S.EvaluatingDecl) {
673+
if (VD == S.EvaluatingDecl &&
674+
!(S.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) {
674675
if (!S.getLangOpts().CPlusPlus14 &&
675676
!VD->getType().isConstant(S.getASTContext())) {
676677
// Diagnose as non-const read.

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
19441944

19451945
const VarDecl &D = *emission.Variable;
19461946
auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, D.getLocation());
1947+
ApplyAtomGroup Grp(getDebugInfo());
19471948
QualType type = D.getType();
19481949

19491950
// If this local has an initializer, emit it now.

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
22222222
}
22232223

22242224
llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
2225+
addInstToCurrentSourceAtom(Store, Value);
2226+
22252227
if (isNontemporal) {
22262228
llvm::MDNode *Node =
22272229
llvm::MDNode::get(Store->getContext(),

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8681,7 +8681,8 @@ static bool CheckC23ConstexprVarType(Sema &SemaRef, SourceLocation VarLoc,
86818681

86828682
if (CanonT->isRecordType()) {
86838683
const RecordDecl *RD = CanonT->getAsRecordDecl();
8684-
if (llvm::any_of(RD->fields(), [&SemaRef, VarLoc](const FieldDecl *F) {
8684+
if (!RD->isInvalidDecl() &&
8685+
llvm::any_of(RD->fields(), [&SemaRef, VarLoc](const FieldDecl *F) {
86858686
return CheckC23ConstexprVarType(SemaRef, VarLoc, F->getType());
86868687
}))
86878688
return true;

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6618,7 +6618,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
66186618
// initializer present. However, we only do this for structure types, not
66196619
// union types, because an unitialized field in a union is generally
66206620
// reasonable, especially in C where unions can be used for type punning.
6621-
if (!Initializer && !Rec->isUnion()) {
6621+
if (!Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) {
66226622
if (const FieldDecl *FD = getConstField(Rec)) {
66236623
unsigned DiagID = diag::warn_default_init_const_field_unsafe;
66246624
if (Var->getStorageDuration() == SD_Static ||

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ constexpr int k(int n) {
7373
}
7474
constexpr int k0 = k(0);
7575

76+
#if __cplusplus >= 202302L
77+
constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \
78+
// all-note {{initializer of 'b' is not a constant expression}} \
79+
// all-note {{declared here}}
80+
#endif
81+
7682
namespace StaticLambdas {
7783
constexpr auto static_capture_constexpr() {
7884
char n = 'n';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
void a() {
8+
// CHECK: store i32 0, ptr %A{{.*}}, !dbg [[G1R1:!.*]]
9+
int A = 0;
10+
// CHECK: %add = add {{.*}}, !dbg [[G2R2:!.*]]
11+
// CHECK: store i32 %add, ptr %B, align 4, !dbg [[G2R1:!.*]]
12+
int B = 2 * A + 1;
13+
}
14+
15+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
16+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
17+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
2+
3+
// This was previously causing a stack overflow when checking the valid
4+
// declaration of an invalid type. Ensure we issue reasonable diagnostics
5+
// instead of crashing.
6+
struct GH140887 { // expected-note {{definition of 'struct GH140887' is not complete until the closing '}'}}
7+
GH140887(); // expected-error {{must use 'struct' tag to refer to type 'GH140887'}} \
8+
expected-error {{expected member name or ';' after declaration specifiers}} \
9+
expected-error {{field has incomplete type 'struct GH140887'}}
10+
};
11+
constexpr struct GH140887 a; // expected-error {{constexpr variable 'a' must be initialized by a constant expression}}
12+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
// This invalid code was causing a stack overflow, check that we issue
4+
// reasonable diagnostics and not crash.
5+
struct GH140887 { // expected-note {{definition of 'struct GH140887' is not complete until the closing '}'}}
6+
struct GH140887 s; // expected-error {{field has incomplete type 'struct GH140887'}}
7+
};
8+
9+
void gh140887() {
10+
struct GH140887 s;
11+
}

0 commit comments

Comments
 (0)