From: Chris Lattner Date: Sun, 3 Jan 2010 18:14:24 +0000 (+0000) Subject: it isn't safe to speculative load from a malloc, it might have X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fa5dd977e4ed16a82e1367ff9ed77c94d4054457;p=oota-llvm.git it isn't safe to speculative load from a malloc, it might have returned null, and may not have been big enough in any case. Thanks to Jay Foad for pointing this out! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92452 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index a5500e6de48..170a15f216f 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -374,37 +374,6 @@ bool Instruction::isCommutative(unsigned op) { } } -// Code here matches isMalloc from MemoryBuiltins, which is not in VMCore. -static bool isMalloc(const Value* I) { - const CallInst *CI = dyn_cast(I); - if (!CI) { - const BitCastInst *BCI = dyn_cast(I); - if (!BCI) return false; - - CI = dyn_cast(BCI->getOperand(0)); - } - - if (!CI) - return false; - Function *Callee = CI->getCalledFunction(); - if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc") - return false; - - // Check malloc prototype. - // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin - // attribute will exist. - const FunctionType *FTy = Callee->getFunctionType(); - if (FTy->getNumParams() != 1) - return false; - if (IntegerType *ITy = dyn_cast(FTy->param_begin()->get())) { - if (ITy->getBitWidth() != 32 && ITy->getBitWidth() != 64) - return false; - return true; - } - - return false; -} - bool Instruction::isSafeToSpeculativelyExecute() const { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) if (Constant *C = dyn_cast(getOperand(i))) @@ -430,7 +399,7 @@ bool Instruction::isSafeToSpeculativelyExecute() const { case Load: { if (cast(this)->isVolatile()) return false; - if (isa(getOperand(0)) || isMalloc(getOperand(0))) + if (isa(getOperand(0))) return true; if (GlobalVariable *GV = dyn_cast(getOperand(0))) return !GV->hasExternalWeakLinkage();