From: Nikola Smiljanic Date: Tue, 13 Sep 2016 07:02:02 +0000 (+0000) Subject: Allow register variables in naked functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b9f3606b58ed9206cf32e6f555863b296911f23;p=clang Allow register variables in naked functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281298 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 773d00bf2d..0c2540b9b7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11818,6 +11818,21 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (FD && FD->hasAttr()) { 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(S)) { + for (const auto *Decl : DS->decls()) { + if (const auto *Var = dyn_cast(Decl)) { + RegisterVariables = + Var->hasAttr() && !Var->hasInit(); + if (!RegisterVariables) + break; + } + } + } + if (RegisterVariables) + continue; if (!isa(S) && !isa(S)) { Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function); Diag(FD->getAttr()->getLocation(), diag::note_attribute); diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c index 6b1344a986..c9a3f1dbfc 100644 --- a/test/Sema/attr-naked.c +++ b/test/Sema/attr-naked.c @@ -48,3 +48,21 @@ __attribute__((naked)) void t9(int z) { // expected-note{{attribute is here}} "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"); +} +