[clang] d054832 - [clang][Interp] Handle dummy pointers in ArrayElemPtr{,Pop} differently

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 9 07:24:23 PST 2024


Author: Timm Bäder
Date: 2024-02-09T16:24:11+01:00
New Revision: d05483288465a87e75cfab51792801cfee43914c

URL: https://github.com/llvm/llvm-project/commit/d05483288465a87e75cfab51792801cfee43914c
DIFF: https://github.com/llvm/llvm-project/commit/d05483288465a87e75cfab51792801cfee43914c.diff

LOG: [clang][Interp] Handle dummy pointers in ArrayElemPtr{,Pop} differently

Instead of returning false, just ignore the operation and return true;
This gives us the desired diagnostic behavior in the added test case.

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 bcabd93304aa29..290edc07fdc87a 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1856,7 +1856,7 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.peek<Pointer>();
 
   if (!CheckDummy(S, OpPC, Ptr))
-    return false;
+    return true;
 
   if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
     return false;
@@ -1869,8 +1869,10 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
   const T &Offset = S.Stk.pop<T>();
   const Pointer &Ptr = S.Stk.pop<Pointer>();
 
-  if (!CheckDummy(S, OpPC, Ptr))
-    return false;
+  if (!CheckDummy(S, OpPC, Ptr)) {
+    S.Stk.push<Pointer>(Ptr);
+    return true;
+  }
 
   if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
     return false;

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..3605462f78bbbe 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -129,3 +129,8 @@ _Static_assert(sizeof(name2) == 0, ""); // expected-error {{failed}} \
                                         // expected-note {{evaluates to}} \
                                         // pedantic-expected-error {{failed}} \
                                         // pedantic-expected-note {{evaluates to}}
+
+void *PR28739d = &(&PR28739d)[(__int128)(unsigned long)-1]; // expected-warning {{refers past the last possible element}} \
+                                                            // pedantic-expected-warning {{refers past the last possible element}} \
+                                                            // ref-warning {{refers past the last possible element}} \
+                                                            // pedantic-ref-warning {{refers past the last possible element}}


        


More information about the cfe-commits mailing list