r281298 - Allow register variables in naked functions.

Nikola Smiljanic via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 13 00:02:03 PDT 2016


Author: nikola
Date: Tue Sep 13 02:02:02 2016
New Revision: 281298

URL: http://llvm.org/viewvc/llvm-project?rev=281298&view=rev
Log:
Allow register variables in naked functions.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/attr-naked.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=281298&r1=281297&r2=281298&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 13 02:02:02 2016
@@ -11818,6 +11818,21 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 
     if (FD && FD->hasAttr<NakedAttr>()) {
       for (const Stmt *S : Body->children()) {
+        // Allow local register variables without initializer as they don't
+        // require prologue.
+        bool RegisterVariables = false;
+        if (auto *DS = dyn_cast<DeclStmt>(S)) {
+          for (const auto *Decl : DS->decls()) {
+            if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
+              RegisterVariables =
+                  Var->hasAttr<AsmLabelAttr>() && !Var->hasInit();
+              if (!RegisterVariables)
+                break;
+            }
+          }
+        }
+        if (RegisterVariables)
+          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);

Modified: cfe/trunk/test/Sema/attr-naked.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-naked.c?rev=281298&r1=281297&r2=281298&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-naked.c (original)
+++ cfe/trunk/test/Sema/attr-naked.c Tue Sep 13 02:02:02 2016
@@ -48,3 +48,21 @@ __attribute__((naked)) void t9(int z) {
                "r"(z) // expected-error{{parameter references not allowed in naked functions}}
            );
 }
+
+__attribute__((naked)) void t10() {  // expected-note{{attribute is here}}
+  int a; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t11() {  // expected-note{{attribute is here}}
+  register int a asm("eax") = x; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t12() {  // expected-note{{attribute is here}}
+  register int a asm("eax"), b asm("ebx") = x; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t13() {
+  register int a asm("eax");
+  register int b asm("ebx"), c asm("ecx");
+}
+




More information about the cfe-commits mailing list