<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94810>94810</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
x86 backend crashes when using `-m32 -mapxf`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
GabrielRavier
</td>
</tr>
</table>
<pre>
The following code:
```cpp
long long xlrandom (long long x, long *random)
{
return x << *random;
}
```
currently makes trunk x86 Clang crash when using `-m32 -mapxf`, with the following error message:
```
fatal error: error in backend: Cannot select: 0xc73fd30: i32 = X86ISD::CMOV 0xc73f160, Constant:i32<0>, TargetConstant:i8<5>, 0xc73fc50, example.cpp:3:14
0xc73f160: i32 = shl 0xc73f1d0, 0xc73f630, example.cpp:3:14
0xc73f1d0: i32,ch = load<(dereferenceable load (s32) from %ir.3, align 8)> 0xc6a31e8, FrameIndex:i32<-1>, undef:i32, example.cpp:3:12
0xc73f390: i32 = FrameIndex<-1>
0xc73f940: i32 = undef
0xc73f630: i8 = and 0xc73f860, Constant:i8<31>, example.cpp:3:14
0xc73f860: i8,ch = load<(load (s8) from %ir.6, align 4)> 0xc6a31e8, 0xc73f400, undef:i32, example.cpp:3:17
0xc73f400: i32,ch = load<(dereferenceable load (s32) from %ir.4)> 0xc6a31e8, FrameIndex:i32<-2>, undef:i32, example.cpp:3:18
0xc73f470: i32 = FrameIndex<-2>
0xc73f940: i32 = undef
0xc73f940: i32 = undef
0xc73f010: i8 = Constant<31>
0xc73f7f0: i32 = Constant<0>
0xc73f9b0: i8 = TargetConstant<5>
0xc73fc50: i32 = X86ISD::CMP 0xc73f2b0, Constant:i8<0>, example.cpp:3:14
0xc73f2b0: i8 = and 0xc73f860, Constant:i8<32>, example.cpp:3:14
0xc73f860: i8,ch = load<(load (s8) from %ir.6, align 4)> 0xc6a31e8, 0xc73f400, undef:i32, example.cpp:3:17
0xc73f400: i32,ch = load<(dereferenceable load (s32) from %ir.4)> 0xc6a31e8, FrameIndex:i32<-2>, undef:i32, example.cpp:3:18
0xc73f470: i32 = FrameIndex<-2>
0xc73f940: i32 = undef
0xc73f940: i32 = undef
0xc73f240: i8 = Constant<32>
0xc73fa20: i8 = Constant<0>
In function: _Z8xlrandomxPl
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: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -m32 -mapxf <source>
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '<source>'.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_Z8xlrandomxPl'
#0 0x000000000376ac58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x376ac58)
#1 0x0000000003768da4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3768da4)
#2 0x00000000036b44f3 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36b44f3)
#3 0x00000000037604be llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x37604be)
#4 0x0000000000c72bc6 (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc72bc6)
#5 0x00000000036be0b3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36be0b3)
#6 0x00000000048da484 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48da484)
#7 0x00000000048e18c5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48e18c5)
#8 0x00000000022d776d (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
#9 0x00000000048d79a4 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48d79a4)
#10 0x00000000048e6d81 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48e6d81)
#11 0x00000000048e99b4 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48e99b4)
#12 0x00000000048eb824 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48eb824)
#13 0x00000000048db2a1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48db2a1)
#14 0x0000000002bde90b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#15 0x000000000310cfa2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x310cfa2)
#16 0x000000000310d121 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x310d121)
#17 0x000000000310edd0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x310edd0)
#18 0x00000000039efe2e clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39efe2e)
#19 0x0000000003ff9b15 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ff9b15)
#20 0x0000000005f02e3c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f02e3c)
#21 0x0000000003ffa395 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ffa395)
#22 0x0000000004296ca1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4296ca1)
#23 0x000000000421c6ab clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x421c6ab)
#24 0x000000000437c8b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x437c8b3)
#25 0x0000000000c7494c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc7494c)
#26 0x0000000000c6ea4d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000000004042db9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#28 0x00000000036b43f3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36b43f3)
#29 0x0000000004042fd9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#30 0x0000000004009577 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4009577)
#31 0x0000000004009f2d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4009f2d)
#32 0x0000000004013f7c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4013f7c)
#33 0x0000000000c71df1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc71df1)
#34 0x0000000000b4e0e4 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb4e0e4)
#35 0x0000727e9f429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x0000727e9f429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000000000c6e4ee _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc6e4ee)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```
Godbolt link that reproduces this issue: https://godbolt.org/z/Yhdfe4aYP
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9z46iy_zTKC-WUhGT9eciDYyfZbM3cSU1yt3bviwtJLZs7CHwBJc799KcAKRaK82fOek-drTM1k7GhaX7d_Gi6CUQpuuEAF8H8Mpivzkint0Je3JBSUmDfySMFeVaK-vniYQuoEYyJJ8o3qBI1BPEiCFdBOPxMQ_e32u1cCxN8g-yPPZOE16JFAc5HrQFeuk8BXjiBABe9tuzSfUAIIQm6kxztURAvg3g5Eo8vB_HVBMUYWtVJCVyzZ9SSH6CQlh3_gfZ5ipaMGGskUVv0tAWOOmXMC9Jw1sYYzVqy2zdGG16iJ6q3SHtuACmFRC0oRTZv-sN9bYgmzA0I4kU_knJUkuoH8Nq0LQnnQiMFDCptGsJ9lcVNH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