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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits