------- Comment #10 from rakdver at atrey dot karlin dot mff dot cuni dot cz 2006-04-03 17:22 ------- Subject: Re: [4.1 Regression] wrong final value of induction variable calculated
> > (In reply to comment #6) > > > I believe c-common.c:pointer_int_sum is wrong in relying on pointer > > > overflow > > > during conversion of the integer offset to an unsigned pointer. I'm > > > sending > > > a patch that fixes this for comments. > > > > The patch seems a bit too conservative to me; perhaps just always comparing > > the > > offsets as signed could work? > > I'm not a language lawyer here - and as this is the second (or third) > patch to this folding to correct problems I'd rather be safe than sorry > this time. I'm sure jsm can construct a testcase where comparing offsets > as signed leads to wrong code. Maybe > > char *memory = 0; > > int foo(void) > { > return memory + 0x80000000 < memory; > } > > int main() > { > if (foo()) > abort (); > } > > i.e. have a mapping >2Gb on a 32bit machine. A corner case, but valid I > guess. no -- the result in this example is undefined. The comparisons are only defined for pointers in the same object. I guess nothing really prevents having an object whose size is more than half of the address space, though. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26763