yronglin updated this revision to Diff 547712. yronglin added a comment. Address comments.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157195/new/ https://reviews.llvm.org/D157195 Files: clang/lib/Parse/ParseStmt.cpp clang/test/AST/ast-dump-recovery.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 @@ -95,6 +95,8 @@ TEST_EVALUATE(ForRange, for (auto x : !!){}); // expected-error + {{}} TEST_EVALUATE(While, while (!!){}); // expected-error + {{}} TEST_EVALUATE(DoWhile, do {} while (!!);); // expected-error + {{}} +TEST_EVALUATE(DoWhileCond, do {} while (some_cond < 10);); // expected-error {{use of undeclared identifier}} \ + // expected-error {{constexpr variable 'forceEvaluateDoWhileCond' must be initialized by a constant expression}} TEST_EVALUATE(If, if (!!){};); // expected-error + {{}} TEST_EVALUATE(IfInit, if (auto x = !!; 1){};);// expected-error + {{}} TEST_EVALUATE(ForInit, if (!!;;){};); // expected-error + {{}} Index: clang/test/AST/ast-dump-recovery.cpp =================================================================== --- clang/test/AST/ast-dump-recovery.cpp +++ clang/test/AST/ast-dump-recovery.cpp @@ -420,3 +420,15 @@ // CHECK: RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT: |-CompoundStmt {{.*}} + // CHECK-NEXT: `-BinaryOperator {{.*}} '<dependent type>' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '<dependent type>' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue + // CHECK-NEXT: | `-IntegerLiteral {{.*}} 'int' 1 + // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 10 + do {} while (some_invalid_val + 1 < 10); +} Index: clang/lib/Parse/ParseStmt.cpp =================================================================== --- clang/lib/Parse/ParseStmt.cpp +++ clang/lib/Parse/ParseStmt.cpp @@ -1894,7 +1894,8 @@ ExprResult Cond = ParseExpression(); // Correct the typos in condition before closing the scope. if (Cond.isUsable()) - Cond = Actions.CorrectDelayedTyposInExpr(Cond); + Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl=*/nullptr, + /*RecoverUncorrectedTypos=*/true); else { if (!Tok.isOneOf(tok::r_paren, tok::r_square, tok::r_brace)) SkipUntil(tok::semi);
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 @@ -95,6 +95,8 @@ TEST_EVALUATE(ForRange, for (auto x : !!){}); // expected-error + {{}} TEST_EVALUATE(While, while (!!){}); // expected-error + {{}} TEST_EVALUATE(DoWhile, do {} while (!!);); // expected-error + {{}} +TEST_EVALUATE(DoWhileCond, do {} while (some_cond < 10);); // expected-error {{use of undeclared identifier}} \ + // expected-error {{constexpr variable 'forceEvaluateDoWhileCond' must be initialized by a constant expression}} TEST_EVALUATE(If, if (!!){};); // expected-error + {{}} TEST_EVALUATE(IfInit, if (auto x = !!; 1){};);// expected-error + {{}} TEST_EVALUATE(ForInit, if (!!;;){};); // expected-error + {{}} Index: clang/test/AST/ast-dump-recovery.cpp =================================================================== --- clang/test/AST/ast-dump-recovery.cpp +++ clang/test/AST/ast-dump-recovery.cpp @@ -420,3 +420,15 @@ // CHECK: RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT: |-CompoundStmt {{.*}} + // CHECK-NEXT: `-BinaryOperator {{.*}} '<dependent type>' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '<dependent type>' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue + // CHECK-NEXT: | `-IntegerLiteral {{.*}} 'int' 1 + // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 10 + do {} while (some_invalid_val + 1 < 10); +} Index: clang/lib/Parse/ParseStmt.cpp =================================================================== --- clang/lib/Parse/ParseStmt.cpp +++ clang/lib/Parse/ParseStmt.cpp @@ -1894,7 +1894,8 @@ ExprResult Cond = ParseExpression(); // Correct the typos in condition before closing the scope. if (Cond.isUsable()) - Cond = Actions.CorrectDelayedTyposInExpr(Cond); + Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl=*/nullptr, + /*RecoverUncorrectedTypos=*/true); else { if (!Tok.isOneOf(tok::r_paren, tok::r_square, tok::r_brace)) SkipUntil(tok::semi);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits