[PATCH] Allow AsmLabel with -fno-gnu-inline-asm
Steven Wu
stevenwu at apple.com
Mon May 11 16:53:34 PDT 2015
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
+
void f (void) {
long long foo = 0, bar;
asm volatile("INST %0, %1" : "=r"(foo) : "r"(bar)); // expected-error {{GNU-style inline assembly is disabled}}
> On May 11, 2015, at 4:18 PM, Reid Kleckner <rnk at google.com> wrote:
>
> I think it might be better to special case empty or white-space only inline asm. That way this flag actually tells you that the .ll file produced doesn't have any instructions already baked into it.
>
>
> REPOSITORY
> rL LLVM
>
> http://reviews.llvm.org/D9679
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
>
>
More information about the cfe-commits
mailing list