Hi, I believe this is a regression from r198270
>From 932cf946fb9d1b99219532a2675cf859346ae21c Mon Sep 17 00:00:00 2001 From: Olivier Goffart <[email protected]> Date: Sat, 22 Feb 2014 15:02:32 +0100 Subject: [PATCH] Fix crash when both Parser::ExpectAndConsume and ConsumeAnyToken throw a diagnostic The diagnostic engine gets confuse on what is the current diagnostic --- lib/Parse/Parser.cpp | 20 +++++++++++--------- test/Parser/diag-crash.c | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/Parser/diag-crash.c diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 71f5b84..8158e11 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -118,15 +118,17 @@ 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; + { + 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(); // Pretend there wasn't a problem. diff --git a/test/Parser/diag-crash.c b/test/Parser/diag-crash.c new file mode 100644 index 0000000..cb985a2 --- /dev/null +++ b/test/Parser/diag-crash.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Don't crash if the preprocessor is throwing a diagnostic from Parser::ExceptAndConsume +int foo: // expected-error {{expected ';' after top level declarator}} +#endif // expected-error {{#endif without #if}} \ No newline at end of file -- 1.9.0
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
