Hi!

This is the case I was talking about in
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642423.html
and Zdenek kindly found a testcase for it.
We can only create BITINT_TYPE with precision at most 65535, not 65536,
so need to punt if we'd want to create it.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-01-12  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/113330
        * tree-sra.cc (create_access): Punt for BITINT_TYPE accesses with
        too large size.

        * gcc.dg/bitint-69.c: New test.

--- gcc/tree-sra.cc.jj  2024-01-10 12:45:54.293851670 +0100
+++ gcc/tree-sra.cc     2024-01-11 15:13:29.697073438 +0100
@@ -967,6 +967,12 @@ create_access (tree expr, gimple *stmt,
       disqualify_candidate (base, "Encountered an access beyond the base.");
       return NULL;
     }
+  if (TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE
+      && size > WIDE_INT_MAX_PRECISION - 1)
+    {
+      disqualify_candidate (base, "Encountered too large _BitInt access.");
+      return NULL;
+    }
 
   access = create_access_1 (base, offset, size);
   access->expr = expr;
--- gcc/testsuite/gcc.dg/bitint-69.c.jj 2024-01-11 15:16:57.573140907 +0100
+++ gcc/testsuite/gcc.dg/bitint-69.c    2024-01-12 09:55:30.026374627 +0100
@@ -0,0 +1,25 @@
+/* PR tree-optimization/113330 */
+/* { dg-do compile { target bitint } } */
+/* { dg-require-stack-check "generic" } */
+/* { dg-options "-std=c23 -O --param=large-stack-frame=131072 
-fstack-check=generic --param=sccvn-max-alias-queries-per-access=0" } */
+
+_BitInt(8) a;
+
+static inline __attribute__((__always_inline__)) void
+bar (int, int, int, int, int, int, int, int)
+{
+#if __BITINT_MAXWIDTH__ >= 65535
+  _BitInt(65535) b = 0;
+  _BitInt(383) c = 0;
+#else
+  _BitInt(63) b = 0;
+  _BitInt(39) c = 0;
+#endif
+  a = b;
+}
+
+void
+foo (void)
+{
+  bar (0, 0, 0, 0, 0, 0, 0, 0);
+}

        Jakub

Reply via email to