public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2024-02-07 14:04 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2024-02-07 14:04 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d21d9d9dc39c68fb4d235e96d19b9220f1950459

commit d21d9d9dc39c68fb4d235e96d19b9220f1950459
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 241b2f0f99..bcaa0cfcc6 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2024-04-17 20:04 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2024-04-17 20:04 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9a30e8cf4fa8d540b16cb08df3b6bd7fb3271131

commit 9a30e8cf4fa8d540b16cb08df3b6bd7fb3271131
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 241b2f0f99..bcaa0cfcc6 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2024-04-02 15:50 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2024-04-02 15:50 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b16f89c1dc89ea4bbe83e385d48bc170bbdbfe03

commit b16f89c1dc89ea4bbe83e385d48bc170bbdbfe03
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 241b2f0f99..bcaa0cfcc6 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2024-02-09 17:28 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2024-02-09 17:28 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7aee1fd8b3ce4228d4c2b10579d72507e45cd16e

commit 7aee1fd8b3ce4228d4c2b10579d72507e45cd16e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 241b2f0f99..bcaa0cfcc6 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2024-01-29 17:54 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2024-01-29 17:54 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=75be51f7485943ddbabb0999902b3ad9a157d4e2

commit 75be51f7485943ddbabb0999902b3ad9a157d4e2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 241b2f0f99..bcaa0cfcc6 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2023-12-21 18:50 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2023-12-21 18:50 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=80ea987d05906406b81e003615801876e35da1df

commit 80ea987d05906406b81e003615801876e35da1df
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index ae067d934d..cee7a4e833 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang
@ 2023-09-28 17:49 Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2023-09-28 17:49 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7a6632a72ce1d2a4a037e04884b4662e7b80f9dd

commit 7a6632a72ce1d2a4a037e04884b4662e7b80f9dd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Sep 13 18:02:57 2023 -0300

    stdlib: longlong.h: Do no use asm input cast for clang
    
     clang by default rejects the input casts with:
    
      error: invalid use of a cast in a inline asm context requiring an
      lvalue: remove the cast or build with -fheinous-gnu-extensions
    
    And even with -fheinous-gnu-extensions clang still throws an warning
    and also states that this option might be removed in the future.
    For gcc the cast are still useful [1] as type-checking.
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html

Diff:
---
 stdlib/longlong.h | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index ae067d934d..cee7a4e833 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -57,6 +57,14 @@
 #define attribute_hidden
 #endif
 
+/* clang does not support output constraint as lvalue, while gcc uses it as a
+   simple type check.  */
+#ifdef __clang__
+# define __asm_output_check_type(__type, __arg) (__arg)
+#else
+# define __asm_output_check_type(__type, __arg) ((__type)(__arg))
+#endif
+
 extern const UQItype __clz_tab[256] attribute_hidden;
 
 /* Define auxiliary asm macros.
@@ -230,16 +238,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -456,30 +464,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type(USItype, sl)			\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" __asm_output_check_type (USItype, sh),		\
+	     "=&r" __asm_output_check_type (USItype, sl)		\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" __asm_output_check_type (USItype, w0),		\
+	     "=d" __asm_output_check_type (USItype, w1)			\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" __asm_output_check_type (USItype, q),			\
+	     "=d" __asm_output_check_type (USItype, r)			\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +500,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" __asm_output_check_type (UDItype, sh),		\
+	     "=&r" __asm_output_check_type (UDItype, sl)		\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" __asm_output_check_type (UDItype, w0),		\
+	     "=d" __asm_output_check_type (UDItype, w1)			\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" __asm_output_check_type (UDItype, q),			\
+	     "=d" __asm_output_check_type (UDItype, r)			\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-17 20:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 14:04 [glibc/azanella/clang] stdlib: longlong.h: Do no use asm input cast for clang Adhemerval Zanella
  -- strict thread matches above, loose matches on Subject: below --
2024-04-17 20:04 Adhemerval Zanella
2024-04-02 15:50 Adhemerval Zanella
2024-02-09 17:28 Adhemerval Zanella
2024-01-29 17:54 Adhemerval Zanella
2023-12-21 18:50 Adhemerval Zanella
2023-09-28 17:49 Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).