genmodes: Use wider types for mode_unit_size array based on max size
Adjusts the data type for `mode_unit_size` array to prevent overflow on architectures with large modes.
The mode_unit_size array, generated by emit_mode_unit_size_inline, previously used unsigned char by default. This is insufficient for architectures like rs6000, which can have opaque modes with sizes up to 256 bytes, causing an overflow. This change introduces a MODE_UNIT_SIZE_TYPE macro that dynamically selects unsigned char, unsigned short, or unsigned int based on the maximum size encountered in the mode_unit_size array, resolving the overflow issue.
In Details
The genmodes.cc script now generates a MODE_UNIT_SIZE_TYPE macro in machmode.h. This macro's definition (unsigned char, unsigned short, or unsigned int) is determined by the maximum value present in the mode_unit_size array. This addresses an issue on platforms like rs6000 where opaque modes can exceed 255 bytes, preventing unsigned char overflow. Previously, emit_mode_unit_size_inline hardcoded this type.
- opaque mode
- A machine mode in GCC that represents a data type whose size and internal structure are not fully known to the compiler front-end, but are handled by the back-end.
- mode_unit_size
- An array used within GCC to store the size of each machine mode in bytes. This is used for various compiler internal calculations.
- rs6000
- The code name for IBM's PowerPC architecture, for which GCC provides specific support.