This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: jtv <jtv at xs4all dot nl>
- To: Bernard Dautrevaux <Dautrevaux at microprocess dot com>
- Cc: "'dewar at gnat dot com'" <dewar at gnat dot com>, paulus at samba dot org, gcc at gcc dot gnu dot org, linux-kernel at vger dot kernel dot org, trini at kernel dot crashing dot org, velco at fadata dot bg
- Date: Mon, 7 Jan 2002 22:49:07 +0100
- Subject: Re: [PATCH] C undefined behavior fix
- References: <17B78BDF120BD411B70100500422FC6309E402@IIS000>
On Mon, Jan 07, 2002 at 02:24:35PM +0100, Bernard Dautrevaux wrote:
>
> Note however that some may not have noticed, in the volatile-using examples,
> that there is a difference between a "pointer to volatile char" and a
> "volatile pointer to char"; the former, defined as "volatile char*" does not
> help in the case of the RELOC macro, while the latter, written "char
> *volatile" (note that volatile is now AFTER the '*', not before) is a sure
> fix as the semantics of "volatile" ensure that the compiler will NO MORE use
> the value it PREVIOUSLY knows was the one of the pointer.
One problem I ran into considering 'char *volatile' was this one: the
compiler is supposed to disable certain optimizations involving
registerization and such, but isn't it still allowed to do constant
folding? That would eliminate the pointer from the intermediate code
altogether, and so the volatile qualifier would be quickly forgotten.
No fixo breako.
Nothing's taking the pointer's address, so the compiler _will_ be able
to prove that (in a sensible universe) no other thread, interrupt,
kernel code or Angered Rain God will be able to find our pointer--much
less change it.
Jeroen