<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68539>68539</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crash: Assertion `LHS.getValueType() == VT && RHS.getValueType() == VT && "Cannot use select on differing types"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
clang at -O3 crashes.
Bisected to f82c55fa082711f520a7359393b483956b69bf08, which was committed by @jayfoad
Compiler explorer: https://godbolt.org/z/eexKfTxjn
```console
% cat a.c
unsigned a;
int b, d, h, i, j, l, r;
struct m {
long n;
short o;
int p;
} q;
static int *s = &q.p;
unsigned char t;
int v() {
int c;
if (d) {
if (h) {
c = j;
} else {
if (l)
c = i << b;
}
}
return c;
}
void w(struct m p) {}
static struct m x() {
unsigned k;
struct m m = {};
w(m);
int **u = &s;
int **n[] = {u};
n != 0;
for (; m.o <= 2;) {
int o;
*s = 0;
r = 0 || 8;
for (; t <= 2; t++) {
k = 0;
for (; k <= 2; k++) {
int e[] = {2, 5, 5, 7, 0, 0, 6, 5, 0};
int f;
for (; f < a;) {
int g;
if (e[f])
break;
f += 6;
}
}
m.p = 0;
for (; v() + r + 1 + *s + k - 4 + m.p < 1; m.p = m.p + 1)
for (; o; o++)
;
}
}
return m;
}
int main() { x(); }
%
% clang -w -O3 a.c
clang: /root/llvm-project/llvm/include/llvm/CodeGen/SelectionDAG.h:1237: llvm::SDValue llvm::SelectionDAG::getSelect(const llvm::SDLoc&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue): Assertion `LHS.getValueType() == VT && RHS.getValueType() == VT && "Cannot use select on differing types"' failed.
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-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -w -O3 <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 '@main'
#0 0x00000000037217e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37217e8)
#1 0x000000000371f4ac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x371f4ac)
#2 0x0000000003668058 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f6776ecc420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f677698f00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007f677696e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f677696e729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f677697ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x0000000000dc2e1f llvm::SelectionDAG::getSelect(llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDValue) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdc2e1f)
#9 0x000000000469dee9 (anonymous namespace)::DAGCombiner::visitSELECT(llvm::SDNode*) DAGCombiner.cpp:0:0
#10 0x00000000046f77f8 (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) DAGCombiner.cpp:0:0
#11 0x00000000046f8805 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x00000000046fa06c (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#13 0x00000000046fc64a llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46fc64a)
#14 0x0000000004825a38 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4825a38)
#15 0x00000000048294b8 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48294b8)
#16 0x000000000482b1b2 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#17 0x000000000231874c (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#18 0x0000000002afabd1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#19 0x00000000030a5b19 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30a5b19)
#20 0x00000000030a5d51 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30a5d51)
#21 0x00000000030a6572 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30a6572)
#22 0x0000000003995ed2 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) BackendUtil.cpp:0:0
#23 0x0000000003996379 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>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3996379)
#24 0x000000000498c19f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498c19f)
#25 0x0000000005e89ea9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5e89ea9)
#26 0x000000000498b388 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498b388)
#27 0x00000000041f0b09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41f0b09)
#28 0x0000000004171fde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4171fde)
#29 0x00000000042cfcae clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42cfcae)
#30 0x0000000000bef2d6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbef2d6)
#31 0x0000000000be6b9a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#32 0x0000000003fce1a9 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
#33 0x0000000003668504 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3668504)
#34 0x0000000003fce79f 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
#35 0x0000000003f96965 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f96965)
#36 0x0000000003f973cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f973cd)
#37 0x0000000003f9f2f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f9f2f5)
#38 0x0000000000bec77c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbec77c)
#39 0x0000000000ae6c91 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xae6c91)
#40 0x00007f6776970083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#41 0x0000000000be667e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbe667e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltz27iS_jXwC0oqErw_-IGWrCSzmU0q9knNmwoEQYkxCXAA0Jf99VsASImg5Ng5o5ndqpNKGKkBdH99QzcoYCnrHaP0GkQ3IFpf4V7tubiWe8wX-x4vmvqq4OXLNWkw20Gs4OJLAInAck_lEnhr4OX2eVNLShQtoeKwShGJogp7KUp8v4qQh5MgyoIsKMI0yKK4iLOi8lKAVvBpX5M9fMISEt62tdIsihcIQu8Hfqk4LuFUyoq3Xd1QAelz13BBBQhyuFeqkyDIAdoAtNnxsuCNWnKxA2jzPwBtKH3-r-r--QebcgKxZ_8SziRv6EBFESRYQbwkltAzY58SYhDcWFLNFCw09FI_9vpR68cP_Wj0QxzmSiV6omALQTJQIGw420F2mAKh3HOhID9StITu8BUka_jnhCNWNTFTAMolBMEaAhT_uTwuOGAmeyygcoA_ApQClE3waCqZoKkrCFBaupPg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