[clang] 86b6300 - [clang][Interp] Allow getFieldPtr ops on null pointers in C
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 6 03:35:15 PST 2024
Author: Timm Bäder
Date: 2024-03-06T12:34:50+01:00
New Revision: 86b630092f9a5139c4c4d627f1e0504e8f549bce
URL: https://github.com/llvm/llvm-project/commit/86b630092f9a5139c4c4d627f1e0504e8f549bce
DIFF: https://github.com/llvm/llvm-project/commit/86b630092f9a5139c4c4d627f1e0504e8f549bce.diff
LOG: [clang][Interp] Allow getFieldPtr ops on null pointers in C
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/c.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index baa1b8e9071ab9..9c3d58d5619c46 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1224,7 +1224,8 @@ inline bool GetPtrGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
inline bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) {
const Pointer &Ptr = S.Stk.pop<Pointer>();
- if (S.inConstantContext() && !CheckNull(S, OpPC, Ptr, CSK_Field))
+ if (S.getLangOpts().CPlusPlus && S.inConstantContext() &&
+ !CheckNull(S, OpPC, Ptr, CSK_Field))
return false;
if (CheckDummy(S, OpPC, Ptr)) {
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index a5270172cfc7b4..8de6139efbea09 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -79,6 +79,11 @@ int a2[(intptr_t)&((struct y*)0)->y]; // all-warning {{folded to constant array}
const struct y *yy = (struct y*)0;
const intptr_t L = (intptr_t)(&(yy->y)); // all-error {{not a compile-time constant}}
+_Static_assert((long)&((struct y*)0)->y > 0, ""); // pedantic-ref-warning {{GNU extension}} \
+ // pedantic-ref-note {{this conversion is not allowed in a constant expression}} \
+ // pedantic-expected-warning {{GNU extension}} \
+ // pedantic-expected-note {{this conversion is not allowed in a constant expression}}
+
const ptr
diff _t m = &m + 137 - &m;
_Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
// pedantic-expected-warning {{GNU extension}}
More information about the cfe-commits
mailing list