[clang] fd98f80 - [clang][Interp] Finish initializing structs from CompoundLiteralExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 18 01:32:05 PDT 2024


Author: Timm Bäder
Date: 2024-04-18T10:31:31+02:00
New Revision: fd98f80f602e11d523d252feef301634c2c689a7

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

LOG: [clang][Interp] Finish initializing structs from CompoundLiteralExprs

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/c.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 47cd32c2ab8673..f317f506d24f4b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1843,7 +1843,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
   const Expr *Init = E->getInitializer();
   if (Initializing) {
     // We already have a value, just initialize that.
-    return this->visitInitializer(Init);
+    return this->visitInitializer(Init) && this->emitFinishInit(E);
   }
 
   std::optional<PrimType> T = classify(E->getType());
@@ -1862,7 +1862,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
         return this->emitInitGlobal(*T, *GlobalIndex, E);
       }
 
-      return this->visitInitializer(Init);
+      return this->visitInitializer(Init) && this->emitFinishInit(E);
     }
 
     return false;
@@ -1891,7 +1891,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
       }
       return this->emitInit(*T, E);
     } else {
-      if (!this->visitInitializer(Init))
+      if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
         return false;
     }
 

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 38df38d1ccfae6..5ae9b1dc7bff86 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -245,3 +245,15 @@ void unaryops(void) {
   (void)((struct zz {float x;}){3}.x++);
   (void)((struct ww {float x;}){3}.x--);
 }
+
+/// This used to fail because we didn't properly mark the struct
+/// initialized through a CompoundLiteralExpr as initialized.
+struct TestStruct {
+  int a;
+  int b;
+};
+int Y __attribute__((annotate(
+  "GlobalValAnnotationWithArgs",
+  42,
+  (struct TestStruct) { .a = 1, .b = 2 }
+)));


        


More information about the cfe-commits mailing list