[clang] a9e8309 - [clang][Interp] Protect Inc/Dec ops against dummy pointers

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 23:04:02 PST 2024


Author: Timm Bäder
Date: 2024-02-01T08:03:49+01:00
New Revision: a9e830910bc07733b7a9d4b935cd12a9041623b3

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

LOG: [clang][Interp] Protect Inc/Dec ops against dummy pointers

We create them more often in C, so it's more likely to happen there.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.h
    clang/test/AST/Interp/c.c
    clang/test/Sema/check-increment.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b71469b2cba1f..7c7e53564c4b4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -519,6 +519,9 @@ enum class IncDecOp {
 
 template <typename T, IncDecOp Op, PushVal DoPush>
 bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+  if (Ptr.isDummy())
+    return false;
+
   const T &Value = Ptr.deref<T>();
   T Result;
 
@@ -1521,6 +1524,9 @@ bool SubOffset(InterpState &S, CodePtr OpPC) {
 template <ArithOp Op>
 static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC,
                                    const Pointer &Ptr) {
+  if (Ptr.isDummy())
+    return false;
+
   using OneT = Integral<8, false>;
 
   const Pointer &P = Ptr.deref<Pointer>();

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 2bc3d906bcc5e..385944d643a30 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -85,3 +85,13 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error {{not a compile-time
 const ptr
diff _t m = &m + 137 - &m;
 _Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
                               // pedantic-expected-warning {{GNU extension}}
+
+/// from test/Sema/switch.c, used to cause an assertion failure.
+void f (int z) {
+  while (z) {
+    default: z--; // expected-error {{'default' statement not in switch}} \
+                  // pedantic-expected-error {{'default' statement not in switch}} \
+                  // ref-error {{'default' statement not in switch}} \
+                  // pedantic-ref-error {{'default' statement not in switch}}
+  }
+}

diff  --git a/clang/test/Sema/check-increment.c b/clang/test/Sema/check-increment.c
index 011ebd85a79cd..66321a1c45e29 100644
--- a/clang/test/Sema/check-increment.c
+++ b/clang/test/Sema/check-increment.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
 // expected-no-diagnostics
 
 int printf(const char *, ...);


        


More information about the cfe-commits mailing list