gccrs: Use EH_ELSE_EXPR for block drop cleanup
GCC's Rust compiler uses EH_ELSE_EXPR for block scope drop cleanup in TRY_FINALLY_EXPR.
GCC’s Rust compiler now uses EH_ELSE_EXPR to manage block-scope drop cleanups within TRY_FINALLY_EXPR. This change ensures that Drop implementations are correctly invoked during normal control flow exits, even before full stack unwinding support is integrated into the compiler. The normal cleanup path now uses the Drop cleanup, while the exceptional path uses an empty statement.
In Details
The rustc_codegen_gcc backend has refined its exception handling for block-scope drops. By utilizing EH_ELSE_EXPR within TRY_FINALLY_EXPR, the compiler ensures that destructors for variables going out of scope are called during normal execution paths. This is particularly relevant for cases where stack unwinding (EH personality) is not yet fully implemented, providing a more robust cleanup mechanism.
- EH_ELSE_EXPR
- A compiler intermediate representation node that represents an exception-handling construct. It allows for distinct handling of normal and exceptional control flow.
- TRY_FINALLY_EXPR
- An expression that guarantees a 'finally' block is executed, regardless of whether the 'try' block completes normally or exits via an exception or other control flow transfer.
- Drop
- In Rust, a trait that can be implemented for a type to define custom logic that runs when a value of that type goes out of scope. This is primarily used for resource management.
- EH personality
- Code executed during stack unwinding to determine how to handle exceptions, including identifying cleanup routines for variables.
- stack unwinding
- The process of reverting function calls on the call stack when an exception is thrown, executing cleanup code for destructed objects along the way.