[cfe-commits] r138310 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/attr-naked.c

Eli Friedman eli.friedman at gmail.com
Mon Aug 22 16:55:33 PDT 2011


Author: efriedma
Date: Mon Aug 22 18:55:33 2011
New Revision: 138310

URL: http://llvm.org/viewvc/llvm-project?rev=138310&view=rev
Log:
Make sure we don't inline functions marked with __attribute__((naked)).  <rdar://problem/9973228>


Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/attr-naked.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=138310&r1=138309&r2=138310&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Aug 22 18:55:33 2011
@@ -472,15 +472,20 @@
   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);
 

Modified: cfe/trunk/test/CodeGen/attr-naked.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-naked.c?rev=138310&r1=138309&r2=138310&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-naked.c (original)
+++ cfe/trunk/test/CodeGen/attr-naked.c Mon Aug 22 18:55:33 2011
@@ -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()  {
+}





More information about the cfe-commits mailing list