Support fuzzy parsing MS line-oriented __asm's that originate from a macro (a case where we can't obtain source line info). As the test case indicates, we don't currently support line-oriented asm statements that mix file/macro body tokens.

llvm-svn: 46878
This commit is contained in:
Steve Naroff 2008-02-08 03:36:19 +00:00
parent 7a55a94ba1
commit db5f7d7699
2 changed files with 26 additions and 5 deletions

View File

@ -921,11 +921,22 @@ Parser::StmtResult Parser::FuzzyParseMicrosoftAsmStatement() {
// From the MS website: If used without braces, the __asm keyword means
// that the rest of the line is an assembly-language statement.
SourceManager &SrcMgr = PP.getSourceManager();
unsigned lineNo = SrcMgr.getLineNumber(Tok.getLocation());
do {
ConsumeAnyToken();
} while ((SrcMgr.getLineNumber(Tok.getLocation()) == lineNo) &&
Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof));
SourceLocation TokLoc = Tok.getLocation();
if (TokLoc.isFileID()) {
unsigned lineNo = SrcMgr.getLineNumber(TokLoc);
do {
ConsumeAnyToken();
TokLoc = Tok.getLocation();
} while (TokLoc.isFileID() && (SrcMgr.getLineNumber(TokLoc) == lineNo) &&
Tok.isNot(tok::r_brace) && Tok.isNot(tok::semi) &&
Tok.isNot(tok::eof));
} else { // The asm tokens come from a macro expansion.
do {
ConsumeAnyToken();
TokLoc = Tok.getLocation();
} while (TokLoc.isMacroID() && Tok.isNot(tok::r_brace) &&
Tok.isNot(tok::semi) && Tok.isNot(tok::eof));
}
}
return false;
}

View File

@ -0,0 +1,10 @@
// RUN: clang %s -verify -fms-extensions
#define M __asm int 0x2c
#define M2 int
void t1(void) { M }
void t2(void) { __asm int 0x2c }
// FIXME? We don't support fuzzy parsing line-oriented __asm's where the body is partially defined in a macro.
void t3(void) { __asm M2 0x2c } // expected-error{{expected ';' after expression}} expected-warning{{expression result unused}}