[cfe-commits] r81756 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/builtin-attributes.c

Daniel Dunbar daniel at zuster.org
Sun Sep 13 21:33:22 PDT 2009


Author: ddunbar
Date: Sun Sep 13 23:33:21 2009
New Revision: 81756

URL: http://llvm.org/viewvc/llvm-project?rev=81756&view=rev
Log:
Fix subtle bug in generating LLVM function declarations for builtin functions.

The decl wasn't being passed down, which meant that function attributes were not
being set correctly. This is particularly important for ARM, since it wants to
override the calling convention. Instead we would emit the builtin with the
wrong calling convention, and instcombine would come along and merrily shred all
the calls to it. :)

Added:
    cfe/trunk/test/CodeGen/builtin-attributes.c
Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=81756&r1=81755&r2=81756&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sun Sep 13 23:33:21 2009
@@ -556,7 +556,7 @@
   // that function.
   if (getContext().BuiltinInfo.isLibFunction(BuiltinID) ||
       getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID))
-    return EmitCall(CGM.getBuiltinLibFunction(BuiltinID),
+    return EmitCall(CGM.getBuiltinLibFunction(FD, BuiltinID),
                     E->getCallee()->getType(), E->arg_begin(),
                     E->arg_end());
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=81756&r1=81755&r2=81756&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Sep 13 23:33:21 2009
@@ -1256,7 +1256,8 @@
 
 /// getBuiltinLibFunction - Given a builtin id for a function like
 /// "__builtin_fabsf", return a Function* for "fabsf".
-llvm::Value *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) {
+llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
+                                                  unsigned BuiltinID) {
   assert((Context.BuiltinInfo.isLibFunction(BuiltinID) ||
           Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) &&
          "isn't a lib fn");
@@ -1276,8 +1277,7 @@
 
   // Unique the name through the identifier table.
   Name = getContext().Idents.get(Name).getName();
-  // FIXME: param attributes for sext/zext etc.
-  return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl());
+  return GetOrCreateLLVMFunction(Name, Ty, GlobalDecl(FD));
 }
 
 llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=81756&r1=81755&r2=81756&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sun Sep 13 23:33:21 2009
@@ -303,7 +303,8 @@
 
   /// getBuiltinLibFunction - Given a builtin id for a function like
   /// "__builtin_fabsf", return a Function* for "fabsf".
-  llvm::Value *getBuiltinLibFunction(unsigned BuiltinID);
+  llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
+                                     unsigned BuiltinID);
 
   llvm::Function *getMemCpyFn();
   llvm::Function *getMemMoveFn();

Added: cfe/trunk/test/CodeGen/builtin-attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-attributes.c?rev=81756&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/builtin-attributes.c (added)
+++ cfe/trunk/test/CodeGen/builtin-attributes.c Sun Sep 13 23:33:21 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -triple arm-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: declare arm_aapcscc i32 @printf(i8*, ...)
+void f0() {
+  printf("a\n");
+}
+
+// CHECK: call arm_aapcscc void @exit
+// CHECK: unreachable
+void f1() {
+  exit(1);
+}





More information about the cfe-commits mailing list