https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120607
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Why do you think this is incorrect. Using -fsanitize=undefined I get the following runtime error message: /app/example.cpp:14:30: runtime error: execution reached an unreachable program point Which means the code is actually undefined. > but under -O2, GCC incorrectly folds the entire test_builtin_unreachable() > function, leading to an infinite loop at runtime. Because with bb == 2, the second if statement is always true so it is converted into: if (true) __builtin_unreachable (); Which means it is always unreachable.