gccrs: Add straight-line BIR drop state analysis
New analysis in gccrs identifies and classifies variable drops within basic blocks.
GCC’s Rust front-end gains a new straight-line BIR drop state analysis pass. This analysis inserts BIR Drop statements at scope exits and classifies them as static or dead based on variable initialization and move states. Function arguments are treated as initialized and their drops are scheduled before function returns.
In Details
A new analysis pass, rust-bir-drop-analysis.cc, is introduced to the gccrs borrow checker. It operates on the BIR to identify and classify Drop statements. It tracks variable initialization and move states within a straight-line execution path. Function parameters are implicitly initialized and their drops are handled specially during function returns via push_function_argument_drops in rust-bir-builder-internal.cc.
- BIR
- Backend Intermediate Representation. A low-level, graph-based intermediate representation used by the GCC Rust front-end (gccrs) for performing analyses and optimizations.
- Drop statement
- In Rust, a
Dropstatement signifies the deallocation of a value that owns resources. This analysis ensures these statements are correctly placed and classified. - static drop
- A classification for a drop operation that is guaranteed to execute, often because the variable it applies to is guaranteed to be live.
- dead drop
- A classification for a drop operation that is determined to be unnecessary, typically because the value has already been moved or its resources are otherwise no longer live.