diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-08-22 23:55:33 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-08-22 23:55:33 +0000 |
commit | 2873aee1774a2ae731d6cc5c5ee05ba82780dc98 (patch) | |
tree | 50fe906ab43fd3423d15df69595e147dcd08b6fd | |
parent | 294396b9f2a2f4ffee6b7ed5e61211fde50b6554 (diff) |
Make sure we don't inline functions marked with __attribute__((naked)). <rdar://problem/9973228>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138310 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 13 | ||||
-rw-r--r-- | test/CodeGen/attr-naked.c | 11 |
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0584a32806..3e30c57f24 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -472,15 +472,20 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (!Features.Exceptions && !Features.ObjCNonFragileABI) F->addFnAttr(llvm::Attribute::NoUnwind); - if (D->hasAttr<AlwaysInlineAttr>()) - F->addFnAttr(llvm::Attribute::AlwaysInline); - - if (D->hasAttr<NakedAttr>()) + if (D->hasAttr<NakedAttr>()) { + // Naked implies noinline: we should not be inlining such functions. F->addFnAttr(llvm::Attribute::Naked); + F->addFnAttr(llvm::Attribute::NoInline); + } if (D->hasAttr<NoInlineAttr>()) F->addFnAttr(llvm::Attribute::NoInline); + // (noinline wins over always_inline, and we can't specify both in IR) + if (D->hasAttr<AlwaysInlineAttr>() && + !F->hasFnAttr(llvm::Attribute::NoInline)) + F->addFnAttr(llvm::Attribute::AlwaysInline); + if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D)) F->setUnnamedAddr(true); diff --git a/test/CodeGen/attr-naked.c b/test/CodeGen/attr-naked.c index bccacc9916..2387d288ec 100644 --- a/test/CodeGen/attr-naked.c +++ b/test/CodeGen/attr-naked.c @@ -1,9 +1,16 @@ -// RUN: %clang_cc1 -g -emit-llvm -o %t %s -// RUN: grep 'naked' %t +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 %s -emit-llvm -o - | FileCheck %s void t1() __attribute__((naked)); +// Basic functionality check +// (Note that naked needs to imply noinline to work properly.) +// CHECK: define void @t1() nounwind noinline naked { void t1() { } +// Make sure this doesn't explode in the verifier. +// (It doesn't really make sense, but it isn't invalid.) +// CHECK: define void @t2() nounwind noinline naked { +__attribute((naked, always_inline)) void t2() { +} |