https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66090
Richard Earnshaw <rearnsha at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED CC| |rguenth at gcc dot gnu.org Resolution|INVALID |--- --- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #2) > Since the pointer is wrapping to null, you need to use > -fno-delete-null-pointer-checks to disable removing of checks of null > pointers or rather it enables allowing pointers to wrap to become null. > In C, once a pointer is non-null, it can't become null by adding a value to > it. So GCC enables an optimization around that case (and > fno-delete-null-pointer-checks disables that optimization). > > So no GCC bug, just wrongly assuming pointers can't become null pointers if > they were not null pointers. I'm inclined to disagree. Firstly, the code does not check for a null pointer, it checks a loop iterator variable. Secondly, although the pointer value wraps to zero, that value is never dereferenced; the last memory access is at 0xfffffffc. So I think the compiler is incorrectly removing a valid termination check. Richi, I'd like your opinion on this one.