This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Tim Hollebeek <tim at hollebeek dot com>
- To: dewar at gnat dot com
- Cc: groudier at free dot fr, jamagallon at able dot es, Dautrevaux at microprocess dot com, gcc at gcc dot gnu dot org, jtv at xs4all dot nl, linux-kernel at vger dot kernel dot org, paulus at samba dot org, tim at hollebeek dot com, trini at kernel dot crashing dot org, velco at fadata dot bg
- Date: Wed, 9 Jan 2002 23:37:26 -0500
- Subject: Re: [PATCH] C undefined behavior fix
- References: <20020110012109.E80C0F2FEB@nile.gnat.com>
- Reply-to: tim at hollebeek dot com
> Nope, that's not enough, it's not that simple. Yes your
> example of a-a is of course straightforward but what about
>
> b = (a & 1) | (b & 1);
>
> if a is volatile and b is known to be odd, can the read of a be eliminated?
> The answer should be no (and I think the standard guarantees this), but the
> reasoning is completely different from thinking about the fact that a may
> change unexpectedly, since obviously no matter what value comes from
> reading a, b will be set to 1 if b is known to be odd.
But presumably the transformation to:
a; b = 1;
is ok. where 'a;' represents the operation "read the value a into a
register and then let that register die".