[PATCH] D92969: [AST] Fix a constexpr-evaluator crash on error-dependent returnstmt.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 10 01:12:38 PST 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGa0539298540e: [AST] Fix a constexpr-evaluator crash on error-dependent returnstmt. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D92969?vs=310651&id=310791#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92969

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
@@ -66,3 +66,6 @@
 constexpr int test9(int x) {
   return f<1>(f<x>(1)); // expected-error {{no matching function for call to 'f'}}
 }
+
+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}}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5142,8 +5142,11 @@
   case Stmt::ReturnStmtClass: {
     const Expr *RetExpr = cast<ReturnStmt>(S)->getRetValue();
     FullExpressionRAII Scope(Info);
-    if (RetExpr && RetExpr->isValueDependent())
-      return EvaluateDependentExpr(RetExpr, Info) ? ESR_Returned : ESR_Failed;
+    if (RetExpr && RetExpr->isValueDependent()) {
+      EvaluateDependentExpr(RetExpr, Info);
+      // We know we returned, but we don't know what the value is.
+      return ESR_Failed;
+    }
     if (RetExpr &&
         !(Result.Slot
               ? EvaluateInPlace(Result.Value, Info, *Result.Slot, RetExpr)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92969.310791.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201210/34f1b39d/attachment.bin>


More information about the cfe-commits mailing list