From 27ed1c2eb0f8a9a2539cd0762b28a77f665ca510 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Wed, 2 Mar 2016 20:27:29 +0000 Subject: [PATCH] Fix ASAN detected errors in code and test llvm-svn: 262511 --- llvm/lib/Transforms/Utils/MemorySSA.cpp | 5 ++--- llvm/unittests/Transforms/Utils/MemorySSA.cpp | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Transforms/Utils/MemorySSA.cpp b/llvm/lib/Transforms/Utils/MemorySSA.cpp index 8013b4a..f7dc744 100644 --- a/llvm/lib/Transforms/Utils/MemorySSA.cpp +++ b/llvm/lib/Transforms/Utils/MemorySSA.cpp @@ -231,7 +231,7 @@ MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA, assert(!this->AA && !this->DT && "MemorySSA without a walker already has AA or DT?"); - auto *Result = new CachingMemorySSAWalker(this, AA, DT); + Walker = new CachingMemorySSAWalker(this, AA, DT); this->AA = AA; this->DT = DT; @@ -343,7 +343,7 @@ MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA, for (auto &MA : *Accesses) { if (auto *MU = dyn_cast(&MA)) { Instruction *Inst = MU->getMemoryInst(); - MU->setDefiningAccess(Result->getClobberingMemoryAccess(Inst)); + MU->setDefiningAccess(Walker->getClobberingMemoryAccess(Inst)); } } } @@ -354,7 +354,6 @@ MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA, if (!Visited.count(&BB)) markUnreachableAsLiveOnEntry(&BB); - Walker = Result; return Walker; } diff --git a/llvm/unittests/Transforms/Utils/MemorySSA.cpp b/llvm/unittests/Transforms/Utils/MemorySSA.cpp index 0657192..18760184 100644 --- a/llvm/unittests/Transforms/Utils/MemorySSA.cpp +++ b/llvm/unittests/Transforms/Utils/MemorySSA.cpp @@ -21,6 +21,7 @@ using namespace llvm; TEST(MemorySSA, RemoveMemoryAccess) { LLVMContext &C(getGlobalContext()); + std::unique_ptr M(new Module("Remove memory access", C)); IRBuilder<> B(C); DataLayout DL("e-i64:64-f80:128-n8:16:32:64-S128"); TargetLibraryInfoImpl TLII; @@ -29,13 +30,13 @@ TEST(MemorySSA, RemoveMemoryAccess) { // We create a diamond where there is a store on one side, and then a load // after the merge point. This enables us to test a bunch of different // removal cases. - std::unique_ptr F(Function::Create( + Function *F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F")); - BasicBlock *Entry(BasicBlock::Create(C, "", F.get())); - BasicBlock *Left(BasicBlock::Create(C, "", F.get())); - BasicBlock *Right(BasicBlock::Create(C, "", F.get())); - BasicBlock *Merge(BasicBlock::Create(C, "", F.get())); + GlobalValue::ExternalLinkage, "F", M.get()); + BasicBlock *Entry(BasicBlock::Create(C, "", F)); + BasicBlock *Left(BasicBlock::Create(C, "", F)); + BasicBlock *Right(BasicBlock::Create(C, "", F)); + BasicBlock *Merge(BasicBlock::Create(C, "", F)); B.SetInsertPoint(Entry); B.CreateCondBr(B.getTrue(), Left, Right); B.SetInsertPoint(Left); @@ -49,10 +50,10 @@ TEST(MemorySSA, RemoveMemoryAccess) { std::unique_ptr MSSA(new MemorySSA(*F)); std::unique_ptr DT(new DominatorTree(*F)); std::unique_ptr AC(new AssumptionCache(*F)); - AAResults *AA = new AAResults(TLI); - BasicAAResult *BAA = new BasicAAResult(DL, TLI, *AC, &*DT); - AA->addAAResult(*BAA); - MemorySSAWalker *Walker = MSSA->buildMemorySSA(AA, &*DT); + AAResults AA; + BasicAAResult BAA(DL, TLI, *AC, &*DT); + AA.addAAResult(BAA); + std::unique_ptr Walker(MSSA->buildMemorySSA(&AA, &*DT)); // Before, the load will be a use of a phi. It should be // the same after. MemoryUse *LoadAccess = cast(MSSA->getMemoryAccess(LoadInst)); -- 2.7.4