Thanks Reid! Actually, for the consistency, I should allow empty function scope as well. Dup the same logic in the StmtAsm parser. Committed in r237073.
Steven > On May 11, 2015, at 5:11 PM, Reid Kleckner <[email protected]> wrote: > > Sounds good, go for it. > > On Mon, May 11, 2015 at 4:53 PM, Steven Wu <[email protected] > <mailto:[email protected]>> wrote: > Great! If the extra special case doesn’t make the option ambiguous about what > it is doing, I am happier with this approach. Here is the patch. > > commit 9dd3fdfa3a90687e46c4731c9d23f4f1885a23f9 > Author: Steven Wu <[email protected] <mailto:[email protected]>> > Date: Mon May 11 16:47:27 2015 -0700 > > 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. > > diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp > index ed27a9e..697fda9 100644 > --- a/lib/Parse/Parser.cpp > +++ b/lib/Parse/Parser.cpp > @@ -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"); > > diff --git a/test/Parser/no-gnu-inline-asm.c b/test/Parser/no-gnu-inline-asm.c > index 7089fa4..7a13f20 100644 > --- a/test/Parser/no-gnu-inline-asm.c > +++ b/test/Parser/no-gnu-inline-asm.c > @@ -5,6 +5,8 @@ asm ("INST r1, 0"); // expected-error {{GNU-style inline > assembly is disabled}} > void foo() __asm("__foo_func"); // AsmLabel is OK > int foo1 asm("bar1") = 0; // OK > > +asm(" "); // Whitespace is OK > > I think it's more interesting to test this in a function context instead of a > module context.
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
