This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement
ClosedPublic

Authored by yronglin on Aug 5 2023, 9:48 AM.

Details

Summary
constexpr int test() {
    do {} while (a + 1 < 10);
    return 0;
}

Before:

`-FunctionDecl 0x56512a172650 <./recovery.cpp:1:1, line:4:1> line:1:15 constexpr test 'int ()' implicit-inline
  `-CompoundStmt 0x56512a172860 <col:22, line:4:1>
    `-ReturnStmt 0x56512a172850 <line:3:5, col:12>
      `-IntegerLiteral 0x56512a172830 <col:12> 'int' 0

Now:

`-FunctionDecl 0x5642c4804650 <./recovery.cpp:1:1, line:4:1> line:1:15 constexpr test 'int ()' implicit-inline
  `-CompoundStmt 0x5642c48048e0 <col:22, line:4:1>
    |-DoStmt 0x5642c4804890 <line:2:5, col:28>
    | |-CompoundStmt 0x5642c4804740 <col:8, col:9>
    | `-BinaryOperator 0x5642c4804870 <col:18, col:26> '<dependent type>' contains-errors '<'
    |   |-BinaryOperator 0x5642c4804850 <col:18, col:22> '<dependent type>' contains-errors '+'
    |   | |-RecoveryExpr 0x5642c4804830 <col:18> '<dependent type>' contains-errors lvalue
    |   | `-IntegerLiteral 0x5642c48047b0 <col:22> 'int' 1
    |   `-IntegerLiteral 0x5642c48047f0 <col:26> 'int' 10
    `-ReturnStmt 0x5642c48048d0 <line:3:5, col:12>
      `-IntegerLiteral 0x5642c48048b0 <col:12> 'int' 0

Diff Detail

Event Timeline

yronglin created this revision.Aug 5 2023, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2023, 9:48 AM
yronglin requested review of this revision.Aug 5 2023, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2023, 9:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
yronglin edited the summary of this revision. (Show Details)Aug 5 2023, 9:50 AM
yronglin added reviewers: hokein, aaron.ballman.
yronglin edited the summary of this revision. (Show Details)
hokein accepted this revision.Aug 7 2023, 12:13 AM

thanks, looks good.

clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
81

nit: it is better to use the below TEST_EVALUATE macro for the test, TEST_EVALUATE(DoWhile2, do {} while (undefined < 10); )

This revision is now accepted and ready to land.Aug 7 2023, 12:13 AM
tbaeder added inline comments.
clang/lib/Parse/ParseStmt.cpp
1897–1899
yronglin updated this revision to Diff 547712.Aug 7 2023, 4:16 AM

Address comments.

yronglin marked 2 inline comments as done.Aug 7 2023, 4:18 AM

Thanks for your review! @hokein @tbaeder

clang/lib/Parse/ParseStmt.cpp
1897–1899

Thanks, done!

clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
81

Thanks, done!