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