<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58552>58552</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crashes on valid code at -Os: Assertion `TrueVal->getType() == FalseVal->getType() && "Select must have same types for true/false ops"' failed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zhendongsu
</td>
</tr>
</table>
<pre>
It affects both trunk and 15.0.0, but not 14.0.0.
Compiler Explorer: https://godbolt.org/z/so4fGeW9T
```
[559] % clangtk -v
clang version 16.0.0 (https://github.com/llvm/llvm-project.git c9447c62966e5ec60ec277e4a7d75420224f53f6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
[560] %
[560] % clangtk -O1 small.c; ./a.out
[561] %
[561] % clangtk -Os small.c
clang-16: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp:4489: llvm::Value* simplifySelectInst(llvm::Value*, llvm::Value*, llvm::Value*, const llvm::SimplifyQuery&, unsigned int): Assertion `TrueVal->getType() == FalseVal->getType() && "Select must have same types for true/false ops"' 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: /local/suz-local/software/local/clang-trunk/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -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 -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20221022-clangtk-m64-Os-Weverything-pipe-fPIC-build-225841/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/16.0.0 -I /usr/local/include/csmith -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20221022-clangtk-m64-Os-Weverything-pipe-fPIC-build-225841/delta -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-b62167.o -x c small.c
1. <eof> parser at end of file
2. Optimizer
#0 0x000055954d049e71 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x000055954d047564 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f06bf614980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#3 0x00007f06be241e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#4 0x00007f06be2437f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
#5 0x00007f06be2333fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
#6 0x00007f06be233472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
#7 0x000055954be6f64c simplifySelectInst(llvm::Value*, llvm::Value*, llvm::Value*, llvm::SimplifyQuery const&, unsigned int) InstructionSimplify.cpp:0:0
#8 0x000055954cac41a5 llvm::InstCombinerImpl::visitSelectInst(llvm::SelectInst&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x39691a5)
#9 0x000055954c9e89fb llvm::InstCombinerImpl::run() (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x388d9fb)
#10 0x000055954c9ea87c combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#11 0x000055954c9eb497 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x3890497)
#12 0x000055954d3f3282 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x4298282)
#13 0x000055954a81455e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x16b955e)
#14 0x000055954c7c0565 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x3665565)
#15 0x000055954a7fad32 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x169fd32)
#16 0x000055954c7be771 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x3663771)
#17 0x000055954d404a70 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) BackendUtil.cpp:0:0
#18 0x000055954d407036 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>>) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x42ac036)
#19 0x000055954e3165d2 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x51bb5d2)
#20 0x000055954efdbaa9 clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x5e80aa9)
#21 0x000055954dbc3271 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x4a68271)
#22 0x000055954db4a43e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x49ef43e)
#23 0x000055954dc8b0d8 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x4b300d8)
#24 0x000055954a4a797d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x134c97d)
#25 0x000055954a4a14d4 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x000055954a4a3fb6 clang_main(int, char**) (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x1348fb6)
#27 0x00007f06be224c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#28 0x000055954a4a06ca _start (/local/suz-local/software/local/clang-trunk/bin/clang-16+0x13456ca)
clang-16: error: unable to execute command: Aborted
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 16.0.0 (https://github.com/llvm/llvm-project.git c9447c62966e5ec60ec277e4a7d75420224f53f6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
clang-16: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-16: note: diagnostic msg: /tmp/small-b7adae.c
clang-16: note: diagnostic msg: /tmp/small-b7adae.sh
clang-16: note: diagnostic msg:
********************
[562] %
[562] % cat small.c
int a, b, c;
static int d = -1;
void f() {
int e;
for (c = 0; c < 3; c++)
if (!a || d > c)
b |= e;
int *g[2] = {&d, &d};
}
int main() {
if (a)
f();
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWtty2zgS_Rr5BUUV75cHPyiynXgrs_bGmqRqX1QgCUqc8LYg6dj5-j0NUDIpy7GTsatmd1yyRIJAX043uhsg4jq9P73sGM8ykXQti-tuyzrZV18Zr1JmeXNzbs7sJYv7jlV1xyyXWuZsZp7NzIX-XtZlkxdCsvO7pqilkDNnwbZd17S4mNkX-GzqNK6Lbl7LDe6-47-t3ey9-BKtxpRmvjl89K33zvOimXfGZrbHkoJXm-4rM271U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