[clang] 82950a6 - [clang][Interp] Protect ArrayElemPtr ops from dummy pointers
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 03:29:43 PST 2024
Author: Timm Bäder
Date: 2024-02-06T12:29:35+01:00
New Revision: 82950a695ddbd92beb07bf58b48067a1f67d57e3
URL: https://github.com/llvm/llvm-project/commit/82950a695ddbd92beb07bf58b48067a1f67d57e3
DIFF: https://github.com/llvm/llvm-project/commit/82950a695ddbd92beb07bf58b48067a1f67d57e3.diff
LOG: [clang][Interp] Protect ArrayElemPtr ops from dummy pointers
Change the semantics of Pointer::isDummy() to check for a null
Pointee and returnd false in that case. Then call CheckDummy()
in ArrayElemPtr{,Pop} to protect those ops from operating on
dummy pointers and enable a few tests in test/Sema/ that now
work with the new constant interpreter.
Added:
Modified:
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Pointer.h
clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c
clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 0766ad88e9224e..683151f7caf528 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -272,7 +272,7 @@ static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
}
bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
- return !Ptr.isZero() && !Ptr.isDummy();
+ return !Ptr.isDummy();
}
bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index e41604e125eba6..6c99fa2f9d14b6 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1855,6 +1855,23 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
const T &Offset = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.peek<Pointer>();
+ if (!CheckDummy(S, OpPC, Ptr))
+ return false;
+
+ if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
+ return false;
+
+ return NarrowPtr(S, OpPC);
+}
+
+template <PrimType Name, class T = typename PrimConv<Name>::T>
+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 (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
return false;
@@ -1877,17 +1894,6 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
return false;
}
-template <PrimType Name, class T = typename PrimConv<Name>::T>
-inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
- const T &Offset = S.Stk.pop<T>();
- const Pointer &Ptr = S.Stk.pop<Pointer>();
-
- if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
- return false;
-
- return NarrowPtr(S, OpPC);
-}
-
inline bool Call(InterpState &S, CodePtr OpPC, const Function *Func) {
if (Func->hasThisPointer()) {
size_t ThisOffset =
diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 53b89c51b5a81a..b3a3a98a043c7e 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -340,7 +340,11 @@ class Pointer {
/// Checks if a structure is a base class.
bool isBaseClass() const { return isField() && getInlineDesc()->IsBase; }
/// Checks if the pointer pointers to a dummy value.
- bool isDummy() const { return getDeclDesc()->isDummy(); }
+ bool isDummy() const {
+ if (!Pointee)
+ return false;
+ return getDeclDesc()->isDummy();
+ }
/// Checks if an object or a subfield is mutable.
bool isConst() const {
diff --git a/clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c b/clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c
index ed47101d644309..c72510beddb13c 100644
--- a/clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c
+++ b/clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c
@@ -1,23 +1,40 @@
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s
-// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
-// RUN: -x c++ -DCPP -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s -fexperimental-new-constant-interpreter
+
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP -DNOERROR %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=source -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=source -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=source \
// RUN: -DNOERROR %s
-
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=source \
+// RUN: -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=double %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=double %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=double %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=double %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=extended %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=extended %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=extended %s
-
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=extended %s -fexperimental-new-constant-interpreter
#ifdef NOERROR
// expected-no-diagnostics
diff --git a/clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c b/clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
index 61bf7c970807cb..f26b43f7cd378a 100644
--- a/clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
+++ b/clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
@@ -1,21 +1,41 @@
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -x c++ -DCPP -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -x c++ -DCPP -DNOERROR %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=double -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=double -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=double -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=double -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=source %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=source %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=extended %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=extended %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=extended %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=extended %s -fexperimental-new-constant-interpreter
#ifdef NOERROR
// expected-no-diagnostics
diff --git a/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c b/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
index 8be5c5535af39d..d58a36dc108ae4 100644
--- a/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
+++ b/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
@@ -1,22 +1,40 @@
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -x c++ -DCPP -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -x c++ -DCPP -DNOERROR %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=extended -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=extended -DNOERROR %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=extended -DNOERROR %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=extended -DNOERROR %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=source %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=source %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
// RUN: -ffp-eval-method=double %s
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only \
+// RUN: -ffp-eval-method=double %s -fexperimental-new-constant-interpreter
+
// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
// RUN: -ffp-eval-method=double %s
-
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=double %s -fexperimental-new-constant-interpreter
#ifdef NOERROR
// expected-no-diagnostics
More information about the cfe-commits
mailing list