[clang] cb6c0f1 - [clang][Interp] Ignore ArrayDecay ops for null pointers
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 28 07:16:18 PST 2024
Author: Timm Bäder
Date: 2024-02-28T16:16:03+01:00
New Revision: cb6c0f1d28c0d1915d1ca9a198254e3828af2384
URL: https://github.com/llvm/llvm-project/commit/cb6c0f1d28c0d1915d1ca9a198254e3828af2384
DIFF: https://github.com/llvm/llvm-project/commit/cb6c0f1d28c0d1915d1ca9a198254e3828af2384.diff
LOG: [clang][Interp] Ignore ArrayDecay ops for null pointers
Just don't do anything and let later operations handle the diagnostics.
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/cxx11.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index db52f6649c18ba..241d5941e143ee 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1933,7 +1933,7 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) {
inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
const Pointer &Ptr = S.Stk.pop<Pointer>();
- if (Ptr.isDummy()) {
+ if (Ptr.isZero() || Ptr.isDummy()) {
S.Stk.push<Pointer>(Ptr);
return true;
}
diff --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
index 29098ea694c688..993e3618a37848 100644
--- a/clang/test/AST/Interp/cxx11.cpp
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -28,3 +28,5 @@ struct S {
};
constexpr S s = { 5 };
constexpr const int *p = &s.m + 1;
+
+constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok
More information about the cfe-commits
mailing list