This is the mail archive of the
mailing list for the GCC project.
Re: basic asm and memory clobbers - Proposed solution
- From: <Paul_Koning at Dell dot com>
- To: <bernd dot edlinger at hotmail dot de>
- Cc: <dw at LimeGreenSocks dot com>, <david at westcontrol dot com>, <gcc at gcc dot gnu dot org>
- Date: Thu, 3 Dec 2015 15:24:10 +0000
- Subject: Re: basic asm and memory clobbers - Proposed solution
- Authentication-results: sourceware.org; auth=none
- References: <HE1PR07MB09059B9BF765EAA730813EE1E40E0 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com> <565F7E7A dot 8040004 at LimeGreenSocks dot com> <HE1PR07MB090552B9A13B87CAC6C6CB67E40D0 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com>
> On Dec 3, 2015, at 12:29 AM, Bernd Edlinger <email@example.com> wrote:
>> If the goal is to order things wrt x, why wouldn't you just reference x?
>> x = 1;
>> asm volatile("nop":"+m"(x));
>> x = 0;
> Exactly, that is what I mean. Either the asm can use memory clobber
> or it can use output and/or input clobbers or any combination of that.
> The problem with basic asm is not that it is basic, but that it does not
> have any outputs nor any inputs and it has no way to specify what it
> might clobber.
> Therefore I think the condition for the warning should not be that the
> asm is "basic", but that has zero outputs, zero inputs and zero clobbers.
> That would make more sense to me.
I don't think so.
Basic asm has a somewhat documented specification, in particular it is defined to be volatile. Some revs of GCC got this wrong, but such cases are obviously bugs. It does omit any statement about clobbers, true. And the difficulty is that people have made assumptions, not necessarily supported by documentation. And those assumptions may have been invalid on some platforms in some revs by new optimizations. The prevalence of confusion about basic asm is the reason why warning about it is potentially useful.
On the other hand, asm volatile ("foo":::) has a different meaning. That specifically says that "foo" doesn't clobber anything (and, implicitly, that it does not rely on any program variable being up to date in memory). While that isn't all that common, it is certainly possible. For example, if I want to turn on an LED on the device front panel, I might use such a statement (on machines where the instruction set allows me to do this without using registers). Since I explicitly stated "this doesn't clobber anything" I would not expect or want a warning.