Skip to content

Commit 4931c3a

Browse files
authored
[clang][bytecode] Reject null pointers in CheckStore() (#156645)
In the attached test case, the global variable later only points to gargbage, because the MaterializeTemporaryExpr used to initialize it is a local variable, which is gone by the time we try to evaluate the store. Fixes #156223
1 parent faca9dd commit 4931c3a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
870870
}
871871

872872
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
873-
if (!Ptr.isBlockPointer())
873+
if (!Ptr.isBlockPointer() || Ptr.isZero())
874874
return false;
875875

876876
if (!Ptr.block()->isAccessible()) {

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ constexpr int k(int n) {
8383
}
8484
constexpr int k0 = k(0);
8585

86+
namespace ThreadLocalStore {
87+
thread_local int &&a = 0;
88+
void store() { a = 42; }
89+
}
90+
8691
#if __cplusplus >= 202302L
8792
constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \
8893
// all-note {{initializer of 'b' is not a constant expression}} \

0 commit comments

Comments
 (0)