https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103887
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Michal Kubecek from comment #2) > (In reply to Andrew Pinski from comment #1) > > The problem is rather __builtin_constant_p not resolving to a constant. This > > is a dup of bug 79482. > > There is a difference: your modified testcase fails to compile regardless of > -fsanitize=shift while mine fails only with this option and succeeds without > it. If __builtin_constant_p(tr) not being handled as constant were the > problem, > the result should not depend on presence of "-fsanitize=shift". Right, but the problem is __builtin_constant_p is not resolved to 0 forcing what is inside the static_assert to be non-constant in both cases. Even take a look at this: #include <stdint.h> #define ASSERT_ON_COMPILE_SELECTOR_SIZE(e) \ _Static_assert(((__builtin_constant_p(e) && ((e) >> 16) == 0)) || \ (sizeof(e) <= 2), "problem") int f(uint32_t tr) { ASSERT_ON_COMPILE_SELECTOR_SIZE(tr); return 0; } The static assert fails but fails because the expression is non-constant at -O2 and above. This is similar to your original case except without using -fsanitize=shift even.