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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 21:00:41 PDT 2024


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/112832

None

>From 28b0023196a895a6b02c5990196bcca394fb8d28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 18 Oct 2024 05:57:34 +0200
Subject: [PATCH] [clang][bytecode] Activate pointers in Init{,Pop}

---
 clang/lib/AST/ByteCode/Interp.h           |  2 ++
 clang/test/AST/ByteCode/placement-new.cpp | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index dece95971b7617..ff5bb94a74c83e 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 caf3ac97fd1c04..eb8311c283e30a 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -286,3 +286,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