[llvm] [FunctionSpecialization] Preserve call counts of specialized functions (PR #157768)

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 20 21:35:35 PDT 2025


alanzhao1 wrote:

> @alanzhao1 this is causing clang crashes when building clang itself. Reduced test case: https://gcc.godbolt.org/z/h5qjdW4c9
> 
> ```
> clang++: /root/llvm-project/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp:799: bool llvm::FunctionSpecializer::run(): Assertion `MaybeCloneCount && "Clone entry count was not set!"' 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++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -xir -O1 <source>
> 1.	Optimizer
> 2.	Running pass "ipsccp" on module "<source>"
>  #0 0x000000000418fc48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418fc48)
>  #1 0x000000000418d074 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418d074)
>  #2 0x00000000040d1708 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
>  #3 0x00007a8c54c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
>  #4 0x00007a8c54c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
>  #5 0x00007a8c54c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
>  #6 0x00007a8c54c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
>  #7 0x00007a8c54c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
>  #8 0x00007a8c54c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
>  #9 0x0000000005b84ce4 llvm::FunctionSpecializer::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5b84ce4)
> #10 0x0000000005b4c96b runIPSCCP(llvm::Module&, llvm::DataLayout const&, llvm::AnalysisManager<llvm::Function>*, std::function<llvm::TargetLibraryInfo const& (llvm::Function&)>, std::function<llvm::TargetTransformInfo& (llvm::Function&)>, std::function<llvm::AssumptionCache& (llvm::Function&)>, std::function<llvm::DominatorTree& (llvm::Function&)>, std::function<llvm::BlockFrequencyInfo& (llvm::Function&)>, bool) SCCP.cpp:0:0
> #11 0x0000000005b4e47d llvm::IPSCCPPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5b4e47d)
> #12 0x000000000535ebae llvm::detail::PassModel<llvm::Module, llvm::IPSCCPPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x535ebae)
> #13 0x0000000003aec3c1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3aec3c1)
> #14 0x0000000004443433 (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
> #15 0x0000000004446f41 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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-assertions-trunk/bin/clang+++0x4446f41)
> #16 0x0000000004acae17 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4acae17)
> #17 0x0000000004db5c95 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4db5c95)
> #18 0x0000000004d31b6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d31b6e)
> #19 0x0000000004eab57d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eab57d)
> #20 0x0000000000db6aa0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb6aa0)
> #21 0x0000000000dad5ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
> #22 0x0000000000dad74d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
> #23 0x0000000004b335c9 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
> #24 0x00000000040d1ba4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40d1ba4)
> #25 0x0000000004b33bdf 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
> #26 0x0000000004af5012 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4af5012)
> #27 0x0000000004af5fbe 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+++0x4af5fbe)
> #28 0x0000000004afd6e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4afd6e5)
> #29 0x0000000000db2fa1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb2fa1)
> #30 0x0000000000c64ce4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc64ce4)
> #31 0x00007a8c54c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
> #32 0x00007a8c54c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
> #33 0x0000000000dad065 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdad065)
> clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
> Compiler returned: 134
> ```

Should be fixed by https://github.com/llvm/llvm-project/commit/7d748a9ceb3716a216a8b586b1d31e046bdee039

https://github.com/llvm/llvm-project/pull/157768


More information about the llvm-commits mailing list