diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-11-28 10:23:47 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-11-28 10:23:47 +0100 |
commit | 88aeea14c23a5d066a635ffb4f1d2943fddcf0bd (patch) | |
tree | 26d7f259ba4a2af19c93e854fae833cd93664c6d /gcc | |
parent | 24dac1eab9c3b650826bbaa84dd64310910e647c (diff) | |
download | gcc-88aeea14c23a5d066a635ffb4f1d2943fddcf0bd.zip gcc-88aeea14c23a5d066a635ffb4f1d2943fddcf0bd.tar.gz gcc-88aeea14c23a5d066a635ffb4f1d2943fddcf0bd.tar.bz2 |
builtins: Handle BITINT_TYPE in __builtin_iseqsig folding [PR117802]
In check_builtin_function_arguments in the _BitInt patchset I've changed
INTEGER_TYPE tests to INTEGER_TYPE or BITINT_TYPE, but haven't done the
same in fold_builtin_iseqsig, which now ICEs because of that.
The following patch fixes that.
BTW, that TYPE_PRECISION (type0) >= TYPE_PRECISION (type1) test
for REAL_TYPE vs. REAL_TYPE looks pretty random and dangerous, I think
it would be useful to handle this builtin also in the C and C++ FEs,
if both arguments have REAL_TYPE, use the FE specific routine to decide
which types to use and error if a comparison between types would be
erroneous (e.g. complain about _Decimal* vs. float/double/long
double/_Float*, pick up the preferred type, complain about
__ibm128 vs. _Float128 in C++, etc.).
But the FEs can just promote one argument to the other in that case
and keep fold_builtin_iseqsig as is for say Fortran and other FEs.
2024-11-28 Jakub Jelinek <jakub@redhat.com>
PR c/117802
* builtins.cc (fold_builtin_iseqsig): Handle BITINT_TYPE like
INTEGER_TYPE.
* gcc.dg/builtin-iseqsig-1.c: New test.
* gcc.dg/bitint-118.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/builtins.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/bitint-118.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/builtin-iseqsig-1.c | 20 |
3 files changed, 45 insertions, 2 deletions
diff --git a/gcc/builtins.cc b/gcc/builtins.cc index d338abe..d925074 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -9946,9 +9946,11 @@ fold_builtin_iseqsig (location_t loc, tree arg0, tree arg1) /* Choose the wider of two real types. */ cmp_type = TYPE_PRECISION (type0) >= TYPE_PRECISION (type1) ? type0 : type1; - else if (code0 == REAL_TYPE && code1 == INTEGER_TYPE) + else if (code0 == REAL_TYPE + && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) cmp_type = type0; - else if (code0 == INTEGER_TYPE && code1 == REAL_TYPE) + else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE) + && code1 == REAL_TYPE) cmp_type = type1; arg0 = builtin_save_expr (fold_convert_loc (loc, cmp_type, arg0)); diff --git a/gcc/testsuite/gcc.dg/bitint-118.c b/gcc/testsuite/gcc.dg/bitint-118.c new file mode 100644 index 0000000..d330cc5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-118.c @@ -0,0 +1,21 @@ +/* PR c/117802 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c23" } */ + +int +foo (float x, _BitInt(8) y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} + +int +bar (double x, unsigned _BitInt(162) y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} + +int +baz (long double x, _BitInt(574) y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} diff --git a/gcc/testsuite/gcc.dg/builtin-iseqsig-1.c b/gcc/testsuite/gcc.dg/builtin-iseqsig-1.c new file mode 100644 index 0000000..e9fe87b --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-iseqsig-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int +foo (float x, int y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} + +int +bar (double x, unsigned long y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} + +int +baz (long double x, long long y) +{ + return __builtin_iseqsig (x, y) * 2 + __builtin_iseqsig (y, x); +} |