Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang crashes on a invalid Phi Instruction #55763

Closed
WAAutoMaton opened this issue May 29, 2022 · 3 comments
Closed

Clang crashes on a invalid Phi Instruction #55763

WAAutoMaton opened this issue May 29, 2022 · 3 comments
Labels
llvm:codegen question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@WAAutoMaton
Copy link

WAAutoMaton commented May 29, 2022

This is a problematic LLVM IR. label3 is not the direct predecessor of the PHI node.

define i32 @f() local_unnamed_addr #0 {
    label0:
  br  i1 1, label %label2, label %label3

label2:                                                ; preds = %label0
  br label %label4

label3:                                                ; preds = %label0
  br  label %label5

label4:                                                ;
  %op5 = phi i32 [ 3, %label2 ], [ 4, %label3 ]
  ret i32 %op5

label5:                                                ; preds = %label3
  br label %label4
}

llc gives an error correctly.

# llc test.ll
PHI node entries do not match predecessors!
  %op5 = phi i32 [ 3, %label2 ], [ 4, %label3 ]
label %label3
label %label5
llc: error: 'test.ll': input module cannot be verified

However, when I use clang to compilt it, clang crashed.

# clang test.ll -v
Debian clang version 15.0.0-++20220507071904+83e07916ffc5-1~exp1~20220507072002.243
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/lib/llvm-15/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/root/a -resource-dir /usr/lib/llvm-15/lib/clang/15.0.0 -fdebug-compilation-dir=/root/a -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-2dba98.o -x ir test.ll
clang -cc1 version 15.0.0 based upon LLVM 15.0.0 default target x86_64-pc-linux-gnu
warning: overriding the module target triple with x86_64-pc-linux-gnu [-Woverride-module]
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/lib/llvm-15/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/root/a -resource-dir /usr/lib/llvm-15/lib/clang/15.0.0 -fdebug-compilation-dir=/root/a -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-2dba98.o -x ir test.ll
1.      Code generation
2.      Running pass 'Function Pass Manager' on module 'test.ll'.
3.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@f'
 #0 0x00007fb5fea6d291 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0xeae291)
 #1 0x00007fb5fea6afde llvm::sys::RunSignalHandlers() (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0xeabfde)
 #2 0x00007fb5fea6d7bb (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0xeae7bb)
 #3 0x00007fb6080a6140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
 #4 0x00007fb5ff146200 llvm::FastISel::handlePHINodesInSuccessorBlocks(llvm::BasicBlock const*) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x1587200)
 #5 0x00007fb5ff1458e9 llvm::FastISel::selectInstruction(llvm::Instruction const*) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x15868e9)
 #6 0x00007fb5ff2a60db llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x16e70db)
 #7 0x00007fb5ff2a4353 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x16e5353)
 #8 0x00007fb601320e4d (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x3761e4d)
 #9 0x00007fb5fee086dd llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x12496dd)
#10 0x00007fb5febbba8f llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0xffca8f)
#11 0x00007fb5febc2ff3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0x1003ff3)
#12 0x00007fb5febbc626 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/llvm-15/bin/../lib/libLLVM-15.so.1+0xffd626)
#13 0x00007fb605fe1c13 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/lib/llvm-15/bin/../lib/libclang-cpp.so.15+0x18fac13)
#14 0x00007fb606328292 clang::CodeGenAction::ExecuteAction() (/usr/lib/llvm-15/bin/../lib/libclang-cpp.so.15+0x1c41292)
#15 0x00007fb606d337e7 clang::FrontendAction::Execute() (/usr/lib/llvm-15/bin/../lib/libclang-cpp.so.15+0x264c7e7)
#16 0x00007fb606caa346 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-15/bin/../lib/libclang-cpp.so.15+0x25c3346)
#17 0x00007fb606dafdaa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-15/bin/../lib/libclang-cpp.so.15+0x26c8daa)
#18 0x0000560e9db3c1b7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-15/bin/clang+0x141b7)
#19 0x0000560e9db3a4bb (/usr/lib/llvm-15/bin/clang+0x124bb)
#20 0x0000560e9db3a304 main (/usr/lib/llvm-15/bin/clang+0x12304)
#21 0x00007fb5fd6f3d0a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26d0a)
#22 0x0000560e9db36f5a _start (/usr/lib/llvm-15/bin/clang+0xef5a)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Debian clang version 15.0.0-++20220507071904+83e07916ffc5-1~exp1~20220507072002.243
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
@fhahn
Copy link
Contributor

fhahn commented May 29, 2022

I think this is kind-of working as expected. Clang doesn't verify the IR. IIRC there were similar issues in the past and this wasn't something we changed. I don't have any references handy though.

@WAAutoMaton
Copy link
Author

Thanks!

@EugeneZelenko EugeneZelenko added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! llvm:codegen and removed new issue labels May 30, 2022
@fhahn
Copy link
Contributor

fhahn commented Jun 2, 2022

There's been another similar issue, so I went ahead and started a thread on Clang verifying IR modules by default: https://discourse.llvm.org/t/should-clang-verify-ir-when-passing-a-llvm-ir-file/62926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:codegen question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

3 participants