asm volatile statement reordering

David Brown david@westcontrol.com
Tue Oct 17 11:56:00 GMT 2017


On 17/10/17 13:29, Segher Boessenkool wrote:
> On Tue, Oct 17, 2017 at 12:49:57PM +0200, David Brown wrote:
>> On 17/10/17 10:12, Segher Boessenkool wrote:
>> I don't have a build of trunk gcc conveniently available (I am building
>> a gcc 7 at the moment).  If this is a bug, then perhaps it is fixed
>> since the latest version I tried (6.3.0).  It is quite easy to test
>> there using the marvellous godbolt online compiler:
> 
> While godbolt is a very nice tool for exploring code generation by
> various compilers, it is not handy at all for debugging GCC bugs (if
> you manage to do that at all with it).

Agreed.  But I am still not entirely sure if this is a bug or part of
the design of asm volatile, and godbolt is a convenient way to test the
code on a variety of compiler versions.  I have not been involved in gcc
development or debugging (maybe I should be).

> 
>> The gcc documentation specifically says that asm volatile statements
>> /can/ be moved.  It just does not make it clear what kind of movements
>> are allowed.
> 
> It doesn't have to.  It is just warning you not to assume it will not
> move code here.  Anything that is not disallowed is allowed.
> 

gcc would be more useful for the kind of code in discussion here if
there were a clearer distinction.

I am afraid I am getting conflicting messages from you about this - or I
am misunderstanding something.  On the one hand, you have stated that
movement of "asm volatile" statements with respect to each other is a
bug - on the other hand, you don't want the documentation to say that
this is disallowed.

>> Is the patch below something you added to the trunk to fix this, or is
>> it something the trunk already had?
> 
> Neither.  I tested it on GCC 5; it should still apply to trunk as well,
> since the code there hasn't changed as far as I see.
> 

That is great, because it means there is an easy back-port to any
relevant version of gcc (many embedded development toolkits are a number
of major versions behind trunk).


> 
> Segher
> 



More information about the Gcc-help mailing list