Error-Running pass 'Function Pass Manager' on module

Hi, everyone,
I use opt to optimize some .bc files, but in some cases, when I use a costume passes sequence, I get the following error

  1. Running pass ‘Function Pass Manager’ on module ‘xx.bc’.
  2. Running pass ‘Value Propagation’ on function ‘@yy
    Segmentation fault (core dumped)

What are the reasons of this error? From the output text, I know that opt runs pass ‘Function Pass Manager’ on module, which is not correct, but I cannot find the reason.
Or there are some cautions that I need to know when I define the passes sequence by myself?

For some cases, the following error also occurs

  1. Running pass ‘Interprocedural Sparse Conditional Constant Propagation’ on module ‘a.bc’.
    Segmentation fault (core dumped)

In most case, opt reports
1 Running pass ‘Function Pass Manager’ on module ‘xx.bc’,
2 Running pass ‘mmm’ on function ‘@yy
Segmentation fault (core dumped)

Have you tried building in Debug mode and reading asserts? What does the assert say?

Zhang

Hi, Zhang
Thanks for your suggestions!
Previously, I use the pre-built binaries of llvm 6.0 downloaded from llvm website. So, I also built the source code of llvm 6.0 in debug mode for further test on a ubuntu 18.04 system.
The output of one passes sequence is as followings.

While deleting: i32* %
Use still stuck around after Def is destroyed: %441 = load i32, i32* , align 4, !tbaa !11
opt: /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/Value.cpp:88: llvm::Value::~Value(): Assertion `use_empty() && “Uses remain when a value is destroyed!”’ failed.
#0 0x000055c84d2d5be9 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Support/Unix/Signals.inc:398:0
#1 0x000055c84d2d5c7c PrintStackTraceSignalHandler(void*) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Support/Unix/Signals.inc:462:0
#2 0x000055c84d2d3e51 llvm::sys::RunSignalHandlers() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Support/Signals.cpp:49:0
#3 0x000055c84d2d5455 SignalHandler(int) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Support/Unix/Signals.inc:252:0
#4 0x00007f5dfaca4890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#5 0x00007f5df9956e97 gsignal /build/glibc-OTsEL5/glibc-2.27/signal/…/sysdeps/unix/sysv/linux/raise.c:51:0
#6 0x00007f5df9958801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
#7 0x00007f5df994839a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
#8 0x00007f5df9948412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
#9 0x000055c84cb72252 llvm::Value::~Value() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/Value.cpp:88:0
#10 0x000055c84c371e04 llvm::User::~User() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/IR/User.h:95:0
#11 0x000055c84cab5ac2 llvm::Instruction::~Instruction() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/Instruction.cpp:48:0
#12 0x000055c84cb76e3c llvm::UnaryInstruction::~UnaryInstruction() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/IR/InstrTypes.h:279:0
#13 0x000055c84cb76e58 llvm::LoadInst::~LoadInst() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/IR/Instructions.h:164:0
#14 0x000055c84cb72aeb llvm::Value::deleteValue() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/IR/Instruction.def:153:0
#15 0x000055c84b268c78 llvm::ilist_alloc_traitsllvm::Instruction::deleteNode(llvm::Instruction*) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/IR/Instruction.h:690:0
#16 0x000055c84b26a289 llvm::iplist_impl<llvm::simple_ilistllvm::Instruction, llvm::SymbolTableListTraitsllvm::Instruction >::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/ADT/ilist.h:282:0
#17 0x000055c84c9b1eaa llvm::iplist_impl<llvm::simple_ilistllvm::Instruction, llvm::SymbolTableListTraitsllvm::Instruction >::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/ADT/ilist.h:318:0
#18 0x000055c84c9b183d llvm::iplist_impl<llvm::simple_ilistllvm::Instruction, llvm::SymbolTableListTraitsllvm::Instruction >::clear() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/ADT/ilist.h:322:0
#19 0x000055c84c9afb08 llvm::BasicBlock::~BasicBlock() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/BasicBlock.cpp:64:0
#20 0x000055c84c9b1f58 llvm::ilist_alloc_traitsllvm::BasicBlock::deleteNode(llvm::BasicBlock*) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/ADT/ilist.h:42:0
#21 0x000055c84c9b1a87 llvm::iplist_impl<llvm::simple_ilistllvm::BasicBlock, llvm::SymbolTableListTraitsllvm::BasicBlock >::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void>, false, false>) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/include/llvm/ADT/ilist.h:282:0
#22 0x000055c84c9afc0f llvm::BasicBlock::eraseFromParent() /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/BasicBlock.cpp:99:0
#23 0x000055c84d37838e llvm::deleteDeadLoop(llvm::Loop*, llvm::DominatorTree*, llvm::ScalarEvolution*, llvm::LoopInfo*) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Transforms/Utils/LoopUtils.cpp:1441:0
#24 0x000055c84d018a44 deleteLoopIfDead(llvm::Loop*, llvm::DominatorTree&, llvm::ScalarEvolution&, llvm::LoopInfo&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Transforms/Scalar/LoopDeletion.cpp:167:0
#25 0x000055c84d019107 (anonymous namespace)::LoopDeletionLegacyPass::runOnLoop(llvm::Loop*, llvm::LPPassManager&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Transforms/Scalar/LoopDeletion.cpp:261:0
#26 0x000055c84c32e9fc llvm::LPPassManager::runOnFunction(llvm::Function&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/Analysis/LoopPass.cpp:202:0
#27 0x000055c84caf631c llvm::FPPassManager::runOnFunction(llvm::Function&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/LegacyPassManager.cpp:1520:0
#28 0x000055c84caf64c1 llvm::FPPassManager::runOnModule(llvm::Module&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/LegacyPassManager.cpp:1541:0
#29 0x000055c84caf6849 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/LegacyPassManager.cpp:1597:0
#30 0x000055c84caf6f73 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/LegacyPassManager.cpp:1700:0
#31 0x000055c84caf716b llvm::legacy::PassManager::run(llvm::Module&) /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/lib/IR/LegacyPassManager.cpp:1732:0
#32 0x000055c84af946f3 main /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/tools/opt/opt.cpp:765:0
#33 0x00007f5df9939b97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/…/csu/libc-start.c:344:0
#34 0x000055c84af63e5a _start (/home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/build/bin/opt+0x1369e5a)
Stack dump:
0. Program arguments: /home/jack-zhou/Documents/llvm/llvm6.0/llvm-6.0.0.src/build/bin/opt -strip-dead-prototypes -loop-vectorize -lcssa -loop-unroll -mem2reg -early-cse-memssa -globalopt -elim-avail-extern -instsimplify -argpromotion -correlated-propagation -simplifycfg -gvn -functionattrs -early-cse -argpromotion -memcpyopt -slp-vectorizer -functionattrs -licm -strip-dead-prototypes -gvn -speculative-execution -inline -speculative-execution -loop-simplify -lcssa-verification -libcalls-shrinkwrap -memcpyopt -float2int -sroa -loop-simplify -loop-rotate -memcpyopt -loop-sink -mldst-motion -adce -alignment-from-assumptions -tailcallelim -loop-unroll -loop-unswitch -forceattrs -ee-instrument -indvars -inline -inferattrs -sroa -callsite-splitting -forceattrs -loop-idiom -argpromotion -called-value-propagation -slp-vectorizer -loop-idiom -mem2reg -prune-eh -tailcallelim -adce -prune-eh -lower-expect -loop-simplify -adce -reassociate -functionattrs -callsite-splitting -lower-expect -strip-dead-prototypes -loop-load-elim -deadargelim -globaldce -float2int -loop-unroll -rpo-functionattrs -memcpyopt -dse -slp-vectorizer -loop-vectorize -globalopt -loop-unswitch -slp-vectorizer -lcssa -loop-simplify -loop-unswitch -inline -called-value-propagation -correlated-propagation -demanded-bits -early-cse -inline -slp-vectorizer -instsimplify -loop-load-elim -alignment-from-assumptions -float2int -speculative-execution -licm -called-value-propagation -demanded-bits -callsite-splitting -early-cse-memssa -called-value-propagation -tailcallelim -dse -loop-distribute -loop-unswitch -adce -mem2reg -loop-load-elim -loop-sink -rpo-functionattrs -ee-instrument -loop-deletion -forceattrs -dse -loop-vectorize -div-rem-pairs -loop-vectorize -lcssa-verification -lower-expect -early-cse-memssa -speculative-execution -alignment-from-assumptions -instsimplify -strip-dead-prototypes -rpo-functionattrs -functionattrs -constmerge -demanded-bits -correlated-propagation -early-cse-memssa -loop-unroll -slp-vectorizer -lcssa -loop-vectorize -float2int -rpo-functionattrs -pgo-memop-opt -loop-distribute -mldst-motion -tailcallelim -loop-unswitch -loop-simplify -constmerge -loop-sink -instcombine -globalopt -adce -reassociate -div-rem-pairs -gvn -strip-dead-prototypes -callsite-splitting -functionattrs -lower-expect -loop-vectorize -prune-eh -loop-rotate -jump-threading -adce -loop-simplify -loop-rotate -licm -inferattrs -jump-threading -constmerge -memcpyopt -loop-deletion -inline -early-cse-memssa -loop-idiom -inferattrs -loop-simplify -loop-unswitch -lower-expect -tailcallelim -loop-deletion -called-value-propagation -mem2reg -loop-load-elim -lcssa -loop-unswitch -called-value-propagation -pgo-memop-opt -forceattrs -dse -early-cse-memssa -loop-unswitch -memcpyopt -loop-sink -loop-load-elim -speculative-execution -loop-simplify -simplifycfg -instsimplify -loop-unroll -lower-expect -rpo-functionattrs -gvn -licm -loop-distribute a.bc -o a-opt1.bc

  1. Running pass ‘Function Pass Manager’ on module ‘a.bc’.
  2. Running pass ‘Loop Pass Manager’ on function ‘@put2bitcmaptile
  3. Running pass ‘Delete dead loops’ on basic block ‘’
    Aborted (core dumped)

For another passes sequence, the output is different for the same program.

  1. Running pass ‘CallGraph Pass Manager’ on module ‘a.bc’.
  2. Running pass ‘Loop Pass Manager’ on function ‘@put1bitcmaptile
  3. Running pass ‘Delete dead loops’ on basic block ‘’
    Aborted (core dumped)

From these outputs, the reasons for this error is that the opt tool tried to delete something, i.e.,

“While deleting: i32* %
Use still stuck around after Def is destroyed: %441 = load i32, i32* , align 4, !tbaa !11”

And I find that the output of the pre-built opt is different from the output of the opt built by myself for the same passes sequence.

In most case, the custom passes sequences work fine for this program. So, are there some principles for designing the passes sequence?

Best!
Zhide

prebuilt opt errors.txt (37.6 KB)