mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-10 10:01:42 +00:00
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
This commit is contained in:
parent
3aa840e685
commit
f2b6e79393
clang
@ -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;
|
||||
}
|
||||
|
||||
|
6
clang/test/Parser/diag-crash.c
Normal file
6
clang/test/Parser/diag-crash.c
Normal file
@ -0,0 +1,6 @@
|
||||
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
||||
|
||||
// Avoid preprocessor diag crash caused by a parser diag left in flight.
|
||||
|
||||
int foo: // expected-error {{expected ';' after top level declarator}}
|
||||
#endif // expected-error {{#endif without #if}}
|
Loading…
Reference in New Issue
Block a user