diff options
author | Torok Edwin <edwintorok@gmail.com> | 2009-10-05 21:15:43 +0000 |
---|---|---|
committer | Torok Edwin <edwintorok@gmail.com> | 2009-10-05 21:15:43 +0000 |
commit | 85c005af0d63c484114ce88258aecb8e1c8c2fa2 (patch) | |
tree | 9e5a2ac0739d903e125f24d58ec77a676bb25fdc /lib/Analysis/MallocHelper.cpp | |
parent | aa5c1b7f9366950b4cbe710c8426d8589d5d975b (diff) |
Don't treat malloc calls with non-matching prototype as malloc.
Fixes second part of PR5130, miscompilation in FreeBSD kernel, where malloc takes 3 params,
and *does* initialize memory.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MallocHelper.cpp')
-rw-r--r-- | lib/Analysis/MallocHelper.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Analysis/MallocHelper.cpp b/lib/Analysis/MallocHelper.cpp index ab6239e55a..1a8665b6f6 100644 --- a/lib/Analysis/MallocHelper.cpp +++ b/lib/Analysis/MallocHelper.cpp @@ -34,12 +34,23 @@ static bool isMallocCall(const CallInst *CI) { return false; const Module* M = CI->getParent()->getParent()->getParent(); - Constant *MallocFunc = M->getFunction("malloc"); + Function *MallocFunc = M->getFunction("malloc"); if (CI->getOperand(0) != MallocFunc) return false; - return true; + // Check malloc prototype. + // FIXME: this will be obsolete when nobuiltin attribute will exist. + const FunctionType *FTy = MallocFunc->getFunctionType(); + if (FTy->getNumParams() != 1) + return false; + if (IntegerType *ITy = dyn_cast<IntegerType>(FTy->param_begin()->get())) { + if (ITy->getBitWidth() != 32 && ITy->getBitWidth() != 64) + return false; + return true; + } + + return false; } /// extractMallocCall - Returns the corresponding CallInst if the instruction |