https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106068
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Dave Flogeras from comment #2) > For that code, agreed, and that was indeed both our and upstreams > workaround. We were just wondering if it was a legitimate compiler bug > given that it generated an infinite loop in asm. Or does it just fall under > "undefined" It is undefined if you access an out of bounds in an array. In this case the compiler assumes there would be no such access and optimizes the range of n because of the access and then removes the bounds check as the access already happened. So yes it is falls under undefined.