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)
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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits