[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
This revision was automatically updated to reflect the committed changes. yronglin marked 2 inline comments as done. Closed by commit rGa2132d72bed1: [Clang] Fix the do while statement disappearing in AST when an error occurs in… (authored by yronglin). 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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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
[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
yronglin marked 2 inline comments as done. yronglin added a comment. Thanks for your review! @hokein @tbaeder Comment at: clang/lib/Parse/ParseStmt.cpp:1897-1898 if (Cond.isUsable()) -Cond = Actions.CorrectDelayedTyposInExpr(Cond); +Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr, + /*RecoveryUncorrectedTypos*/ true); else { tbaeder wrote: > Thanks, done! Comment at: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp:81 +constexpr int test13() { do {} while (a < 10); return 0; } // expected-error {{use of undeclared identifier}} +static_assert(test13()); // expected-error {{static assertion expression is not an integral constant expression}} hokein wrote: > nit: it is better to use the below `TEST_EVALUATE` macro for the test, > `TEST_EVALUATE(DoWhile2, do {} while (undefined < 10); )` Thanks, done! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157195/new/ https://reviews.llvm.org/D157195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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
[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
tbaeder added inline comments. Comment at: clang/lib/Parse/ParseStmt.cpp:1897-1898 if (Cond.isUsable()) -Cond = Actions.CorrectDelayedTyposInExpr(Cond); +Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr, + /*RecoveryUncorrectedTypos*/ true); else { Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157195/new/ https://reviews.llvm.org/D157195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
hokein accepted this revision. hokein added a comment. This revision is now accepted and ready to land. thanks, looks good. Comment at: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp:81 +constexpr int test13() { do {} while (a < 10); return 0; } // expected-error {{use of undeclared identifier}} +static_assert(test13()); // expected-error {{static assertion expression is not an integral constant expression}} nit: it is better to use the below `TEST_EVALUATE` macro for the test, `TEST_EVALUATE(DoWhile2, do {} while (undefined < 10); )` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157195/new/ https://reviews.llvm.org/D157195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
yronglin created this revision. Herald added a project: All. yronglin requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Signed-off-by: yrong Repository: rG LLVM Github Monorepo 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 @@ -78,6 +78,9 @@ constexpr int test12() { return "wrong"; } // expected-error {{cannot initialize return object of type 'int'}} constexpr int force12 = test12(); // expected-error {{must be initialized by a constant}} +constexpr int test13() { do {} while (a < 10); return 0; } // expected-error {{use of undeclared identifier}} +static_assert(test13()); // expected-error {{static assertion expression is not an integral constant expression}} + #define TEST_EVALUATE(Name, X) \ constexpr int testEvaluate##Name() { \ X return 0;\ 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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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, + /*RecoveryUncorrectedTypos*/ 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 @@ -78,6 +78,9 @@ constexpr int test12() { return "wrong"; } // expected-error {{cannot initialize return object of type 'int'}} constexpr int force12 = test12(); // expected-error {{must be initialized by a constant}} +constexpr int test13() { do {} while (a < 10); return 0; } // expected-error {{use of undeclared identifier}} +static_assert(test13()); // expected-error {{static assertion expression is not an integral constant expression}} + #define TEST_EVALUATE(Name, X) \ constexpr int testEvaluate##Name() { \ X return 0;\ 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 {{.*}} '' contains-errors lvalue // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *' } + +void RecoveryToDoWhileStmtCond() { + // CHECK: FunctionDecl {{.*}} RecoveryToDoWhileStmtCond + // CHECK: `-DoStmt {{.*}} + // CHECK-NEXT:|-CompoundStmt {{.*}} + // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<' + // CHECK-NEXT: |-BinaryOperator {{.*}} '' contains-errors '+' + // CHECK-NEXT: | |-RecoveryExpr {{.*}} '' 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, +