Parse: Avoid crashing on unterminated top-level asm strings

When parsing invalid top-level asm statements, we were ignoring the
return code of the SkipUntil we used for recovery. This led to crashes
when we hit the end of file and tried to continue parsing anyway.

This fixes the crash and adds a couple of tests for parsing related
problems.

llvm-svn: 196961
This commit is contained in:
Justin Bogner 2013-12-10 21:29:48 +00:00
parent 29da7178c8
commit ab403f463a
2 changed files with 18 additions and 6 deletions

View File

@ -1354,16 +1354,15 @@ Parser::ExprResult Parser::ParseSimpleAsm(SourceLocation *EndLoc) {
ExprResult Result(ParseAsmStringLiteral());
if (Result.isInvalid()) {
SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
if (EndLoc)
*EndLoc = Tok.getLocation();
ConsumeAnyToken();
} else {
if (!Result.isInvalid()) {
// Close the paren and get the location of the end bracket
T.consumeClose();
if (EndLoc)
*EndLoc = T.getCloseLocation();
} else if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) {
if (EndLoc)
*EndLoc = Tok.getLocation();
ConsumeParen();
}
return Result;

View File

@ -23,3 +23,16 @@ __asm ; // expected-error {{expected '(' after 'asm'}}
// <rdar://problem/10465079> - Don't crash on wide string literals in 'asm'.
int foo asm (L"bar"); // expected-error {{cannot use wide string literal in 'asm'}}
asm() // expected-error {{expected string literal in 'asm'}}
// expected-error@-1 {{expected ';' after top-level asm block}}
asm(; // expected-error {{expected string literal in 'asm'}}
asm("") // expected-error {{expected ';' after top-level asm block}}
// Unterminated asm strings at the end of the file were causing us to crash, so
// this needs to be last. rdar://15624081
// expected-warning@+3 {{missing terminating '"' character}}
// expected-error@+2 {{expected string literal in 'asm'}}
// expected-error@+1 {{expected ';' after top-level asm block}}
asm("