Skip to content

Commit

Permalink
[clang][bytecode] Activate pointers in Init{,Pop} (llvm#112832)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr authored Oct 18, 2024
1 parent ad4a582 commit 5d08625
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/ByteCode/placement-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit 5d08625

Please sign in to comment.