Grab the LLVMContext and parent Module of SI ahead of the
point where SI can get deleted. This fixes a use of free'd memory.
This fixes Externals/Povray.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77285 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index f63a912..c359e47 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -352,6 +352,8 @@
TargetData &TD = getAnalysis<TargetData>();
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
+ LLVMContext &Context = SI->getContext();
+ Module *M = SI->getParent()->getParent()->getParent();
// Okay, so we now have a single store that can be splatable. Scan to find
// all subsequent stores of the same value to offset from the same pointer.
@@ -431,8 +433,7 @@
if (MemSetF == 0) {
const Type *Tys[] = {Type::Int64Ty};
- MemSetF = Intrinsic::getDeclaration(SI->getParent()->getParent()
- ->getParent(), Intrinsic::memset,
+ MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset,
Tys, 1);
}
@@ -440,7 +441,7 @@
StartPtr = Range.StartPtr;
// Cast the start ptr to be i8* as memset requires.
- const Type *i8Ptr = SI->getContext().getPointerTypeUnqual(Type::Int8Ty);
+ const Type *i8Ptr = Context.getPointerTypeUnqual(Type::Int8Ty);
if (StartPtr->getType() != i8Ptr)
StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(),
InsertPt);