[llvm-commits] [llvm] r83324 - /llvm/trunk/lib/Analysis/MallocHelper.cpp
Chris Lattner
clattner at apple.com
Mon Oct 5 14:28:23 PDT 2009
On Oct 5, 2009, at 2:15 PM, Torok Edwin wrote:
> Author: edwin
> Date: Mon Oct 5 16:15:43 2009
> New Revision: 83324
>
> URL: http://llvm.org/viewvc/llvm-project?rev=83324&view=rev
> Log:
> 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.
Thanks Edwin, please mention the PR in the FIXME so we can remember
what this is working around.
-Chris
>
> Modified:
> llvm/trunk/lib/Analysis/MallocHelper.cpp
>
> Modified: llvm/trunk/lib/Analysis/MallocHelper.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MallocHelper.cpp?rev=83324&r1=83323&r2=83324&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/Analysis/MallocHelper.cpp (original)
> +++ llvm/trunk/lib/Analysis/MallocHelper.cpp Mon Oct 5 16:15:43 2009
> @@ -34,12 +34,23 @@
> 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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list