https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128052
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:d5e7633c5a4e91f2c51cc12ca4995e51179ab96e commit r17-5468-gd5e7633c5a4e91f2c51cc12ca4995e51179ab96e Author: Richard Biener <[email protected]> Date: Wed Oct 21 16:48:33 2026 +0200 tree-optimization/128052 - miscompilation of unaligned loads from covered stores When vn_reference_lookup_3 interprets a load fully covered by a single store of a constant, the bits needed start at bit (offseti - offset2i) % BITS_PER_UNIT of the first encoded byte and thus span that remainder plus maxsizei bits. The code only checked that maxsizei bits were encoded, and with a 64 byte encoding limit an unaligned load of up to 512 bits (for example a 510-bit _BitInt bit-field at bit offset 3) could need a 65th byte that was not encoded, which then was zero-filled before the shift, dropping bits from the stored value. The following accounts for the bit remainder in the check, makes room for encoding one extra byte and caps the access size at bufsize * BITS_PER_UNIT to retain the previous limit. PR tree-optimization/128052 * tree-ssa-sccvn.cc (vn_reference_lookup_3): Guard single-store lookup with maxsizei <= bufsize * BITS_PER_UNIT. Increase buffer size to bufsize + 2. Account for the bit remainder (offseti - offset2i) % BITS_PER_UNIT when verifying that sufficient bits were encoded. * gcc.dg/torture/bitint-115.c: New test.
