Check GIMPLE memory LHSs as stores
Correctly identifies GIMPLE memory LHSs as stores for exception analysis, improving safety.
This commit corrects the handling of memory Left-Hand Sides (LHSs) in GIMPLE (GCC’s Intermediate Representation) within the exception analysis. Previously, gimple_could_trap_p_1 incorrectly used tree_could_trap_p for memory LHSs when store checks were requested, potentially misclassifying them as non-trapping loads. The changes ensure that memory LHSs are now checked using gimple_store_p and lhs_could_trap_p, correctly identifying them as stores and preserving non-call exception information for constructs like GIMPLE_CALL results.
In Details
The gimple_could_trap_p_1 function in gimple.cc was using tree_could_trap_p on GIMPLE statement LHSs when store_p was true. tree_could_trap_p describes evaluation as an rvalue (load), which is incorrect for an assignment LHS. This commit modifies gimple_could_trap_p_1 to use gimple_store_p and lhs_could_trap_p for memory LHSs when store checks are enabled. It also omits statement LHSs from the rvalue scan and correctly checks memory call LHSs for non-call exceptions.
- GIMPLE
- GCC's Internal Representation, a three-address Three-part 'statement' form used after initial parsing and optimization passes. It's a structured intermediate language that simplifies many optimization analyses.
- LHS
- Left-Hand Side. In an assignment statement (e.g.,
x = y + 1;), the LHS is the variable or memory location being assigned to (x). - tree_could_trap_p
- A GCC internal function that determines if a tree node (representing an expression or operation) could potentially cause a trap or exception during evaluation.
- non-call exception
- An exception that can be raised by an operation (like a memory access or arithmetic overflow) as opposed to an explicit function call that might throw an exception.