Re: const versus __attribute__((const))

Linus Torvalds
2003-12-09T07:26:42Z

On Mon, 8 Dec 2003, H. Peter Anvin wrote:
>
> Sure it will:

No, Jamie was thinking of a variable that _already_ has a memory location
having its value copied around to _another_ memory location (ie a
temporary stack slot).

What your example shows is that gcc will create a stack slot for an
automatic variable if it doesn't have one already, in order to make it an
lvalue with a memory address.

So what's interesting is if gcc would take something like

extern int variable;

asm("..." : :"m" (variable));

and cause this to create a _new_ temporary on the stack slot, and pass the
asm the pointer to that temporary rather than the "real" address of
'variable'.

And as far as I know, it won't. Newer gcc's will _require_ memory
arguments to be lvalues (well, it will warn if they aren't), and will
always turn them into addressables of that particular lvalue.

This is actually an issue, because some asm code depends on getting the
proper address - not just the proper value. Things like locks etc care
_deeply_ about more than just the value.

Linus