summaryrefslogtreecommitdiff
path: root/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-05-03 21:19:58 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-05-03 21:19:58 +0000
commit252ef566e8734b6bcf46434d0a7954c9eda0bd96 (patch)
treeb71231a8b801496ddd368cc3b642544a33bad547 /lib/Analysis/MemoryBuiltins.cpp
parent1d61f283fad2e49d3e50a3585aac4cc9183a0d28 (diff)
downloadllvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.gz
llvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.bz2
llvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.xz
add support for calloc to objectsize lowering
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156102 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--lib/Analysis/MemoryBuiltins.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Analysis/MemoryBuiltins.cpp b/lib/Analysis/MemoryBuiltins.cpp
index b145650b0f..347a7ea7a8 100644
--- a/lib/Analysis/MemoryBuiltins.cpp
+++ b/lib/Analysis/MemoryBuiltins.cpp
@@ -180,6 +180,46 @@ Value *llvm::getMallocArraySize(CallInst *CI, const TargetData *TD,
return computeArraySize(CI, TD, LookThroughSExt);
}
+
+//===----------------------------------------------------------------------===//
+// clloc Call Utility Functions.
+//
+
+static bool isCallocCall(const CallInst *CI) {
+ if (!CI)
+ return false;
+
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0 || !Callee->isDeclaration())
+ return false;
+ if (Callee->getName() != "calloc")
+ return false;
+
+ // Check malloc prototype.
+ // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
+ // attribute will exist.
+ FunctionType *FTy = Callee->getFunctionType();
+ return FTy->getReturnType() == Type::getInt8PtrTy(FTy->getContext()) &&
+ FTy->getNumParams() == 2 &&
+ ((FTy->getParamType(0)->isIntegerTy(32) &&
+ FTy->getParamType(1)->isIntegerTy(32)) ||
+ (FTy->getParamType(0)->isIntegerTy(64) &&
+ FTy->getParamType(1)->isIntegerTy(64)));
+}
+
+/// extractCallocCall - Returns the corresponding CallInst if the instruction
+/// is a calloc call.
+const CallInst *llvm::extractCallocCall(const Value *I) {
+ const CallInst *CI = dyn_cast<CallInst>(I);
+ return isCallocCall(CI) ? CI : 0;
+}
+
+CallInst *llvm::extractCallocCall(Value *I) {
+ CallInst *CI = dyn_cast<CallInst>(I);
+ return isCallocCall(CI) ? CI : 0;
+}
+
+
//===----------------------------------------------------------------------===//
// free Call Utility Functions.
//