John Regehr
explains how
new optimizations in GCC 4.8.0 can break code making use of undefined
behavior. "
A C compiler, upon seeing d[++k], is permitted to assume
that the incremented value of k is within the array bounds, since otherwise
undefined behavior occurs. For the code here, GCC can infer that k is in
the range 0..15. A bit later, when GCC sees k<16, it says to itself: 'Aha--
that expression is always true, so we have an infinite loop.'"
(
Log in to post comments)