Issue 98133
Summary Random assertion failure `!isa<PHINode>(this) && "Inserting PHI after debug-records!"' when compiling a file
Labels new issue
Assignees
Reporter dyung
    We have an internal test that started hitting an assertion failure recently which I was able to bisect back to 385118644cca. What is odd about this crash though is that it seems to not happen reliably which is odd.

Consider the following code:
```c++
void foo(float *dest) {
  unsigned int i;
  float s0 = 0;
  float s1 = 0;
  float acc1 = 0;
  for (i = 0; i < 32; i++) {
    dest[0] = acc1;
    acc1 = s0 * 0 + s1 * 0;
    s0 = acc1 < 1 ? 1 : acc1;
    s1 = s1 < 1 ? 1 : s1;
  }
}
```

If compiled with the options `-O2 -g -mavx` repeatedly using a compiler that includes 385118644cca, it should eventually hit the following assertion failure:
```
$ ~/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang -c -O2 -g test.cpp -o test.o -mavx
clang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/IR/Instruction.cpp:153: void llvm::Instruction::insertBefore(llvm::BasicBlock&, llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction, llvm::ilist_iterator_bits<true>, llvm::ilist_parent<llvm::BasicBlock> >, llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true>, llvm::ilist_parent<llvm::BasicBlock> > >::iterator): Assertion `!isa<PHINode>(this) && "Inserting PHI after debug-records!"' 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: /home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang -c -O2 -g test.cpp -o test.o -mavx
1.      <eof> parser at end of file
2.      Optimizer
3.      Running pass "function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>)" on module "test.cpp"
4.      Running pass "slp-vectorizer" on function "_Z3fooPf"
 #0 0x000055aff4e7801f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x419001f)
 #1 0x000055aff4e75b7c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x418db7c)
 #2 0x000055aff4dbb068 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f8819c12420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f88196df00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f88196be859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f88196be729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f88196be729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f88196cffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055aff477d1b7 (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x3a951b7)
#10 0x000055aff674d604 llvm::slpvectorizer::BoUpSLP::~BoUpSLP() (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x5a65604)
#11 0x000055aff67f4021 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#12 0x000055aff67f4863 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x5b0c863)
#13 0x000055aff62cb276 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x55e3276)
#14 0x000055aff48207b1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x3b387b1)
#15 0x000055aff23ed256 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x1705256)
#16 0x000055aff481f17d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x3b3717d)
#17 0x000055aff23ee166 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x1706166)
#18 0x000055aff481d2c1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x3b352c1)
#19 0x000055aff512c538 (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>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#20 0x000055aff512f8b5 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#21 0x000055aff512ff56 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*) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4447f56)
#22 0x000055aff57a429c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4abc29c)
#23 0x000055aff75863fc clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x689e3fc)
#24 0x000055aff57a46a8 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4abc6a8)
#25 0x000055aff5a38139 clang::FrontendAction::Execute() (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4d50139)
#26 0x000055aff59bb7ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4cd37ee)
#27 0x000055aff5b23626 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4e3b626)
#28 0x000055aff1fd4c2f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x12ecc2f)
#29 0x000055aff1fcdcda ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#30 0x000055aff57e996d 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
#31 0x000055aff4dbb570 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x40d3570)
#32 0x000055aff57e9f8f 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
#33 0x000055aff57ae3ec clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4ac63ec)
#34 0x000055aff57aee7d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4ac6e7d)
#35 0x000055aff57b6f55 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x4acef55)
#36 0x000055aff1fd1f3b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x12e9f3b)
#37 0x000055aff1ec4d7b main (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x11dcd7b)
#38 0x00007f88196c0083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#39 0x000055aff1fcd76e _start (/home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin/clang+0x12e576e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0 (https://github.com/llvm/llvm-project.git 385118644ccabe27a634804c7db60734746c170f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dyung/src/upstream/385118644ccabe27a634804c7db60734746c170f-linux/bin
Build config: +assertions
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to