Skip to content

Commit

Permalink
Don't treat malloc calls with non-matching prototype as malloc.
Browse files Browse the repository at this point in the history
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
edwintorok committed Oct 5, 2009
1 parent aa5c1b7 commit 85c005a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/Analysis/MallocHelper.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 85c005a

Please sign in to comment.