From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Hollebeek To: geoffk@geoffk.org (Geoff Keating) Cc: aoliva@redhat.com (Alexandre Oliva), kenner@vlsi1.ultra.nyu.edu, gcc@gcc.gnu.org, dewar@gnat.com (Robert Dewar) Subject: Re: Bug in loop optimize (invalid postinc to preinc transformation) Date: Thu, 28 Dec 2000 15:22:00 -0000 Message-id: <200012282342.SAA29717@cj44686-b.reston1.va.home.com> References: X-SW-Source: 2000-12/msg00810.html Geoff Keating writes ... > > Since 0 is not a valid pointer---that is, no pointer to an object > should ever compare equal to 0--- Please, everyone, be careful with your language. 0 is not a valid pointer because it isn't a pointer. It's an integral constant. Another possible interpretation is that you meant a pointer with representation all bits zero. If the null pointer has that representation, then no valid pointer can have it. So you're saying (essentially) is "the all bits zero pointer is the null pointer, which points to nothing --- no pointer to an object can ever have that representation". True, given the assumption that the all bits zero pointer is the null pointer. Yet another possible interpretation of '0' in both halves is that you meant a null pointer constant which is what the integral constant 0 becomes when converted to a pointer. If that's what you meant then what you said is "a null pointer isn't non-null --- that is, no non-null pointer should ever compare equal to a null pointer constant". True in all cases, but rather unprofound. No "valid" pointer can compare equal to a null pointer, but this says nothing about the representation of pointers. The null pointer need not be represented by "all bits zero", and all bits zero may be a valid pointer on some architectures. > this makes pointers a case of unsigned integers for which overflow is not permitted. This doesn't follow at all. If pointers are implementation as unsigned offsets into a flat memory model, one of two things is true: Case 1: 0x00000000 is the null pointer. Therefore it isn't within a valid object, and is not immediately following a valid array. >>>THEREFORE WRAPPING IS IRRELEVANT<<< since no valid pointer increment or operation can cross the boundary. Case 2: 0x00000000 is within a valid object, or immediately follows an array. In this case, 0x00000000 cannot be the null pointer, so some other value (__null) is. Overflow isn't an issue since if all computations on unsigned pointer values involve first subtracting __null (using unsigned arithmetic; wrapping is well defined here) from each pointer, than adding it back in when necessary, we reduce to case 1. Either way, wrapping is well-defined/irrelevant. Optimization must just preserve the correct semantics. If an optimization causes values to be used which might overflow or cause other problems when the original values would not, then that's a bad optimization. But this has nothing to do with "pointer wrapping" or "pointers being unsigned" or any other such nonsense. It's just a bad optimization.