https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107912
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Keywords|diagnostic | Last reconfirmed| |2022-11-29 Summary|UBsan at -O0 missed a |shorterning causes a |signed integer overflow |missing signed integer | |overflow --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Another example where optimization level does not matter: ``` unsigned short a; int b; int main() { int c = b = -2147483648; unsigned short t = 0; a = t - b; __builtin_printf("%d\n", a); } ``` I thought we had there was a bug report about this but I can't find it right now. Anyways confirmed. The only reason why the original example works at -O1 and above is because (c && c == 0) is figured out to be false (0) and then 0-b is translated into -b and the shorterning does not happen.