https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67809
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- We indeed do not have a flag to tell GCC it's ok to remove infinite loops with no side-effects. We assume the dereferences will not trap (unless -fexceptions -fnon-call-exceptions) and GCC happily removes possible traps so I don't think that would prevent the DCE here. What prevents DCE is that the loop might not terminate. There isn't any "infinite loop is undefined behavior" thing so clang removing the loop is an invalid transform.