-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Description
Summary
Clang crashes with an assertion failure when building LLVM's Polly component in a self-hosted build configuration. The crash occurs during the Control Flow Optimizer pass in the BranchFolder's HoistCommonCodeInSuccs function.
Bug Classification
Compiler crash bug - Backend code generator crash
Assertion Details
Assertion failed: (isDebugValue() && "Must be a debug value instruction."), function setDebugValueUndef, file MachineInstr.h, line 2004.
Stack Trace
Stack dump:
0. Program arguments: clang [compiler flags]
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'polly/lib/External/isl/isl_transitive_closure.c'.
4. Running pass 'Control Flow Optimizer' on function '@has_spurious_elements'
#8 (anonymous namespace)::BranchRelaxation::run(llvm::MachineFunction&) (.cold.9)
#9 llvm::MachineInstr::setDebugValueUndef()
#10 llvm::BranchFolder::HoistCommonCodeInSuccs(llvm::MachineBasicBlock*)::::operator()
#11 llvm::BranchFolder::HoistCommonCodeInSuccs(llvm::MachineBasicBlock*)
#12 llvm::BranchFolder::OptimizeFunction(...)
Reproduction Steps
- Configure LLVM build with self-hosted clang
- Run
ninjain build directory - Crash occurs when compiling
polly/lib/External/isl/isl_transitive_closure.c - Also reproduces with
polly/lib/External/isl/isl_scheduler.c
Build Configuration
- Host System: macOS (Darwin 24.5.0, arm64)
- Compiler: clang version 22.0.0git
- Target: arm64-apple-darwin24.5.0
- Build Type: Self-hosted build (clang building LLVM)
- Optimization:
-O2 -g -DNDEBUG - Assertions: Enabled (
+assertions)
Analysis
The assertion failure occurs when setDebugValueUndef() is called on a MachineInstr that fails the isDebugValue() check. This suggests that:
- The BranchFolder optimization is incorrectly identifying a non-debug instruction as a debug instruction
- There may be corruption in the debug metadata during the optimization pass
- The debug instruction handling in
HoistCommonCodeInSuccshas a logic error
This appears related to recent changes in debug instruction handling during branch folding, as there were recent reverts of patches modifying this code (commits 654c0d8 and 8d4fde5).
Affected Files
- Files that trigger the crash:
polly/lib/External/isl/isl_transitive_closure.c,polly/lib/External/isl/isl_scheduler.c - Code location:
MachineInstr.h:2004(setDebugValueUndeffunction) - Optimization pass:
BranchFolder::HoistCommonCodeInSuccs
Workarounds
- Building with
-O1or-O0may avoid the crash - Disabling debug info (
-g) may prevent the issue - Excluding Polly from the build avoids the crash
Additional Context
This crash prevents successful self-hosted LLVM builds and appears to be a regression in the debug instruction handling during backend optimization passes.