]> gcc.gnu.org Git - gcc.git/commitdiff
lower-bitint: Handle casts from large/huge _BitInt to pointer/reference types [PR113692]
authorJakub Jelinek <jakub@redhat.com>
Fri, 2 Feb 2024 10:28:31 +0000 (11:28 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 2 Feb 2024 10:30:06 +0000 (11:30 +0100)
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.

gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/bitint-82.c [new file with mode: 0644]

index 758815039219f96f57df05a24fe76704c69cb66b..a7cc5cee07baed4b1e6afe6b62264e10c0eebabf 100644 (file)
@@ -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 (file)
index 0000000..4ea86f0
--- /dev/null
@@ -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;
+}
This page took 0.082077 seconds and 5 git commands to generate.