[clang] 4931c3a - [clang][bytecode] Reject null pointers in CheckStore() (#156645)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 4 06:19:29 PDT 2025
Author: Timm Baeder
Date: 2025-09-04T15:19:26+02:00
New Revision: 4931c3afc347f3ea099ebbe3d056dfc63e9eba45
URL: https://github.com/llvm/llvm-project/commit/4931c3afc347f3ea099ebbe3d056dfc63e9eba45
DIFF: https://github.com/llvm/llvm-project/commit/4931c3afc347f3ea099ebbe3d056dfc63e9eba45.diff
LOG: [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
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/cxx23.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 06b2bdc98b428..f1b9104c04feb 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -870,7 +870,7 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
}
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
- if (!Ptr.isBlockPointer())
+ if (!Ptr.isBlockPointer() || Ptr.isZero())
return false;
if (!Ptr.block()->isAccessible()) {
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index 2182d7c4e4325..72c751d627a44 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -83,6 +83,11 @@ constexpr int k(int n) {
}
constexpr int k0 = k(0);
+namespace ThreadLocalStore {
+ thread_local int &&a = 0;
+ void store() { a = 42; }
+}
+
#if __cplusplus >= 202302L
constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \
// all-note {{initializer of 'b' is not a constant expression}} \
More information about the cfe-commits
mailing list