hokein created this revision. hokein added reviewers: sammccall, rsmith. hokein requested review of this revision. Herald added a project: clang.
When the evaluator encounters an error-dependent returnstmt, before this patch it returned a ESR_Returned without setting the result, the callsides think this is a successful execution, and try to access the Result which causes the crash. The fix is to always return failed as we don't know the result of the error-dependent return stmt. Repository: rG LLVM Github Monorepo 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,10 @@ 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); + 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,10 @@ 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); + 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