Grab the LLVMContext and parent Module of SI ahead of the
authorDan Gohman <gohman@apple.com>
Tue, 28 Jul 2009 00:37:06 +0000 (00:37 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 28 Jul 2009 00:37:06 +0000 (00:37 +0000)
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

lib/Transforms/Scalar/MemCpyOptimizer.cpp

index f63a912d6ca1de112036df9e297d3892385c53f2..c359e47d05d790dcb2a7ccc7f505b8278aa70073 100644 (file)
@@ -352,6 +352,8 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) {
 
   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 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) {
   
     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 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) {
     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);