[llvm-branch-commits] [llvm-branch] r86713 - /llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp

Victor Hernandez vhernandez at apple.com
Tue Nov 10 12:15:43 PST 2009


Author: hernande
Date: Tue Nov 10 14:15:43 2009
New Revision: 86713

URL: http://llvm.org/viewvc/llvm-project?rev=86713&view=rev
Log:
--- Merging 86712 into '.':
U    lib/VMCore/Instructions.cpp


Modified:
    llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp

Modified: llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp?rev=86713&r1=86712&r2=86713&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp Tue Nov 10 14:15:43 2009
@@ -495,22 +495,21 @@
   BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
   Module* M = BB->getParent()->getParent();
   const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
-  if (!MallocF)
+  Value *MallocFunc = MallocF;
+  if (!MallocFunc)
     // prototype malloc as "void *malloc(size_t)"
-    MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
-                                                    IntPtrTy, NULL));
-  if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
+    MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
   const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
   CallInst *MCall = NULL;
   Instruction *Result = NULL;
   if (InsertBefore) {
-    MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore);
+    MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall", InsertBefore);
     Result = MCall;
     if (Result->getType() != AllocPtrType)
       // Create a cast instruction to convert to the right type...
       Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
   } else {
-    MCall = CallInst::Create(MallocF, AllocSize, "malloccall");
+    MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall");
     Result = MCall;
     if (Result->getType() != AllocPtrType) {
       InsertAtEnd->getInstList().push_back(MCall);
@@ -519,7 +518,10 @@
     }
   }
   MCall->setTailCall();
-  MCall->setCallingConv(MallocF->getCallingConv());
+  if (Function *F = dyn_cast<Function>(MallocFunc)) {
+    MCall->setCallingConv(F->getCallingConv());
+    if (!F->doesNotAlias(0)) F->setDoesNotAlias(0);
+  }
   assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
          "Malloc has void return type");
 





More information about the llvm-branch-commits mailing list