<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54218>54218</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crashes at -Os and above: Assertion `Parent == Other->Parent && "cross-BB instruction order comparison"' failed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zhendongsu
</td>
</tr>
</table>
<pre>
Related to https://github.com/llvm/llvm-project/issues/54195
```
[509] % clangtk -v
clang version 15.0.0 (https://github.com/llvm/llvm-project.git d5d03135a7160586e2b09dc47c7021379252fbbd)
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/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/7.5.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
[510] %
[510] % clangtk -O1 small.c; ./a.out
[511] %
[511] % clangtk -Os small.c
clang-15: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/IR/Instruction.cpp:113: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion `Parent == Other->Parent && "cross-BB instruction order comparison"' 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-15 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model static -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/20220304-clangtk-m64-O3-mllvm-enable-constraint-elimination-build-174437/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/15.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/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../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/20220304-clangtk-m64-O3-mllvm-enable-constraint-elimination-build-174437/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-0fa05a.o -x c small.c
1. <eof> parser at end of file
2. Optimizer
#0 0x0000564eb93f131f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x0000564eb93eeadd SignalHandler(int) Signals.cpp:0:0
#2 0x00007fe418e03980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#3 0x00007fe417ab4e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#4 0x00007fe417ab67f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
#5 0x00007fe417aa63fa __assert_fail_base /build/glibc-uZu3wS/glibc-2.27/assert/assert.c:89:0
#6 0x00007fe417aa6472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
#7 0x0000564eb8ac98ac (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x31b88ac)
#8 0x0000564eb84ab70a llvm::RecurrenceDescriptor::isFirstOrderRecurrence(llvm::PHINode*, llvm::Loop*, llvm::MapVector<llvm::Instruction*, llvm::Instruction*, llvm::DenseMap<llvm::Instruction*, unsigned int, llvm::DenseMapInfo<llvm::Instruction*, void>, llvm::detail::DenseMapPair<llvm::Instruction*, unsigned int> >, std::vector<std::pair<llvm::Instruction*, llvm::Instruction*>, std::allocator<std::pair<llvm::Instruction*, llvm::Instruction*> > > >&, llvm::DominatorTree*) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x2b9a70a)
#9 0x0000564eb96c5d92 llvm::LoopVectorizationLegality::canVectorizeInstrs() (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3db4d92)
#10 0x0000564eb96c7466 llvm::LoopVectorizationLegality::canVectorize(bool) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3db6466)
#11 0x0000564eb9622813 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3d11813)
#12 0x0000564eb9625871 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo&, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AAResults&, llvm::AssumptionCache&, std::function<llvm::LoopAccessInfo const& (llvm::Loop&)>&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3d14871)
#13 0x0000564eb9625e09 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3d14e09)
#14 0x0000564eba6186f1 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x4d076f1)
#15 0x0000564eb8b571ec llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x32461ec)
#16 0x0000564eb6ff4061 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-15+0x16e3061)
#17 0x0000564eb8b56c0a llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x3245c0a)
#18 0x0000564eb6ff49c1 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-15+0x16e39c1)
#19 0x0000564eb8b553c4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x32443c4)
#20 0x0000564eb972e030 (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> >&) (.constprop.836) BackendUtil.cpp:0:0
#21 0x0000564eb9731002 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-15+0x3e20002)
#22 0x0000564eba43d67b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x4b2c67b)
#23 0x0000564ebb348df9 clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x5a37df9)
#24 0x0000564eba43c178 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x4b2b178)
#25 0x0000564eb9dd3c91 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x44c2c91)
#26 0x0000564eb9d6e23a clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x445d23a)
#27 0x0000564eb9ea1ae3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x4590ae3)
#28 0x0000564eb6d31d01 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x1420d01)
#29 0x0000564eb6d2db99 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x0000564eb6c53e79 main (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x1342e79)
#31 0x00007fe417a97c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#32 0x0000564eb6d2d70a _start (/local/suz-local/software/local/clang-trunk/bin/clang-15+0x141c70a)
clang-15: error: unable to execute command: Aborted
clang-15: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project.git d5d03135a7160586e2b09dc47c7021379252fbbd)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
clang-15: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/small-c9f9f4.c
clang-15: note: diagnostic msg: /tmp/small-c9f9f4.sh
clang-15: note: diagnostic msg:
********************
[512] %
[512] % cat small.c
short a, c, e, *g;
int *b, d;
char f;
void h() {
e = c ? a / c : 0;
*b = d;
}
int main () {
while (b) {
while (1) {
*b && (f = 0);
h();
break;
}
*g = f--;
}
return 0;
}
```
@fhahn
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztW1lv4zgS_jXJCyFD9_GQB8eJOwHSmyDJzAD7YlAUZWsiS1pSSjv967eKkmxRcY7uthezO9twfJDFqq8OFosiOy6Tl7N7ntOaJ6QuyaquK3niTE_sObyWWb1q4gkr1_Ajz5_7D6MS5Z-c1fAzk7LhEr54rhV5J-bFiTnt3n2ze7U_vXPPjE68C3Jie4TltFjWT8R4bnvVb_LMhczKgljexJyYQBj-GJ4JEJDES0zHcjwaWL7phT63YzNKmBuwwLQtJ4hsz07jODmxo1b2IxVLXoMQsgn9he8aTfFUlN8KI8-KZmMsi6ajWwlOE7IuE54jdVXKbNN2XReypnnOk4tMYBfiKhnN4VM2343-e1mlzffv8CXOinbgvGyKhDBaJFkCPiBfZjOStcxoDabomDVSIMssRiMwhnb3Q38A0J6Hv8iw033I0j8Cywm49vBsgyOwPA7Szk0PPId4hTl3IIizLbh1k9cZDgRGkxPn_MQ11777HpVjd2Tw5R2yzZZu0xNutXhPKE58y-wn_r62bTK4tYhcgyUmDHgAI3tOJ2VTD8ZYe_hYr_nILZ9ddjEs752pKcu0_kYFh6-KOm6yPHmd7vqkoxxzfY9v4DzRMPTdhFUViLAsBwXFZZkTRQ_py5kO6NoGyGJcnvO0RKEhK6H_DXIb0l9EFAUynkrJBXYQSK53gLmoyYlzAS9yW6-4ME6cy77Z9uEFHzYTpZTG-bkKto4xKUXCBTBeV1RkEiXZJ3ZAUppBKpu0tru7uZw-X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