[clang] 54aa1d2 - [clang][Interp] Fix initializing atomic record types

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 07:38:30 PDT 2024


Author: Timm Bäder
Date: 2024-07-03T16:38:09+02:00
New Revision: 54aa1d28b6a26b4980df4d5448fb64d19dc1a100

URL: https://github.com/llvm/llvm-project/commit/54aa1d28b6a26b4980df4d5448fb64d19dc1a100
DIFF: https://github.com/llvm/llvm-project/commit/54aa1d28b6a26b4980df4d5448fb64d19dc1a100.diff

LOG: [clang][Interp] Fix initializing atomic record types

Remove the atomic type when visiting InitListExprs.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Compiler.cpp
    clang/test/CodeGenCXX/atomicinit.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp
index 9ca71e0496989..775cabf7f8c59 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 a568f17b90d0c..b507a22e84bc1 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;


        


More information about the cfe-commits mailing list