This is an archive of the discontinued LLVM Phabricator instance.

Allow AsmLabel with -fno-gnu-inline-asm
ClosedPublic

Authored by steven_wu on May 11 2015, 1:54 PM.

Details

Summary

AsmLabel is heavily used in system level and firmware to redirect
function and access platform specific labels. They are also extensively
used in system headers which makes this option unusable for many
users. Since AsmLabel doesn't introduce any assembly code into the
output binary, it shouldn't be considered as inline-asm.

Diff Detail

Repository
rL LLVM

Event Timeline

steven_wu updated this revision to Diff 25506.May 11 2015, 1:54 PM
steven_wu retitled this revision from to Allow AsmLabel with -fno-gnu-inline-asm.
steven_wu updated this object.
steven_wu edited the test plan for this revision. (Show Details)
steven_wu added reviewers: rnk, bob.wilson.
steven_wu added a subscriber: Unknown Object (MLST).
rnk accepted this revision.May 11 2015, 2:07 PM
rnk edited edge metadata.

lgtm

Yeah, the asm label syntax isn't really assembly.

This revision is now accepted and ready to land.May 11 2015, 2:07 PM
This revision was automatically updated to reflect the committed changes.

Thanks, Reid. Committed in r237048.

Steven

Hi Reid

I did more digging in the darwin system headers and realize there are lots more than AsmLabel that prevents the user using this flag correctly.
For example, we have quite many empty file scope assembly blocks asm(“”) which are used to disable tail call optimization.
I think it will be better if we should just ignore system headers rather than special case them. Patch attached.

Steven

diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index ed27a9e..9c5d85d 100644

  • a/lib/Parse/Parser.cpp

+++ b/lib/Parse/Parser.cpp
@@ -671,7 +671,8 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,

SourceLocation EndLoc;
 
// Check if GNU-style InlineAsm is disabled.
  • if (!getLangOpts().GNUAsm)

+ if (!(getLangOpts().GNUAsm ||
+ PP.getSourceManager().isInSystemHeader(StartLoc)))

  Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
 
ExprResult Result(ParseSimpleAsm(&EndLoc));

diff --git a/test/Parser/no-gnu-inline-asm.c b/test/Parser/no-gnu-inline-asm.c
index 7089fa4..bae28de 100644

  • a/test/Parser/no-gnu-inline-asm.c

+++ b/test/Parser/no-gnu-inline-asm.c
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 %s -triple i686-apple-darwin -verify -fsyntax-only -fno-gnu-inline-asm

+#include "no-gnu-inline-asm.h" file scope asm is ok in system header
+
asm ("INST r1, 0");
expected-error {{GNU-style inline assembly is disabled}}

void foo() asm("foo_func"); // AsmLabel is OK
diff --git a/test/Parser/no-gnu-inline-asm.h b/test/Parser/no-gnu-inline-asm.h
new file mode 100644
index 0000000..ba12e08

  • /dev/null

+++ b/test/Parser/no-gnu-inline-asm.h
@@ -0,0 +1,3 @@
+ Test -fno-gnu-inline-asm in system header
+#pragma clang system_header
+asm("");
file scope asm is OK in system header

rnk added a comment.May 11 2015, 4:18 PM

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.