[clang] 79e43eb - [clang][Interp] Protect ArrayDecay ops against dummy pointers

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


Author: Timm Bäder
Date: 2024-02-09T10:12:26+01:00
New Revision: 79e43eb3e20484bdb6f32eecc336742dd721fcc9

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

LOG: [clang][Interp] Protect ArrayDecay ops against dummy pointers

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.h
    clang/test/AST/Interp/arrays.cpp
    clang/test/SemaCXX/self-comparison.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 1299a70c01548c..bcabd93304aa29 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1891,6 +1891,9 @@ 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())
+    return false;
+
   if (!Ptr.isUnknownSizeArray()) {
     S.Stk.push<Pointer>(Ptr.atIndex(0));
     return true;

diff  --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp
index e14ff34dd73716..dedfa0173908f6 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -598,3 +598,23 @@ namespace NonConstReads {
   const int y = 0;
   int yy[y];
 }
+
+namespace SelfComparison {
+  struct S {
+    int field;
+    static int static_field;
+    int array[4];
+  };
+
+  struct T {
+    int field;
+    static int static_field;
+    int array[4];
+    S s;
+  };
+
+  int struct_test(S s1, S s2, S *s3, T t) {
+    return s3->array[t.field] == s3->array[t.field];  // expected-warning {{self-comparison always evaluates to true}} \
+                                                      // ref-warning {{self-comparison always evaluates to true}}
+  };
+}

diff  --git a/clang/test/SemaCXX/self-comparison.cpp b/clang/test/SemaCXX/self-comparison.cpp
index 72127f11024128..c3c875565ff1db 100644
--- a/clang/test/SemaCXX/self-comparison.cpp
+++ b/clang/test/SemaCXX/self-comparison.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a -fexperimental-new-constant-interpreter
 
 int foo(int x) {
   return x == x; // expected-warning {{self-comparison always evaluates to true}}


        


More information about the cfe-commits mailing list