From b57c757a80532a610d949c2eeb9d9e05c76f543f Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 31 Mar 2010 00:37:59 +0000 Subject: [PATCH] Don't skip past the '}' if an expression has error and is not followed by ';'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99972 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseStmt.cpp | 8 +++++--- test/Index/recover-bad-code-rdar_7487294.c | 1 - test/Parser/statements.c | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 9fd145dc26..b752b48cfd 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -125,10 +125,12 @@ Parser::ParseStatementOrDeclaration(bool OnlyStatement) { // expression[opt] ';' OwningExprResult Expr(ParseExpression()); if (Expr.isInvalid()) { - // If the expression is invalid, skip ahead to the next semicolon. Not - // doing this opens us up to the possibility of infinite loops if + // If the expression is invalid, skip ahead to the next semicolon or '}'. + // Not doing this opens us up to the possibility of infinite loops if // ParseExpression does not consume any tokens. - SkipUntil(tok::semi); + SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true); + if (Tok.is(tok::semi)) + ConsumeToken(); return StmtError(); } // Otherwise, eat the semicolon. diff --git a/test/Index/recover-bad-code-rdar_7487294.c b/test/Index/recover-bad-code-rdar_7487294.c index 97bb5158e4..e060672b69 100644 --- a/test/Index/recover-bad-code-rdar_7487294.c +++ b/test/Index/recover-bad-code-rdar_7487294.c @@ -11,4 +11,3 @@ int foo(int x) { // CHECK: 9:3: error: use of undeclared identifier 'help' // CHECK: help -// CHECK: 14:102: error: expected '}' diff --git a/test/Parser/statements.c b/test/Parser/statements.c index a662c9b821..bc7192a7b2 100644 --- a/test/Parser/statements.c +++ b/test/Parser/statements.c @@ -57,3 +57,8 @@ void test6(void) { int test7() { return 4 // expected-error {{expected ';' after return statement}} } + +void test8() { + // Should not skip '}' and produce a "expected '}'" error. + undecl // expected-error {{use of undeclared identifier 'undecl'}} +} -- 2.50.1