diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-02-02 11:28:31 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2024-02-02 11:30:06 +0100 |
commit | fb28d5cdae149f08f0d472c210a5143a64771410 (patch) | |
tree | 9ff0ee89f50d01724692098efaeebcd1a629cf49 | |
parent | 49e75666c592d23dfa17f062974e660edd01d5fb (diff) | |
download | gcc-fb28d5cdae149f08f0d472c210a5143a64771410.zip gcc-fb28d5cdae149f08f0d472c210a5143a64771410.tar.gz gcc-fb28d5cdae149f08f0d472c210a5143a64771410.tar.bz2 |
lower-bitint: Handle casts from large/huge _BitInt to pointer/reference types [PR113692]
I thought one needs to cast first to pointer-sized integer before casting to
pointer, but apparently that is not the case.
So the following patch arranges for the large/huge _BitInt to
pointer/reference conversions to use the same code as for conversions
of them to small integral types.
2024-02-02 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/113692
* gimple-lower-bitint.cc (bitint_large_huge::lower_stmt): Handle casts
from large/huge BITINT_TYPEs to POINTER_TYPE/REFERENCE_TYPE as
final_cast_p.
* gcc.dg/bitint-82.c: New test.
-rw-r--r-- | gcc/gimple-lower-bitint.cc | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/bitint-82.c | 18 |
2 files changed, 23 insertions, 3 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 7588150..a7cc5ce 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -5264,7 +5264,8 @@ bitint_large_huge::lower_stmt (gimple *stmt) mergeable_cast_p = true; else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large - && INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || POINTER_TYPE_P (TREE_TYPE (lhs)))) { final_cast_p = true; if (TREE_CODE (rhs1) == SSA_NAME @@ -5393,8 +5394,9 @@ bitint_large_huge::lower_stmt (gimple *stmt) be needed. */ gcc_assert (TYPE_PRECISION (lhs_type) <= 2 * limb_prec); gimple *g; - if (TREE_CODE (lhs_type) == BITINT_TYPE - && bitint_precision_kind (lhs_type) == bitint_prec_middle) + if ((TREE_CODE (lhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) == bitint_prec_middle) + || POINTER_TYPE_P (lhs_type)) lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (lhs_type), TYPE_UNSIGNED (lhs_type)); m_data_cnt = 0; diff --git a/gcc/testsuite/gcc.dg/bitint-82.c b/gcc/testsuite/gcc.dg/bitint-82.c new file mode 100644 index 0000000..4ea86f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-82.c @@ -0,0 +1,18 @@ +/* PR tree-optimization/113692 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c23" } */ + +#if __BITINT_MAXWIDTH__ >= 135 +_BitInt(135) i; +#else +_BitInt(63) i; +#endif + +void * +foo (void) +{ + void *ret = 0; + if (i & 1) + ret = (void *) 1; + return ret; +} |