diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-24 02:26:51 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-24 02:26:51 +0000 |
commit | 5d5ed59f1ee57ad2639f0ef1fb400f8854480bb0 (patch) | |
tree | 98582d9d9afa3261b73a45ad408e2e582724e9d9 /lib/Parse/ParseStmt.cpp | |
parent | e27af29401da15cc2e9a92825cb24adb1aef7091 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 5fe5e6a2b6..79b53c3b24 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -823,17 +823,20 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { 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); } |