This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Paul Mackerras <paulus at samba dot org>
- To: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Cc: <jkl at miacid dot net>, Florian Weimer <fw at deneb dot enyo dot de>,<dewar at gnat dot com>, <Dautrevaux at microprocess dot com>,<Franz dot Sirl-kernel at lauterbach dot com>, <benh at kernel dot crashing dot org>,<gcc at gcc dot gnu dot org>, <jtv at xs4all dot nl>, <linux-kernel at vger dot kernel dot org>,<linuxppc-dev at lists dot linuxppc dot org>, <minyard at acm dot org>,<rth at redhat dot com>, <trini at kernel dot crashing dot org>, <velco at fadata dot bg>
- Date: Sun, 6 Jan 2002 15:09:49 +1100 (EST)
- Subject: Re: [PATCH] C undefined behavior fix
- References: <Pine.BSI.4.10.10201051111100.8542-100000@hevanet.com><Pine.LNX.4.33.0201051929080.485-100000@kern.srcf.societies.cam.ac.uk>
- Reply-to: paulus at samba dot org
Joseph S. Myers writes:
> Just because you've created a pointer P, and it compares bitwise equal to
> a valid pointer Q you can use to access an object, does not mean that P
> can be used to access that object. Look at DR#260, discussing the
I looked at this, and it starts out with an example that includes a
statement free(p); (where p was assigned a value returned from malloc)
and then states that "After the call to free the value of p is
indeterminate."!
This seems absolutely and completely bogus to me. Certainly, after
the free, the value of *p is indeterminate, but the value of p itself
*is* determinate; its value after the free is identical to its value
before the free. Why do they say that the value of p itself is
indeterminate after the free?
The two examples of why a compiler might want to change the value are
also bogus; the compiler can avoid writing the value of p from a
register back to memory only if the value is dead, and it isn't in the
example given. As for the debugging opportunity, if I want p to be
set to NULL or some other pattern for debugging I'll do it explicitly.
In general I think that when a pointer value has been obtained by a
cast to an integer or by passing the address of a pointer to a
function, the compiler should assume that the pointer can point
anywhere. That means reduced opportunities for optimization, but so
be it. Note that all of the examples in DR#260 involve passing &p to
some function.
Paul.