switchlower handles large BITINT_TYPE correctly
Fixes switchlower to correctly handle switch statement conversions for large integer types.
The switchlower pass in GCC incorrectly handled large BITINT_TYPE values in switch statements, leading to incorrect conditional logic for determining if a value was within a cluster’s range. This commit corrects the logic by ensuring that values are cast to their unsigned equivalent before subtraction and comparison when !TYPE_UNSIGNED is true, rather than relying on !TYPE_OVERFLOW_WRAPS. A new test case verifies this fix.
In Details
The jump_table_cluster::emit function within the switchlower pass was incorrectly applying range checks for BITINT_TYPEs wider than 64 bits. The original logic used !TYPE_OVERFLOW_WRAPS as the condition to cast to an unsigned type before performing value - low > high - low. This commit corrects the condition to !TYPE_UNSIGNED, ensuring that negative values that wrap around are handled appropriately and that values outside the valid range are correctly identified, especially for unsigned types.
- BITINT_TYPE
- GCC's internal representation for arbitrary-precision integer types, also known as
_BitIntin C++. - switchlower
- A GCC optimization pass that converts switch statements into more efficient forms, such as jump tables or conditional branches.
- jump_table_cluster
- A data structure used by the switchlower pass to group related case values for efficient jump table generation.
- TYPE_UNSIGNED
- A flag in GCC's internal type representation indicating whether a type is signed or unsigned.
- TYPE_OVERFLOW_WRAPS
- A flag indicating whether arithmetic operations on a type are defined to wrap around on overflow.