aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/MallocHelper.cpp
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-10-24 04:23:03 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-10-24 04:23:03 +0000
commit66284e063a1e46500acae48bdc0e4a00652021d1 (patch)
tree7326efcf20c334046c044082a205dc2eb1f17466 /lib/Analysis/MallocHelper.cpp
parent5a850beb2e3032e6ff3474ce5317f5454060328c (diff)
Auto-upgrade free instructions to calls to the builtin free function.
Update all analysis passes and transforms to treat free calls just like FreeInst. Remove RaiseAllocations and all its tests since FreeInst no longer needs to be raised. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84987 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MallocHelper.cpp')
-rw-r--r--lib/Analysis/MallocHelper.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Analysis/MallocHelper.cpp b/lib/Analysis/MallocHelper.cpp
index e7bb41eeec..511de9d6a5 100644
--- a/lib/Analysis/MallocHelper.cpp
+++ b/lib/Analysis/MallocHelper.cpp
@@ -263,3 +263,29 @@ Value* llvm::getMallocArraySize(CallInst* CI, LLVMContext &Context,
assert(BO && "getMallocArraySize not constant but not multiplication either");
return BO->getOperand(0);
}
+
+/// isFreeCall - Returns true if the the value is a call to the builtin free()
+bool llvm::isFreeCall(const Value* I) {
+ const CallInst *CI = dyn_cast<CallInst>(I);
+ if (!CI)
+ return false;
+
+ const Module* M = CI->getParent()->getParent()->getParent();
+ Function *FreeFunc = M->getFunction("free");
+
+ if (CI->getOperand(0) != FreeFunc)
+ return false;
+
+ // Check free prototype.
+ // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
+ // attribute will exist.
+ const FunctionType *FTy = FreeFunc->getFunctionType();
+ if (FTy->getReturnType() != Type::getVoidTy(M->getContext()))
+ return false;
+ if (FTy->getNumParams() != 1)
+ return false;
+ if (FTy->param_begin()->get() != Type::getInt8PtrTy(M->getContext()))
+ return false;
+
+ return true;
+}