This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Linus Torvalds <torvalds at transmeta dot com>
- To: mike stump <mrs at windriver dot com>
- Cc: <dennis at juniper dot net>, <gcc at gcc dot gnu dot org>, <paulus at samba dot org>, <rth at redhat dot com>
- Date: Mon, 7 Jan 2002 15:13:26 -0800 (PST)
- Subject: Re: [PATCH] C undefined behavior fix
On Mon, 7 Jan 2002, mike stump wrote:
>
> Any expansive text on volatile will cover it. We can see some of the
> bits of it from a C c99 working draft:
Note that if we start using "volatile", then gcc really _has_ to improve
its code generation here. Quite frankly, as it is, "volatile" absolutely
_sucks_ code-generation-wise.
Just as an example, look at your two "hide()" functions:
#define hide(x) ({ void *vp = x; asm ("" : "+r" (vp)); vp; })
inline void *hide(void *vp) { void *volatile v; v = vp; return v; }
I already sent out an example of why the "asm" thing generates suboptimal
code, because it forgets the value and is unable to use the knowledge.
However, with "volatile", the code generated _really_ sucks.
Here's the code for the "asm" version of ((*(int *)(0x10000+hide(i)):
movl $i, %eax
movl 65536(%eax), %eax
and here's the code that gcc generates from the "volatile" inline
function:
movl $i, %eax
movl %eax, (%esp)
movl (%esp), %eax
movl 65536(%eax), %eax
which is just not acceptable for any real use.
Linus