This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c818b0a4f92: [clang][Interp] Fix a crash when calling 
invalid constexpr functions (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147845/new/

https://reviews.llvm.org/D147845

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -202,3 +202,20 @@
 constexpr int doit() { return nyd(10); }
 constexpr int nyd(int m) { return m; }
 static_assert(doit() == 10, "");
+
+namespace InvalidCall {
+  struct S {
+    constexpr int a() const { // expected-error {{never produces a constant 
expression}} \
+                              // ref-error {{never produces a constant 
expression}}
+      return 1 / 0; // expected-note 2{{division by zero}} \
+                    // expected-warning {{is undefined}} \
+                    // ref-note 2{{division by zero}} \
+                    // ref-warning {{is undefined}}
+    }
+  };
+  constexpr S s;
+  static_assert(s.a() == 1); // expected-error {{not an integral constant 
expression}} \
+                             // expected-note {{in call to}} \
+                             // ref-error {{not an integral constant 
expression}} \
+                             // ref-note {{in call to}}
+}
Index: clang/lib/AST/Interp/InterpFrame.cpp
===================================================================
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -127,7 +127,8 @@
   }
 
   // Drop the first pointer since we print it unconditionally anyway.
-  Levels.erase(Levels.begin());
+  if (!Levels.empty())
+    Levels.erase(Levels.begin());
 
   printDesc(P.getDeclDesc());
   for (const auto &It : Levels) {


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -202,3 +202,20 @@
 constexpr int doit() { return nyd(10); }
 constexpr int nyd(int m) { return m; }
 static_assert(doit() == 10, "");
+
+namespace InvalidCall {
+  struct S {
+    constexpr int a() const { // expected-error {{never produces a constant expression}} \
+                              // ref-error {{never produces a constant expression}}
+      return 1 / 0; // expected-note 2{{division by zero}} \
+                    // expected-warning {{is undefined}} \
+                    // ref-note 2{{division by zero}} \
+                    // ref-warning {{is undefined}}
+    }
+  };
+  constexpr S s;
+  static_assert(s.a() == 1); // expected-error {{not an integral constant expression}} \
+                             // expected-note {{in call to}} \
+                             // ref-error {{not an integral constant expression}} \
+                             // ref-note {{in call to}}
+}
Index: clang/lib/AST/Interp/InterpFrame.cpp
===================================================================
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -127,7 +127,8 @@
   }
 
   // Drop the first pointer since we print it unconditionally anyway.
-  Levels.erase(Levels.begin());
+  if (!Levels.empty())
+    Levels.erase(Levels.begin());
 
   printDesc(P.getDeclDesc());
   for (const auto &It : Levels) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to