[PATCH] include/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints

Florian Weimer fw@deneb.enyo.de
Mon Oct 11 04:58:50 GMT 2021


* Fangrui Song:

> An output constraint takes a lvalue. While GCC happily strips the
> incorrect lvalue to rvalue conversion, Clang rejects the code by default:
>
>     error: invalid use of a cast in a inline asm context requiring an lvalue: remove the cast or build with -fheinous-gnu-extensions
>
> The file appears to share the same origin with gmplib longlong.h but
> they differ much now (gmplib version is much longer).
>
> I don't have write access to the git repo.
> ---
>  include/longlong.h | 186 ++++++++++++++++++++++-----------------------
>  1 file changed, 93 insertions(+), 93 deletions(-)
>
> diff --git a/include/longlong.h b/include/longlong.h
> index c3e92e54ecc..0a21a441d2d 100644
> --- a/include/longlong.h
> +++ b/include/longlong.h
> @@ -194,8 +194,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>  #if defined (__arc__) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add.f	%1, %4, %5\n\tadc	%0, %2, %3"		\
> -	   : "=r" ((USItype) (sh)),					\
> -	     "=&r" ((USItype) (sl))					\
> +	   : "=r" (sh),							\
> +	     "=&r" (sl)							\
>  	   : "%r" ((USItype) (ah)),					\
>  	     "rICal" ((USItype) (bh)),					\
>  	     "%r" ((USItype) (al)),					\

This seems to alter the meanining of existing programs if sh and sl do
not have the expected type.

I think you need to add a compound expression and temporaries of type
USItype if you want to avoid the cast.


More information about the Gcc-patches mailing list