Skip to content

Commit 54aa1d2

Browse files
committed
[clang][Interp] Fix initializing atomic record types
Remove the atomic type when visiting InitListExprs.
1 parent aa3c84c commit 54aa1d2

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,13 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
12851285
template <class Emitter>
12861286
bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
12871287
const Expr *ArrayFiller, const Expr *E) {
1288-
if (E->getType()->isVoidType())
1288+
1289+
QualType QT = E->getType();
1290+
1291+
if (const auto *AT = QT->getAs<AtomicType>())
1292+
QT = AT->getValueType();
1293+
1294+
if (QT->isVoidType())
12891295
return this->emitInvalid(E);
12901296

12911297
// Handle discarding first.
@@ -1298,17 +1304,16 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
12981304
}
12991305

13001306
// Primitive values.
1301-
if (std::optional<PrimType> T = classify(E->getType())) {
1307+
if (std::optional<PrimType> T = classify(QT)) {
13021308
assert(!DiscardResult);
13031309
if (Inits.size() == 0)
1304-
return this->visitZeroInitializer(*T, E->getType(), E);
1310+
return this->visitZeroInitializer(*T, QT, E);
13051311
assert(Inits.size() == 1);
13061312
return this->delegate(Inits[0]);
13071313
}
13081314

1309-
QualType T = E->getType();
1310-
if (T->isRecordType()) {
1311-
const Record *R = getRecord(E->getType());
1315+
if (QT->isRecordType()) {
1316+
const Record *R = getRecord(QT);
13121317

13131318
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
13141319
return this->delegate(Inits[0]);
@@ -1405,8 +1410,8 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
14051410
return this->emitFinishInit(E);
14061411
}
14071412

1408-
if (T->isArrayType()) {
1409-
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
1413+
if (QT->isArrayType()) {
1414+
if (Inits.size() == 1 && QT == Inits[0]->getType())
14101415
return this->delegate(Inits[0]);
14111416

14121417
unsigned ElementIndex = 0;
@@ -1438,7 +1443,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
14381443
// FIXME: This should go away.
14391444
if (ArrayFiller) {
14401445
const ConstantArrayType *CAT =
1441-
Ctx.getASTContext().getAsConstantArrayType(E->getType());
1446+
Ctx.getASTContext().getAsConstantArrayType(QT);
14421447
uint64_t NumElems = CAT->getZExtSize();
14431448

14441449
for (; ElementIndex != NumElems; ++ElementIndex) {
@@ -1450,7 +1455,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
14501455
return this->emitFinishInit(E);
14511456
}
14521457

1453-
if (const auto *ComplexTy = E->getType()->getAs<ComplexType>()) {
1458+
if (const auto *ComplexTy = QT->getAs<ComplexType>()) {
14541459
unsigned NumInits = Inits.size();
14551460

14561461
if (NumInits == 1)
@@ -1480,7 +1485,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
14801485
return true;
14811486
}
14821487

1483-
if (const auto *VecT = E->getType()->getAs<VectorType>()) {
1488+
if (const auto *VecT = QT->getAs<VectorType>()) {
14841489
unsigned NumVecElements = VecT->getNumElements();
14851490
assert(NumVecElements >= Inits.size());
14861491

clang/test/CodeGenCXX/atomicinit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fno-inline-functions %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 -std=c++11 | FileCheck %s
2+
// RUN: %clang_cc1 -fno-inline-functions %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s
23

34
// CHECK-DAG: @PR22043 ={{.*}} local_unnamed_addr global i32 0, align 4
45
typedef _Atomic(int) AtomicInt;

0 commit comments

Comments
 (0)