https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115156
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- The match.pd GENERIC folding happens at -O0 too and (__builtin_clzl (b), 3) is non-zero and has no side-effects, so it is just optimized away. I think the only way to "fix" this would be to make __builtin_clz* non-const/pure for the case when ubsan sanitizes them, but I think it isn't worth it. Don't expect diagnostics in silly code where it isn't actually used.