[PATCH] D112633: [AST] fail rather than crash when const evaluating invalid c++ foreach

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 27 13:45:50 PDT 2021


This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGde7494a33a5c: [AST] fail rather than crash when const evaluating invalid c++ foreach (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D112633?vs=382705&id=382776#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112633

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===================================================================
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -69,3 +69,8 @@
 
 constexpr int test10() { return undef(); } // expected-error {{use of undeclared identifier 'undef'}}
 static_assert(test10() <= 1, "should not crash"); // expected-error {{static_assert expression is not an integral constant expression}}
+
+struct X {} array[] = {undef()}; // expected-error {{use of undeclared identifier 'undef'}}
+constexpr void test11() {
+  for (X& e : array) {}
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5319,6 +5319,11 @@
       return ESR;
     }
 
+    // In error-recovery cases it's possible to get here even if we failed to
+    // synthesize the __begin and __end variables.
+    if (!FS->getBeginStmt() || !FS->getEndStmt() || !FS->getCond())
+      return ESR_Failed;
+
     // Create the __begin and __end iterators.
     ESR = EvaluateStmt(Result, Info, FS->getBeginStmt());
     if (ESR != ESR_Succeeded) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112633.382776.patch
Type: text/x-patch
Size: 1259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211027/ea0f7cf2/attachment.bin>


More information about the cfe-commits mailing list