------- Comment #6 from mikpe at it dot uu dot se 2009-07-08 09:59 ------- (In reply to comment #2) > Replacing *tbl++ by tbl[i] gives this ARM code: > .L2: > mov r3, #10 > str r3, [r2], #4 > cmp r2, #0 > bne .L2 > bx lr > > See, gcc knows about the wrapping but still the *tbl++ version misses the > end-condition which is the bug.
The difference is that in the tbl[i] version there will not be a wraparound at runtime because &tbl[i] for i == 64 is never computed, while in the *tbl++ version the iteration with i == 63 will do tbl++ moving tbl from -4U to 0 before the loop termination test, which triggers undefined behaviour. And the issue is not ARM, the same infinite loop occurs for e.g. target i686. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40679