[clang] 5d08625 - [clang][bytecode] Activate pointers in Init{, Pop} (#112832)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 22:38:25 PDT 2024


Author: Timm Baeder
Date: 2024-10-18T07:38:22+02:00
New Revision: 5d08625347a5467d463ff4377816709e262edb59

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

LOG: [clang][bytecode] Activate pointers in Init{,Pop} (#112832)

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.h
    clang/test/AST/ByteCode/placement-new.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index a1a92562cc5e3d..f034bde309035f 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1841,6 +1841,7 @@ bool Init(InterpState &S, CodePtr OpPC) {
     assert(false);
     return false;
   }
+  Ptr.activate();
   Ptr.initialize();
   new (&Ptr.deref<T>()) T(Value);
   return true;
@@ -1852,6 +1853,7 @@ bool InitPop(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop<Pointer>();
   if (!CheckInit(S, OpPC, Ptr))
     return false;
+  Ptr.activate();
   Ptr.initialize();
   new (&Ptr.deref<T>()) T(Value);
   return true;

diff  --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp
index 6bd83f2372eab6..8e6d802e93295c 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -300,3 +300,14 @@ namespace UsedToCrash {
   }
   int alloc1 = (alloc(), 0);
 }
+
+constexpr bool change_union_member() {
+  union U {
+    int a;
+    int b;
+  };
+  U u = {.a = 1};
+  std::construct_at<int>(&u.b, 2);
+  return u.b == 2;
+}
+static_assert(change_union_member());


        


More information about the cfe-commits mailing list