summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-03-31 00:37:59 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-03-31 00:37:59 +0000
commit90ab3b7779b16e95181ab55aa887290abef7a7c3 (patch)
treec2cd76d247d96a473842805bd30ecbd5d41c5092 /clang
parentd7f18dd750d312d51458f9e1677232bab5340817 (diff)
downloadbcm5719-llvm-90ab3b7779b16e95181ab55aa887290abef7a7c3.tar.gz
bcm5719-llvm-90ab3b7779b16e95181ab55aa887290abef7a7c3.zip
Don't skip past the '}' if an expression has error and is not followed by ';'.
llvm-svn: 99972
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Parse/ParseStmt.cpp8
-rw-r--r--clang/test/Index/recover-bad-code-rdar_7487294.c1
-rw-r--r--clang/test/Parser/statements.c5
3 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 9fd145dc267..b752b48cfd4 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/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/clang/test/Index/recover-bad-code-rdar_7487294.c b/clang/test/Index/recover-bad-code-rdar_7487294.c
index 97bb5158e47..e060672b692 100644
--- a/clang/test/Index/recover-bad-code-rdar_7487294.c
+++ b/clang/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/clang/test/Parser/statements.c b/clang/test/Parser/statements.c
index a662c9b8211..bc7192a7b2b 100644
--- a/clang/test/Parser/statements.c
+++ b/clang/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'}}
+}
OpenPOWER on IntegriCloud