Guys,<div><br></div><div>In this case, I wanted to hack globalopt pass to require ScalarEvolution analysis. It seems ScalarEvolution is not released after globalopt pass, and it will hold a reference to the basicblocks. Later when the function is removed(by inline pass), coredump happened:</div>
<div>opt test.bc -mem2reg -globalopt -inline -loop-unroll -debug-pass Details -o out.bc >& log</div><div><br></div><div>So it seems to me if a pass wanted to require ScalarEvolution, ScalarEvolution::releaseMemory should be called every time after the pass is called. Is that right?</div>
<div><br></div><div>Steps to reproduce(In case some of you do not have clang installed, test.bc attached):</div><div>1. The makefile:</div><div><div>all:</div><div>        clang test.c -disable-llvm-optzns -emit-llvm -S</div>
<div>        llvm-as test.s -o test.bc</div><div>        opt test.bc -mem2reg -globalopt -inline -loop-unroll -debug-pass Details -o out.bc >& log</div><div>        llvm-dis < out.bc > out.ll</div></div><div>
2. test.c:</div><div><div>#include <stdio.h></div><div><br></div><div>int A[100];</div><div>static int toBeInlined(int A[100]) {</div><div>    int ans = 0;</div><div>    for (int i=0; i<100; ++i)</div><div>        ans+=A[i];</div>
<div>    return ans;</div><div>}</div><div><br></div><div>int main() {</div><div>    for (int i=0; i<100; ++i)</div><div>        if (i%3==0)</div><div>            A[i] = i;</div><div>        else</div><div>            A[i] = i+1;</div>
<div>    int ans = toBeInlined(A);</div><div>    printf("%d\n", ans);</div><div>    return 0;</div><div>}</div></div><div><br></div><div>3. Hack to globalopt pass:</div><div><div> #include <algorithm></div>
<div> using namespace llvm;</div><div><br></div><div>@@ -63,6 +65,7 @@</div><div>   struct GlobalOpt : public ModulePass {</div><div>     virtual void getAnalysisUsage(AnalysisUsage &AU) const {</div><div>       AU.addRequired<TargetLibraryInfo>();</div>
<div>+      AU.addRequired<ScalarEvolution>();</div><div>     }</div><div>     static char ID; // Pass identification, replacement for typeid</div><div>     GlobalOpt() : ModulePass(ID) {</div><div>@@ -92,6 +95,7 @@</div>
<div> INITIALIZE_PASS_BEGIN(GlobalOpt, "globalopt",</div><div>                 "Global Variable Optimizer", false, false)</div><div> INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)</div><div>+INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)</div>
<div> INITIALIZE_PASS_END(GlobalOpt, "globalopt",</div><div>                 "Global Variable Optimizer", false, false)</div><div><br></div><div>@@ -2084,6 +2088,14 @@</div><div>   for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {</div>
<div>     Function *F = FI++;</div><div>     // Functions without names cannot be referenced outside this module.</div><div>+    if (!F->isDeclaration()) {</div><div>+      ScalarEvolution *SE = &getAnalysis<ScalarEvolution>(*F);</div>
<div>+      for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {</div><div>+        Instruction *I = &*i;</div><div>+        if (I->getType()->isIntegerTy() || I->getType()->isPointerTy())</div>
<div>+          const SCEV* SS = SE->getSCEV(I);</div><div>+      }</div><div>+    }</div><div>     if (!F->hasName() && !F->isDeclaration())</div><div>       F->setLinkage(GlobalValue::InternalLinkage);</div>
<div>     F->removeDeadConstantUsers();</div></div><div><br></div><div>4. The coredump:</div><div><div>(gdb) bt</div><div>#0  0x000000386de30265 in raise () from /lib64/libc.so.6</div><div>#1  0x000000386de31d10 in abort () from /lib64/libc.so.6</div>
<div>#2  0x0000000000aa93e6 in llvm::llvm_unreachable_internal (</div><div>    msg=0xcce748 "An asserting value handle still pointed to this value!",</div><div>    file=0xccde18 "/home/xchen/llvm/lib/VMCore/Value.cpp", line=620)</div>
<div>    at /home/xchen/llvm/lib/Support/ErrorHandling.cpp:98</div><div>#3  0x0000000000a6d369 in llvm::ValueHandleBase::ValueIsDeleted (V=0x10f7050)</div><div>    at /home/xchen/llvm/lib/VMCore/Value.cpp:619</div><div>#4  0x0000000000a6e631 in llvm::Value::~Value (this=0x10f7050, __in_chrg=<value optimized out>)</div>
<div>    at /home/xchen/llvm/lib/VMCore/Value.cpp:59</div><div>#5  0x00000000009401fd in llvm::BasicBlock::~BasicBlock (this=0x10f7050, __in_chrg=<value optimized out>)</div><div>    at /home/xchen/llvm/lib/VMCore/BasicBlock.cpp:83</div>
<div>#6  0x000000000068503d in llvm::ilist_node_traits<llvm::BasicBlock>::deleteNode (V=0x10f7050)</div><div>    at /home/xchen/llvm/include/llvm/ADT/ilist.h:112</div><div>#7  0x0000000000686ed3 in llvm::iplist<llvm::BasicBlock, llvm::ilist_traits<llvm::BasicBlock> >::erase (</div>
<div>    this=0x10f3f68, where=...) at /home/xchen/llvm/include/llvm/ADT/ilist.h:463</div><div>#8  0x00000000009400a6 in llvm::BasicBlock::eraseFromParent (this=0x10f7050)</div><div>    at /home/xchen/llvm/lib/VMCore/BasicBlock.cpp:101</div>
<div>#9  0x0000000000a155a7 in llvm::Function::dropAllReferences (this=0x10f3f10)</div><div>    at /home/xchen/llvm/lib/VMCore/Function.cpp:242</div><div>#10 0x0000000000a15701 in llvm::Function::~Function (this=0x10f3f10, __in_chrg=<value optimized out>)</div>
<div>    at /home/xchen/llvm/lib/VMCore/Function.cpp:188</div><div>#11 0x0000000000598107 in llvm::Inliner::runOnSCC (this=0x10e9780, SCC=...)</div><div>    at /home/xchen/llvm/lib/Transforms/IPO/Inliner.cpp:487</div><div>
#12 0x000000000079a828 in (anonymous namespace)::CGPassManager::RunPassOnSCC (this=0x10e9f80, P=0x10e9780,</div><div>    CurSCC=..., CG=..., CallGraphUpToDate=@0x7fffffffd0af, DevirtualizedCall=@0x7fffffffd1f7)</div><div>
    at /home/xchen/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:121</div><div>#13 0x000000000079ac71 in (anonymous namespace)::CGPassManager::RunAllPassesOnSCC (this=0x10e9f80,</div><div>    CurSCC=..., CG=..., DevirtualizedCall=@0x7fffffffd1f7)</div>
<div>    at /home/xchen/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:402</div><div>#14 0x000000000079b046 in (anonymous namespace)::CGPassManager::runOnModule (this=0x10e9f80, M=...)</div><div>    at /home/xchen/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:457</div>
<div>#15 0x0000000000a50d49 in llvm::MPPassManager::runOnModule (this=0x10f4100, M=...)</div><div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1572</div><div>---Type <return> to continue, or q <return> to quit---</div>
<div>#16 0x0000000000a521b9 in llvm::PassManagerImpl::run (this=0x10f4460, M=...)</div><div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1655</div><div>#17 0x0000000000a5221b in llvm::PassManager::run (this=0x7fffffffd4b0, M=...)</div>
<div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1684</div><div>#18 0x0000000000541e77 in main (argc=10, argv=0x7fffffffd718) at /home/xchen/llvm/tools/opt/opt.cpp:745</div></div><div><br></div><div><br></div>