Skip to content

Commit 5d08625

Browse files
authored
[clang][bytecode] Activate pointers in Init{,Pop} (#112832)
1 parent ad4a582 commit 5d08625

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,7 @@ bool Init(InterpState &S, CodePtr OpPC) {
18411841
assert(false);
18421842
return false;
18431843
}
1844+
Ptr.activate();
18441845
Ptr.initialize();
18451846
new (&Ptr.deref<T>()) T(Value);
18461847
return true;
@@ -1852,6 +1853,7 @@ bool InitPop(InterpState &S, CodePtr OpPC) {
18521853
const Pointer &Ptr = S.Stk.pop<Pointer>();
18531854
if (!CheckInit(S, OpPC, Ptr))
18541855
return false;
1856+
Ptr.activate();
18551857
Ptr.initialize();
18561858
new (&Ptr.deref<T>()) T(Value);
18571859
return true;

clang/test/AST/ByteCode/placement-new.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,14 @@ namespace UsedToCrash {
300300
}
301301
int alloc1 = (alloc(), 0);
302302
}
303+
304+
constexpr bool change_union_member() {
305+
union U {
306+
int a;
307+
int b;
308+
};
309+
U u = {.a = 1};
310+
std::construct_at<int>(&u.b, 2);
311+
return u.b == 2;
312+
}
313+
static_assert(change_union_member());

0 commit comments

Comments
 (0)