public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] c: Fix handling of cond ? intcap : uintcap
@ 2022-05-06 14:45 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5a9edede48acc978a6527ff1157847a4b279caa9

commit 5a9edede48acc978a6527ff1157847a4b279caa9
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Fri Apr 29 13:45:05 2022 +0100

    c: Fix handling of cond ? intcap : uintcap
    
    c_common_type would ICE on a joust between two intcaps with
    opposite signedness.  The handling of intcap vs. integer
    works for this case too, with a minor tweak.

Diff:
---
 gcc/c/c-typeck.c                                   |  6 +-
 .../gcc.target/aarch64/morello/cond-expr-2.c       | 76 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index b6b59687151..e88a4525a61 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -924,18 +924,18 @@ c_common_type (tree t1, tree t2)
 
   /* INTCAP_TYPEs out-rank all other integer types.  */
 
-  if ((code1 == INTCAP_TYPE && INTEGRAL_TYPE_P (t2))
-      || (code2 == INTCAP_TYPE && INTEGRAL_TYPE_P (t1)))
+  if (code1 == INTCAP_TYPE || code2 == INTCAP_TYPE)
     {
       tree t_intcap = (code1 == INTCAP_TYPE) ? t1 : t2;
       tree t_int = (t_intcap == t1) ? t2 : t1;
+      gcc_assert (INTEGRAL_TYPE_P (t_int) || INTCAP_TYPE_P (t_int));
 
       /* If the signs differ, the unsigned type has conversion rank less
 	 than the signed type, and the signed type cannot represent all values
 	 of the unsigned type, then both operands are converted to the unsigned
 	 counterpart of the signed operand.  */
       if (!TYPE_UNSIGNED (t_intcap) && TYPE_UNSIGNED (t_int)
-	  && TYPE_NONCAP_PRECISION (t_intcap) <= TYPE_PRECISION (t_int))
+	  && TYPE_NONCAP_PRECISION (t_intcap) <= TYPE_NONCAP_PRECISION (t_int))
 	return uintcap_type_node;
       else
 	return t_intcap;
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/cond-expr-2.c b/gcc/testsuite/gcc.target/aarch64/morello/cond-expr-2.c
new file mode 100644
index 00000000000..2ef57197517
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/cond-expr-2.c
@@ -0,0 +1,76 @@
+#include <stdint.h>
+
+__intcap_t icap;
+__uintcap_t ucap;
+int8_t i8;
+uint8_t u8;
+int16_t i16;
+uint16_t u16;
+int32_t i32;
+uint32_t u32;
+int64_t i64;
+uint64_t u64;
+__int128 i128;
+unsigned __int128 u128;
+
+void foo(int cond) {
+  _Static_assert(_Generic (cond ? ucap : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : icap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : icap, __intcap_t: 1, default: 0));
+
+  _Static_assert(!_Generic (cond ? ucap : ucap, __intcap_t: 1, default: 0));
+  _Static_assert(!_Generic (cond ? ucap : icap, __intcap_t: 1, default: 0));
+  _Static_assert(!_Generic (cond ? icap : ucap, __intcap_t: 1, default: 0));
+  _Static_assert(!_Generic (cond ? icap : icap, __uintcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? ucap : u8, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : i8, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : u8, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : i8, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? ucap : u16, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : i16, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : u16, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : i16, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? ucap : u32, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : i32, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : u32, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : i32, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? ucap : u64, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : i64, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : u64, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : i64, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? ucap : u128, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? ucap : i128, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : u128, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? icap : i128, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? u8 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i8 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? u8 : icap, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i8 : icap, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? u16 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i16 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? u16 : icap, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i16 : icap, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? u32 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i32 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? u32 : icap, __intcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i32 : icap, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? u64 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i64 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? u64 : icap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i64 : icap, __intcap_t: 1, default: 0));
+
+  _Static_assert(_Generic (cond ? u128 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i128 : ucap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? u128 : icap, __uintcap_t: 1, default: 0));
+  _Static_assert(_Generic (cond ? i128 : icap, __intcap_t: 1, default: 0));
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-06 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:45 [gcc(refs/vendors/ARM/heads/morello)] c: Fix handling of cond ? intcap : uintcap Matthew Malcomson

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).