llvm / llvm/llvm-project

clang, Floating point exception in distributeIrrLoopHeaderMass in BlockFrequencyInfoImpl.cpp with PGO profile

Open
#212,019 0 comments 0 reactions 0 assignees View on GitHub
crash generated by fuzzer llvm:analysis PGO
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Found by a fuzzer

Reduced C, profdata
[reduced.c](https://github.com/user-attachments/files/30372563/reduced.c)
[reduced.profdata.zip](https://github.com/user-attachments/files/30372568/reduced.profdata.zip)

```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /home/llvm/llvm-latest/build-fast/bin/clang -O2 -w -fprofile-use=/home/llvm/llvm-latest/report-csmith-4719769192585930289/c-reduction/reduced.profdata /home/llvm/llvm-latest/report-csmith-4719769192585930289/c-reduction/reduced.c -c -o /dev/null
1. parser at end of file
2. Optimizer
3. Running pass "pgo-instr-use" on module "/home/llvm/llvm-latest/report-csmith-4719769192585930289/c-reduction/reduced.c"
#0 0x0000649cb5217931 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm/llvm-latest/build-fast/bin/clang+0x3303931)
#1 0x0000649cb521805b PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#2 0x0000649cb521539b llvm::sys::RunSignalHandlers() (/home/llvm/llvm-latest/build-fast/bin/clang+0x330139b)
#3 0x0000649cb5216f93 llvm::sys::CleanupOnSignal(unsigned long) (/home/llvm/llvm-latest/build-fast/bin/clang+0x3302f93)
#4 0x0000649cb513f47c (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
#5 0x0000649cb513f8c5 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#6 0x00007333caa45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#7 0x0000649cb3425d0e llvm::BranchProbability::BranchProbability(unsigned int, unsigned int) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1511d0e)
#8 0x0000649cb3e7f15d (anonymous namespace)::DitheringDistributer::takeMass(unsigned int) BlockFrequencyInfoImpl.cpp:0:0
#9 0x0000649cb3e80e0d llvm::BlockFrequencyInfoImplBase::distributeIrrLoopHeaderMass(llvm::BlockFrequencyInfoImplBase::Distribution&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f6ce0d)
#10 0x0000649cb3e6b70a llvm::BlockFrequencyInfoImpl::computeMassInLoop(llvm::BlockFrequencyInfoImplBase::LoopData&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f5770a)
#11 0x0000649cb3e6bab5 llvm::BlockFrequencyInfoImpl::computeIrreducibleMass(llvm::BlockFrequencyInfoImplBase::LoopData*, std::_List_iterator) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f57ab5)
#12 0x0000649cb3e65a7d llvm::BlockFrequencyInfoImpl::computeMassInFunction() (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f51a7d)
#13 0x0000649cb3e5e589 llvm::BlockFrequencyInfoImpl::calculate(llvm::Function const&, llvm::BranchProbabilityInfo const&, llvm::LoopInfo const&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f4a589)
#14 0x0000649cb3e5e0b0 llvm::BlockFrequencyInfo::calculate(llvm::Function const&, llvm::BranchProbabilityInfo const&, llvm::LoopInfo const&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f4a0b0)
#15 0x0000649cb3e5e03a llvm::BlockFrequencyInfo::BlockFrequencyInfo(llvm::Function const&, llvm::BranchProbabilityInfo const&, llvm::LoopInfo const&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f4a03a)
#16 0x0000649cb789d589 fixFuncEntryCount((anonymous namespace)::PGOUseFunc&, llvm::LoopInfo&, llvm::BranchProbabilityInfo&) PGOInstrumentation.cpp:0:0
#17 0x0000649cb788a446 annotateAllFunctions(llvm::Module&, llvm::StringRef, llvm::StringRef, llvm::vfs::FileSystem&, llvm::function_ref, llvm::function_ref, llvm::function_ref, llvm::function_ref, llvm::ProfileSummaryInfo*, bool) PGOInstrumentation.cpp:0:0
#18 0x0000649cb78892a1 llvm::PGOInstrumentationUse::run(llvm::Module&, llvm::AnalysisManager&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x59752a1)
#19 0x0000649cb6c1b3f0 llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Module&, llvm::AnalysisManager&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x4d073f0)
#20 0x0000649cb4a6d4b1 llvm::detail::PassConcept>::run(llvm::Module&, llvm::AnalysisManager&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x2b594b1)
#21 0x0000649cb4a6d009 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x2b59009)
#22 0x0000649cb55eaace (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#23 0x0000649cb55de21a (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#24 0x0000649cb55dd410 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/home/llvm/llvm-latest/build-fast/bin/clang+0x36c9410)
#25 0x0000649cb61061e4 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x41f21e4)
#26 0x0000649cb8a1a9c4 clang::ParseAST(clang::Sema&, bool, bool) (/home/llvm/llvm-latest/build-fast/bin/clang+0x6b069c4)
#27 0x0000649cb64c4ee3 clang::ASTFrontendAction::ExecuteAction() (/home/llvm/llvm-latest/build-fast/bin/clang+0x45b0ee3)
#28 0x0000649cb610bfa0 clang::CodeGenAction::ExecuteAction() (/home/llvm/llvm-latest/build-fast/bin/clang+0x41f7fa0)
#29 0x0000649cb64c4696 clang::FrontendAction::Execute() (/home/llvm/llvm-latest/build-fast/bin/clang+0x45b0696)
#30 0x0000649cb63e7529 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x44d3529)
#31 0x0000649cb662c6eb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/llvm/llvm-latest/build-fast/bin/clang+0x47186eb)
#32 0x0000649cb33e63cc cc1_main(llvm::ArrayRef, char const*, void*) (/home/llvm/llvm-latest/build-fast/bin/clang+0x14d23cc)
#33 0x0000649cb33dc20c ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#34 0x0000649cb33e4a71 clang_main(int, char**, llvm::ToolContext const&)::$_0::operator()(llvm::SmallVectorImpl&) const driver.cpp:0:0
#35 0x0000649cb33e4a1d int llvm::function_ref&)>::callback_fn(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#36 0x0000649cb61c5b11 llvm::function_ref&)>::operator()(llvm::SmallVectorImpl&) const (/home/llvm/llvm-latest/build-fast/bin/clang+0x42b1b11)
#37 0x0000649cb61c5ad8 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const::$_0::operator()() const Job.cpp:0:0
#38 0x0000649cb61c5aa5 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::$_0>(long) Job.cpp:0:0
#39 0x0000649cb3e36a39 llvm::function_ref::operator()() const (/home/llvm/llvm-latest/build-fast/bin/clang+0x1f22a39)
#40 0x0000649cb513f329 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/home/llvm/llvm-latest/build-fast/bin/clang+0x322b329)
#41 0x0000649cb61c27c0 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (/home/llvm/llvm-latest/build-fast/bin/clang+0x42ae7c0)
#42 0x0000649cb6149bf3 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/llvm/llvm-latest/build-fast/bin/clang+0x4235bf3)
#43 0x0000649cb614a0bc clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/home/llvm/llvm-latest/build-fast/bin/clang+0x42360bc)
#44 0x0000649cb6171d32 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x425dd32)
#45 0x0000649cb33db891 clang_main(int, char**, llvm::ToolContext const&) (/home/llvm/llvm-latest/build-fast/bin/clang+0x14c7891)
#46 0x0000649cb3409859 main (/home/llvm/llvm-latest/build-fast/bin/clang+0x14f5859)
#47 0x00007333caa2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#48 0x00007333caa2a28b call_init ./csu/../csu/libc-start.c:128:20
#49 0x00007333caa2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#50 0x0000649cb33da205 _start (/home/llvm/llvm-latest/build-fast/bin/clang+0x14c6205)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 24.0.0git (https://github.com/llvm/llvm-project.git 9c756612c7a0231ba40982ab2c7f8b6cf8fb895b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/llvm/llvm-latest/build-fast/bin
Build config: +unoptimized
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
clang: note: diagnostic msg: /tmp/reduced-ddc246.c
clang: note: diagnostic msg: /tmp/reduced-ddc246.sh
clang: note: diagnostic msg:

********************
Floating point exception
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with reduced.c, reduced.profdata, and the clang command shown in the report. Start in BlockFrequencyInfoImpl.cpp at DitheringDistributer::takeMass and distributeIrrLoopHeaderMass, then trace the pgo-instr-use path. Done means the reduced profile-guided compilation no longer raises a floating point exception and a regression case covers it.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.