summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-01-31 14:36:23 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-02-01 08:03:49 +0100
commita9e830910bc07733b7a9d4b935cd12a9041623b3 (patch)
tree1654f572d5679eafe10c5f1c19b8d7934ebca17a
parent021a2b4ba254eb9e06fece5c18e5596cbb4896e6 (diff)
[clang][Interp] Protect Inc/Dec ops against dummy pointers
We create them more often in C, so it's more likely to happen there.
-rw-r--r--clang/lib/AST/Interp/Interp.h6
-rw-r--r--clang/test/AST/Interp/c.c10
-rw-r--r--clang/test/Sema/check-increment.c1
3 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b71469b2cba1..7c7e53564c4b 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 2bc3d906bcc5..385944d643a3 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 ptrdiff_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 011ebd85a79c..66321a1c45e2 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 *, ...);