diff options
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 19 | ||||
-rw-r--r-- | test/Parser/statements.c | 7 |
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index f5cdfffba5..30c62e3a3c 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -170,9 +170,10 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) { // If we reached this code, the statement must end in a semicolon. if (Tok.is(tok::semi)) { ConsumeToken(); - } else { + } else if (!Res.isInvalid) { Diag(Tok, diag::err_expected_semi_after, SemiError); - SkipUntil(tok::semi); + // Skip until we see a } or ;, but don't eat it. + SkipUntil(tok::r_brace, true, true); } return Res; } @@ -717,8 +718,8 @@ Parser::StmtResult Parser::ParseDoStatement() { // The substatement in an iteration-statement implicitly defines a local scope // which is entered and exited each time through the loop. // - bool NeedsInnerScope = (getLang().C99 || getLang().CPlusPlus) && - Tok.isNot(tok::l_brace); + bool NeedsInnerScope = + (getLang().C99 || getLang().CPlusPlus) && Tok.isNot(tok::l_brace); if (NeedsInnerScope) EnterScope(Scope::DeclScope); // Read the body statement. @@ -729,9 +730,11 @@ Parser::StmtResult Parser::ParseDoStatement() { if (Tok.isNot(tok::kw_while)) { ExitScope(); - Diag(Tok, diag::err_expected_while); - Diag(DoLoc, diag::err_matching, "do"); - SkipUntil(tok::semi); + if (!Body.isInvalid) { + Diag(Tok, diag::err_expected_while); + Diag(DoLoc, diag::err_matching, "do"); + SkipUntil(tok::semi, false, true); + } return true; } SourceLocation WhileLoc = ConsumeToken(); @@ -739,7 +742,7 @@ Parser::StmtResult Parser::ParseDoStatement() { if (Tok.isNot(tok::l_paren)) { ExitScope(); Diag(Tok, diag::err_expected_lparen_after, "do/while"); - SkipUntil(tok::semi); + SkipUntil(tok::semi, false, true); return true; } diff --git a/test/Parser/statements.c b/test/Parser/statements.c index db2ec628ee..26b26624da 100644 --- a/test/Parser/statements.c +++ b/test/Parser/statements.c @@ -47,3 +47,10 @@ void test5() { if (0); // expected-warning {{if statement has empty body}} } + +void test6(void) { + do + . // expected-error {{expected expression}} + while (0); +} + |