Illegal instruction (core dumped) LLVM 8.0

Hello,
I have implemented a pass to count total number of instructions in LLVM 8.0. Its source code is attached here. The pass runs fine with LLVM 4.0.
But with LLVM 8.0 following error is shown;

$ $LLVMopt_BIN/opt -load $LLVM_SO/LLVMStatic-Info.so -one output-simple.bc
WARNING: You’re attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f’ option.
%2+_Z5UsageiPPc 5 call:1,getelementptr:1,load:2,ret:1,
_Z5UsageiPPc 5 5Stack dump:
0. Program arguments:opt -load /build/lib/LLVMStatic-Info.so -one output-simple.bc

  1. Running pass ‘Function Pass Manager’ on module ‘output-simple.bc’.
  2. Running pass ‘Numbers of Opcodes inside the program’ on function ‘@_Z5UsageiPPc
    #0 0x0000000002636939 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /llvm-8.0.0.src/lib/Support/Unix/Signals.inc:495:11
    #1 0x0000000002636ae9 PrintStackTraceSignalHandler(void*) /llvm-8.0.0.src/lib/Support/Unix/Signals.inc:559:1
    #2 0x0000000002634bd6 llvm::sys::RunSignalHandlers() /llvm-8.0.0.src/lib/Support/Signals.cpp:68:5
    #3 0x000000000263718b SignalHandler(int) /llvm-8.0.0.src/lib/Support/Unix/Signals.inc:358:1
    #4 0x00007f9153c4f890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
    #5 0x00007f91524b40fe (anonymous namespace)::opcodecount::runOnFunction(llvm::Function&) /llvm-8.0.0.src/lib/Transforms/Static-Info/Static-Info.cpp:30:1
    #6 0x0000000001c64464 llvm::FPPassManager::runOnFunction(llvm::Function&) /llvm-8.0.0.src/lib/IR/LegacyPassManager.cpp:1644:23
    #7 0x0000000001c64845 llvm::FPPassManager::runOnModule(llvm::Module&) /llvm-8.0.0.src/lib/IR/LegacyPassManager.cpp:1679:16
    #8 0x0000000001c6507b (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /llvm-8.0.0.src/lib/IR/LegacyPassManager.cpp:1744:23
    #9 0x0000000001c64b1b llvm::legacy::PassManagerImpl::run(llvm::Module&) /llvm-8.0.0.src/lib/IR/LegacyPassManager.cpp:1857:16
    #10 0x0000000001c65651 llvm::legacy::PassManager::run(llvm::Module&) /llvm-8.0.0.src/lib/IR/LegacyPassManager.cpp:1888:3
    #11 0x0000000000b54d93 main /llvm-8.0.0.src/tools/opt/opt.cpp:835:12
    #12 0x00007f91526dbb97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/…/csu/libc-start.c:344:0
    #13 0x0000000000b0a5fa _start (/build/bin/opt+0xb0a5fa)
    Illegal instruction (core dumped)

what is the reason of this error?

Please help.

Static-Info.cpp (1.52 KB)

Hi, Could please attach your IR file? Convert .bc into .ll file and send :slight_smile:

attached

output-simple.ll (22.8 KB)

Hi Hameeza
Yeah, I trying to reproduce the same behaviour with top of the trunk. If I succeeded, I will you let know :slight_smile:

Thanks

Thank You. I am waiting…

Can you try adding a return statement to your run() method? It is returning a value and it is UB to not do so.

Thank You.
I put
return 1;
in the end

for(BasicBlock::iterator it = bb->begin(), end = bb->end();it!=end;++it) {
++op_counter[it->getOpcodeName()]; }
for (std::map<std::string, int>::iterator it = op_counter.begin(), end = op_counter.end(); it != end; ++it) {
errs() << it->first << “:” << it->second << “,”; }
}
globalCount+=instCount;
errs() << “\n”<<func.getName() << “\t” << instCount << “\t” << globalCount;
return 1;
}
Now it is working fine.