https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125072
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Martin Uecker <[email protected]>: https://gcc.gnu.org/g:a02ff0f1faf0858a6fe80492c51b82892ab90479 commit r17-1354-ga02ff0f1faf0858a6fe80492c51b82892ab90479 Author: Martin Uecker <[email protected]> Date: Thu Jun 4 19:19:33 2026 +0200 c: wrong code generated with counted_by on pointer + ubsan [PR125072] When a pointer is accessed with a constant offset, this has to be split into the size of the element type and the index to be able to instrument the index. The code failed to re-apply the element size after this. PR c/125072 gcc/c-family/ChangeLog: * c-ubsan.cc (get_index_from_offset,get_index_from_pointer_addr_expr, is_instrumentable_pointer_array_address): Return factor. (ubsan_maybe_instrument_array_ref): Apply factor. gcc/testsuite/ChangeLog: * gcc.dg/pr125072.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-124230-union.c: Avoid heap corruption. * gcc.dg/ubsan/pointer-counted-by-bounds-124230.c: Likewise.
