]> granicus.if.org Git - clang/commitdiff
Fix subtle bug in generating LLVM function declarations for builtin functions.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 14 Sep 2009 04:33:21 +0000 (04:33 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 14 Sep 2009 04:33:21 +0000 (04:33 +0000)
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. :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81756 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
test/CodeGen/builtin-attributes.c [new file with mode: 0644]

index 77c408a9638597f21fb4bd67a75e442b1edc6b45..e049cc890d730bc6909664c7c8e20cc511c5cdfc 100644 (file)
@@ -556,7 +556,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
   // 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());
 
index 05f14682d782a7f04e7cefbc963491799ceee593..fca6ebefda4cbfa8a7676e7c2d0417050dca738e 100644 (file)
@@ -1256,7 +1256,8 @@ void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) {
 
 /// 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 @@ llvm::Value *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) {
 
   // 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,
index f115feba4fd01f115da8df095a1b066e7ced3c29..ff8ffb305df0b17a660692006b063fd92cdd88f4 100644 (file)
@@ -303,7 +303,8 @@ public:
 
   /// 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();
diff --git a/test/CodeGen/builtin-attributes.c b/test/CodeGen/builtin-attributes.c
new file mode 100644 (file)
index 0000000..184e967
--- /dev/null
@@ -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);
+}