summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-02-23 03:45:03 +0000
committerAlp Toker <alp@nuanti.com>2014-02-23 03:45:03 +0000
commitf2b6e793936188b0fcd4c15b86409a402f88e001 (patch)
treeaafb454069f5cb2b60126ab50d54fba4bf4485dc /clang/lib/Parse/Parser.cpp
parent3aa840e685658e26a58d33f03976dfee259ba779 (diff)
downloadbcm5719-llvm-f2b6e793936188b0fcd4c15b86409a402f88e001.tar.gz
bcm5719-llvm-f2b6e793936188b0fcd4c15b86409a402f88e001.zip
Fix crash when both ExpectAndConsume and ConsumeAnyToken emit diagnostics
The DiagnosticBuilder's lifetime in parser typo recovery was overlapping with the subsequent consume which can itself emit PP diagnostics. Patch by Olivier Goffart! llvm-svn: 201965
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r--clang/lib/Parse/Parser.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 71f5b845ddd..b76d430f176 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -118,18 +118,20 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
// Detect common single-character typos and resume.
if (IsCommonTypo(ExpectedTok, Tok)) {
SourceLocation Loc = Tok.getLocation();
- DiagnosticBuilder DB = Diag(Loc, DiagID);
- DB << FixItHint::CreateReplacement(SourceRange(Loc),
- getPunctuatorSpelling(ExpectedTok));
- if (DiagID == diag::err_expected)
- DB << ExpectedTok;
- else if (DiagID == diag::err_expected_after)
- DB << Msg << ExpectedTok;
- else
- DB << Msg;
- ConsumeAnyToken();
+ {
+ DiagnosticBuilder DB = Diag(Loc, DiagID);
+ DB << FixItHint::CreateReplacement(
+ SourceRange(Loc), tok::getPunctuatorSpelling(ExpectedTok));
+ if (DiagID == diag::err_expected)
+ DB << ExpectedTok;
+ else if (DiagID == diag::err_expected_after)
+ DB << Msg << ExpectedTok;
+ else
+ DB << Msg;
+ }
// Pretend there wasn't a problem.
+ ConsumeAnyToken();
return false;
}
OpenPOWER on IntegriCloud