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 | 6db850133f66abbe89a2d6c0f161c063eba79840 (patch) | |
tree | 4f0a0e19e26b945ec1534c8650496572129578ab /clang/lib | |
parent | 4b9ab74690b84b2b095d56e6f222456e333e91eb (diff) | |
download | bcm5719-llvm-6db850133f66abbe89a2d6c0f161c063eba79840.tar.gz bcm5719-llvm-6db850133f66abbe89a2d6c0f161c063eba79840.zip |
[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
llvm-svn: 153367
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 5fe5e6a2b6a..79b53c3b245 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/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); } |