tree-eh: Fix lhs_could_trap_p for *this pointer accesses
Correctly handle pointer dereferences on the left-hand side of assignments that might trap.
The compiler previously treated this->a as non-trapping on the left-hand side of an assignment, which could be incorrect if the memory was not read-only. This change refactors tree_could_trap_p into a new function tree_could_trap_1 that properly considers the left-hand side, resolving issues with constant method this pointer accesses.
In Details
The tree_eh.cc pass handles exception handling during code generation. The lhs_could_trap_p function determines if an expression on the left-hand side of an assignment could potentially trap (e.g., due to a null pointer dereference). Previously, it oversimplified this check for this pointers. This commit refactors tree_could_trap_p into tree_could_trap_1, allowing for more precise handling of LHS trapping, particularly for expressions like this->a in C++.
- tree-eh.cc
- A GCC source file responsible for analyzing and managing exception handling during the compilation process, particularly in relation to potential runtime errors like null pointer dereferences.
- lhs_could_trap_p
- A function within GCC's tree-eh pass that checks if an expression on the left-hand side (LHS) of an assignment could cause a runtime trap or exception.
- this pointer
- In C++, a special pointer that holds the address of the current object within a non-static member function. Accessing members through
this->membercan sometimes involve memory operations that need careful analysis for potential traps.