Is it safe to use _Bool as asm statement outputs on x86?

Richard Henderson rth@redhat.com
Wed Jun 3 01:02:00 GMT 2015


On 06/02/2015 04:46 PM, H. Peter Anvin wrote:
> For the x86 backend explicitly, is doing something like:
>
> 	_Bool x;
>
> 	asm("blah ; setc %0" : "=qm" (x));
>
> ... guaranteed to be safe for older versions of gcc?

I believe so, for the restricted set of conditions I expect you're asking.
In particular:

  (1) Linux has always defined _Bool as a byte (indeed, afaik only Darwin
      has ever done otherwise).

  (2) You must really produce 0/1 from the asm; the compiler doesn't re-do
      the canonicalization afterward, and afaik we do rely on that in the
      optimizers.  But certainly that's true for any version of GCC.



r~



More information about the Gcc mailing list