[PATCH] D24193: Allow variables with asm labels in naked functions

Nikola Smiljanić via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 07:35:04 PDT 2016


nikola created this revision.
nikola added reviewers: hans, rnk, compnerd.
nikola added a subscriber: cfe-commits.
Herald added a subscriber: aemerson.

I think the current mode is too restrictive, it will emit error for any statement inside a naked function. Code I'm trying to compile for ARM declares registers as variables to improve readability and passes them as input operands to inline assembly.

register uint32_t Something asm("rax");


https://reviews.llvm.org/D24193

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/attr-naked.c

Index: test/Sema/attr-naked.c
===================================================================
--- test/Sema/attr-naked.c
+++ test/Sema/attr-naked.c
@@ -48,3 +48,12 @@
                "r"(z) // expected-error{{parameter references not allowed in naked functions}}
            );
 }
+
+__attribute__((naked)) void t10() {  // expected-note{{attribute is here}}
+  int x; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t11() {
+  register int x asm("eax");
+}
+
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11792,6 +11792,14 @@
 
     if (FD && FD->hasAttr<NakedAttr>()) {
       for (const Stmt *S : Body->children()) {
+        if (auto *DS = dyn_cast<DeclStmt>(S)) {
+          if (DS->isSingleDecl()) {
+            if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) {
+              if (Var->hasAttr<AsmLabelAttr>())
+                continue;
+            }
+          }
+        }
         if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) {
           Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function);
           Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24193.70161.patch
Type: text/x-patch
Size: 1282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160902/483e61a0/attachment.bin>


More information about the cfe-commits mailing list