]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
sra: Punt for too large _BitInt accesses [PR113330]
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2024 10:22:04 +0000 (11:22 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2024 10:22:04 +0000 (11:22 +0100)
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.

2024-01-12  Jakub Jelinek  <jakub@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/testsuite/gcc.dg/bitint-69.c [new file with mode: 0644]
gcc/tree-sra.cc

diff --git a/gcc/testsuite/gcc.dg/bitint-69.c b/gcc/testsuite/gcc.dg/bitint-69.c
new file mode 100644 (file)
index 0000000..c225cbd
--- /dev/null
@@ -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);
+}
index e786232f6b004c69af811c2dda91d4b92d4ab3ef..6a1141b737709fd76bbb0f515d3d14b56a23e07d 100644 (file)
@@ -967,6 +967,12 @@ create_access (tree expr, gimple *stmt, bool write)
       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;