[PATCH] D24193: Allow variables with asm labels in naked functions
Nikola Smiljanić via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 12 03:03:05 PDT 2016
nikola updated this revision to Diff 70985.
nikola added a comment.
This should address Hans' comments, as for the code get I have no idea. I was hoping someone more knowledgeable would tell me if this made sense or not?
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,21 @@
"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");
+}
+
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11792,6 +11792,21 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24193.70985.patch
Type: text/x-patch
Size: 2005 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160912/e8d635f3/attachment.bin>
More information about the cfe-commits
mailing list