[cfe-commits] r153367 - in /cfe/trunk: lib/Parse/ParseStmt.cpp test/Index/unmatched-braces.c test/Index/unmatched-braces.m
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Mar 23 19:26:52 PDT 2012
Author: akirtzidis
Date: Fri Mar 23 21:26:51 2012
New Revision: 153367
URL: http://llvm.org/viewvc/llvm-project?rev=153367&view=rev
Log:
[parser] If there are unmatched braces in a function definition, try to
recover by returning the statements that we parsed so far, instead of
dropping the whole function body.
rdar://10967343
Added:
cfe/trunk/test/Index/unmatched-braces.c
cfe/trunk/test/Index/unmatched-braces.m
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=153367&r1=153366&r2=153367&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Mar 23 21:26:51 2012
@@ -823,17 +823,20 @@
Stmts.push_back(R.release());
}
+ SourceLocation CloseLoc = Tok.getLocation();
+
// We broke out of the while loop because we found a '}' or EOF.
if (Tok.isNot(tok::r_brace)) {
Diag(Tok, diag::err_expected_rbrace);
Diag(T.getOpenLocation(), diag::note_matching) << "{";
- return StmtError();
+ // Recover by creating a compound statement with what we parsed so far,
+ // instead of dropping everything and returning StmtError();
+ } else {
+ if (!T.consumeClose())
+ CloseLoc = T.getCloseLocation();
}
- if (T.consumeClose())
- return StmtError();
-
- return Actions.ActOnCompoundStmt(T.getOpenLocation(), T.getCloseLocation(),
+ return Actions.ActOnCompoundStmt(T.getOpenLocation(), CloseLoc,
move_arg(Stmts), isStmtExpr);
}
Added: cfe/trunk/test/Index/unmatched-braces.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/unmatched-braces.c?rev=153367&view=auto
==============================================================================
--- cfe/trunk/test/Index/unmatched-braces.c (added)
+++ cfe/trunk/test/Index/unmatched-braces.c Fri Mar 23 21:26:51 2012
@@ -0,0 +1,9 @@
+void foo() {
+ int x;
+ if (x) {
+}
+
+// RUN: c-index-test -cursor-at=%s:2:7 %s > %t
+// RUN: FileCheck %s -input-file %t
+
+// CHECK: VarDecl=x:2:7
Added: cfe/trunk/test/Index/unmatched-braces.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/unmatched-braces.m?rev=153367&view=auto
==============================================================================
--- cfe/trunk/test/Index/unmatched-braces.m (added)
+++ cfe/trunk/test/Index/unmatched-braces.m Fri Mar 23 21:26:51 2012
@@ -0,0 +1,11 @@
+ at implementation I
+-(void)meth {
+ int x;
+ if (x) {
+}
+ at end
+
+// RUN: c-index-test -cursor-at=%s:3:7 %s > %t
+// RUN: FileCheck %s -input-file %t
+
+// CHECK: VarDecl=x:3:7
More information about the cfe-commits
mailing list