aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-07-03 15:34:16 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-07-03 16:38:09 +0200
commit54aa1d28b6a26b4980df4d5448fb64d19dc1a100 (patch)
tree386ab58a4ce03f424e50c99fc59297455c378e2d /clang
parentaa3c84c85c8c2ef5b8665932e7934458a44504ce (diff)
downloadllvm-54aa1d28b6a26b4980df4d5448fb64d19dc1a100.zip
llvm-54aa1d28b6a26b4980df4d5448fb64d19dc1a100.tar.gz
llvm-54aa1d28b6a26b4980df4d5448fb64d19dc1a100.tar.bz2
[clang][Interp] Fix initializing atomic record types
Remove the atomic type when visiting InitListExprs.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/Interp/Compiler.cpp27
-rw-r--r--clang/test/CodeGenCXX/atomicinit.cpp1
2 files changed, 17 insertions, 11 deletions
diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp
index 9ca71e0..775cabf 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1285,7 +1285,13 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
const Expr *ArrayFiller, const Expr *E) {
- if (E->getType()->isVoidType())
+
+ QualType QT = E->getType();
+
+ if (const auto *AT = QT->getAs<AtomicType>())
+ QT = AT->getValueType();
+
+ if (QT->isVoidType())
return this->emitInvalid(E);
// Handle discarding first.
@@ -1298,17 +1304,16 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
}
// Primitive values.
- if (std::optional<PrimType> T = classify(E->getType())) {
+ if (std::optional<PrimType> T = classify(QT)) {
assert(!DiscardResult);
if (Inits.size() == 0)
- return this->visitZeroInitializer(*T, E->getType(), E);
+ return this->visitZeroInitializer(*T, QT, E);
assert(Inits.size() == 1);
return this->delegate(Inits[0]);
}
- QualType T = E->getType();
- if (T->isRecordType()) {
- const Record *R = getRecord(E->getType());
+ if (QT->isRecordType()) {
+ const Record *R = getRecord(QT);
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
return this->delegate(Inits[0]);
@@ -1405,8 +1410,8 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return this->emitFinishInit(E);
}
- if (T->isArrayType()) {
- if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
+ if (QT->isArrayType()) {
+ if (Inits.size() == 1 && QT == Inits[0]->getType())
return this->delegate(Inits[0]);
unsigned ElementIndex = 0;
@@ -1438,7 +1443,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
// FIXME: This should go away.
if (ArrayFiller) {
const ConstantArrayType *CAT =
- Ctx.getASTContext().getAsConstantArrayType(E->getType());
+ Ctx.getASTContext().getAsConstantArrayType(QT);
uint64_t NumElems = CAT->getZExtSize();
for (; ElementIndex != NumElems; ++ElementIndex) {
@@ -1450,7 +1455,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return this->emitFinishInit(E);
}
- if (const auto *ComplexTy = E->getType()->getAs<ComplexType>()) {
+ if (const auto *ComplexTy = QT->getAs<ComplexType>()) {
unsigned NumInits = Inits.size();
if (NumInits == 1)
@@ -1480,7 +1485,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return true;
}
- if (const auto *VecT = E->getType()->getAs<VectorType>()) {
+ if (const auto *VecT = QT->getAs<VectorType>()) {
unsigned NumVecElements = VecT->getNumElements();
assert(NumVecElements >= Inits.size());
diff --git a/clang/test/CodeGenCXX/atomicinit.cpp b/clang/test/CodeGenCXX/atomicinit.cpp
index a568f17..b507a22 100644
--- a/clang/test/CodeGenCXX/atomicinit.cpp
+++ b/clang/test/CodeGenCXX/atomicinit.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fno-inline-functions %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -fno-inline-functions %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s
// CHECK-DAG: @PR22043 ={{.*}} local_unnamed_addr global i32 0, align 4
typedef _Atomic(int) AtomicInt;