https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85365
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |marxin at gcc dot gnu.org --- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- void foo (char *p, char *q) { __builtin_strcpy (p, q); __builtin_strcat (p, q + 32); } warns too and there is no check that could be removable (with extra specialized code to detect stuff like this; note, we intentionally for sanitizers use -fno-delete-null-exceptions etc. so that the checks aren't all removed). There is redundancy (p checked twice), that is something sanopt pass handles, but it runs late. What we could do is defer all or almost all UBSAN sanitizations in form of ifns until sanopt time, so jump threading wouldn't affect it and only sanopt would lower it into comparison and the cold diagnostics. Or improve jump threading so that it doesn't try to thread these checks with cold calls in it. Or don't warn on non-sensical dead code that is going to be optimized away immediately (on these testcases, gimple_fold sees (dead) strcpy (0, 0), -Wrestrict warns on it and it is immediately turned into a GIMPLE_NOP.