Bug in loop optimize (invalid postinc to preinc transformation)

Jamie Lokier egcs@tantalophile.demon.co.uk
Wed Jan 3 00:52:00 GMT 2001


dewar@gnat.com wrote:
> Indeed. The important thing to remember in C is that the semantic
> model of a pointer is a pair (pointer-to-object, offset). Address
> arithmetic just modifies the offset, comparison compares only the
> offsets (and is undefined if the pointer-to-object values are
> different).
> 
> Of course in practice the implementation is typically a single pointer
> from a flat space, representing the sum of the two components, but the
> proper semantic model needs to be kept in mind, and code that does not
> respect this semantic model has undefined effects.

The point (no pun intended) is that the problematic example code
includes a constant-valued pointer (unsigned char *) 0xffffffff.  Such a
pointer does not refer to any object unless your semantic model is a
flat space, in which all objects are sub-objects of a single "all of
memory" object.

> As C compilers get more clever, they are likely to be less permissive
> to abuses of the semantics :-)

Indeed.  As with strict type aliasing, as the compilers get more clever,
the programmers need clear definitions of which semantics they may rely
on from a particular compiler.  Many, many programs have a small part
that depends on traditional behaviour that's not defined in the ISO
standard.

-- Jamie


More information about the Gcc mailing list