https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119140
--- Comment #1 from Siddhesh Poyarekar <siddhesh at gcc dot gnu.org> --- How about emitting .ACCESS_WITH_SIZE for p (or in case of foo, the return value), i.e. const __SIZE_TYPE__ sz = sizeof (b) - i; .ACCESS_WITH_SIZE(&p, &sz, ...) which should survive optimizations and in a later ubsan pass, look at .UBSAN_BOUNDS lhs to see if it has any .ACCESS_WITH_SIZE calls and then adjust the size accordingly?