GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
eh

eh: Use `lhs_could_trap_p` for non-call exceptions in assignment.

Improved exception handling for assignments involving the 'this' pointer by using more precise trapping checks.

The exception handling subsystem now correctly accounts for non-call exceptions that can occur on the left-hand side (LHS) of assignments, particularly when the this pointer is involved. Previously, a fix for PR127133 incorrectly marked the this argument as non-trapping, leading to an oversight in exception analysis. This commit replaces checks for tree_could_throw_p with lhs_could_trap_p and tree_could_throw_1 in lower_eh_constructs_2 and related functions, ensuring that potential trapping on the LHS is properly identified, fixing PR127183.

In Details

In tree-eh.cc, the exception handling logic for non-call sites has been refined. The this argument, after being fixed in PR127133 to not cause non-call exceptions, was causing issues in lower_eh_constructs_2 and stmt_could_throw_1_p due to overly broad trapping checks. This patch updates these functions to use lhs_could_trap_p and tree_could_throw_1 instead of tree_could_throw_p when analyzing the LHS of an assignment, correctly identifying potential exceptions originating from the LHS itself, rather than assuming it cannot trap. This resolves PR tree-optimization/127183.

For Context
eh
Abbreviation for Exception Handling. Refers to the mechanisms within GCC that manage runtime exceptions, such as C++ exceptions or hardware traps.
LHS
Left-Hand Side. In an assignment statement (e.g., a = b;), the LHS refers to the variable or memory location receiving the value (e.g., a).
`this` pointer
In C++ member functions, a pointer that points to the object on which the member function was called. It is implicitly passed to non-static member functions.
tree_could_throw_p
A GCC internal function that checks if a given GCC Tree node (representing an expression or statement) could potentially throw an exception.
Filed Under: ehexception handlingoptimizationthis pointer