gccrs drop analysis handles conditional moves in BIR
gccrs improves its analysis of when locals are dropped, correctly handling conditional moves.
gccrs now accurately tracks the initialization state of local variables across control-flow branches in the BIR, specifically addressing conditional moves. This allows the compiler to correctly classify Drop statements as conditional when a local is moved on only some execution paths. New tests validate this behavior for static, dead, and conditional drops.
In Details
This commit refines gccrs' borrow checker's drop analysis, operating on the BIR. It introduces BlockInitializationState and related functions (is_straight_line, set_initialized, etc.) to track initialization across CFG branches. The DropAnalysis::analyze now propagates this state to correctly classify Drop statements, particularly when locals are involved in conditional moves, ensuring correct RAII behavior.
- BIR
- Backend Intermediate Representation. A low-level, SSA-based intermediate representation used by GCC for optimization and code generation.
- Drop analysis
- In Rust, analysis performed by the compiler to determine when and how a value's destructor (its
dropimplementation) should be called. This is crucial for managing resources and preventing memory leaks. - Control-Flow Graph (CFG)
- A graphical representation of the possible execution paths through a program. Basic blocks are nodes, and control flow transfers (jumps, branches) are edges.