range-op: Fix pointer difference relation with undefined RHS
The range-op pass now correctly handles undefined right-hand sides in pointer difference calculations.
This commit fixes an issue in the range-op pass where calculating the relation for pointer differences (operator_pointer_diff) could cause an ICE (Internal Compiler Error) if the right-hand side operand was undefined. The fix ensures that the type of the right-hand side is retrieved safely, preventing the ICE. This mirrors a similar check already present in operator_minus.
In Details
The operator_pointer_diff::op1_op2_relation function previously did not check if rhs1 was defined before attempting to get its type. This could lead to an ICE. The fix adds a check for rhs1 being undefined, similar to the operator_minus implementation which uses overflow_free to handle this. This ensures the relation is computed safely even when operand types are not fully determined.
- range-op
- A GCC pass or component likely responsible for optimizing operations involving ranges of values, including pointer arithmetic.
- pointer difference
- The result of subtracting two pointers of the same type, which yields the number of elements between them. This is typically an integer type like
ptrdiff_t. - ICE
- Internal Compiler Error. A fatal error occurring within the compiler itself, usually indicating a bug in the compiler's logic.
- RHS
- Right-Hand Side. Refers to the operand on the right side of a binary operator.
- op1_op2_relation
- A function within GCC that determines the relationship (e.g., less than, equal to, greater than) between two operands, often used for optimization purposes.