[PATCH] Allow AsmLabel with -fno-gnu-inline-asm
Reid Kleckner
rnk at google.com
Mon May 11 17:11:28 PDT 2015
Sounds good, go for it.
On Mon, May 11, 2015 at 4:53 PM, Steven Wu <stevenwu at apple.com> 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 <stevenwu at apple.com>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150511/45c3cb02/attachment.html>
More information about the cfe-commits
mailing list