https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105727
--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> --- That may be true, but I think only the 1/2/4/8/16 sizes are interesting to handle with special code. And as the function is provably called by a function which can have any size and through LTO can get a constant value, the options are remove the BUILD_BUG(); or ensure that the size is never constant from the mm/kasan/shadow.c (memset) call (hide e.g. through inline asm the exact value from the compiler) or have 2 different implementations, one that has BUILD_BUG() and is used only for those specific sizes and another one which doesn't (either calls just the *_n function or has everything but BUILD_BUG) that can handle arbitrary sizes.