Allow empty assembly string literal with -fno-gnu-inline-asm

Empty assembly string will not introduce assembly code in the output
binary and it is often used as a trick in the header to disable
optimizations. It doesn't conflict with the purpose of the option so it
is allowed with -fno-gnu-inline-asm flag.

llvm-svn: 237073
This commit is contained in:
Steven Wu
2015-05-12 00:16:37 +00:00
parent 0ddaf2bfb9
commit 18bbe191cd
3 changed files with 21 additions and 8 deletions

View File

@@ -670,12 +670,17 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
SourceLocation StartLoc = Tok.getLocation();
SourceLocation EndLoc;
// Check if GNU-style InlineAsm is disabled.
if (!getLangOpts().GNUAsm)
Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
ExprResult Result(ParseSimpleAsm(&EndLoc));
// Check if GNU-style InlineAsm is disabled.
// Empty asm string is allowed because it will not introduce
// any assembly code.
if (!(getLangOpts().GNUAsm || Result.isInvalid())) {
const auto *SL = cast<StringLiteral>(Result.get());
if (!SL->getString().trim().empty())
Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
}
ExpectAndConsume(tok::semi, diag::err_expected_after,
"top-level asm block");