]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bitint: Fix tree node sharing bug [PR114209]
authorJakub Jelinek <jakub@redhat.com>
Mon, 4 Mar 2024 10:15:07 +0000 (11:15 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 4 Mar 2024 10:15:07 +0000 (11:15 +0100)
We ICE on the following testcase due to invalid tree sharing.
The second hunk fixes that, the first one is from me looking around at
other spots which might need end up with invalid tree sharing too.

2024-03-04  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/114209
* gimple-lower-bitint.cc (bitint_large_huge::limb_access): Call
unshare_expr when creating a MEM_REF from MEM_REF.
(bitint_large_huge::lower_stmt): Call unshare_expr.

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

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

index 15a27126d44a30d6cdd2f10bf16226cb2dcc1d1b..e3c8518f745f03994579693ba5afa1098b8a670f 100644 (file)
@@ -620,7 +620,7 @@ bitint_large_huge::limb_access (tree type, tree var, tree idx, bool write_p)
   else if (TREE_CODE (var) == MEM_REF && tree_fits_uhwi_p (idx))
     {
       ret
-       = build2 (MEM_REF, ltype, TREE_OPERAND (var, 0),
+       = build2 (MEM_REF, ltype, unshare_expr (TREE_OPERAND (var, 0)),
                  size_binop (PLUS_EXPR, TREE_OPERAND (var, 1),
                              build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)),
                                             tree_to_uhwi (idx)
@@ -5342,7 +5342,7 @@ bitint_large_huge::lower_stmt (gimple *stmt)
                      = build_qualified_type (ltype,
                                              TYPE_QUALS (ltype)
                                              | ENCODE_QUAL_ADDR_SPACE (as));
-                 rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, mem);
+                 rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, unshare_expr (mem));
                  gimple_assign_set_rhs1 (stmt, rhs1);
                }
              else
diff --git a/gcc/testsuite/gcc.dg/bitint-97.c b/gcc/testsuite/gcc.dg/bitint-97.c
new file mode 100644 (file)
index 0000000..a859978
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR middle-end/114209 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-Og -std=c23 -fno-strict-aliasing" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+
+typedef signed char V __attribute__((__vector_size__(16)));
+typedef _Float128 W __attribute__((__vector_size__(16)));
+
+_Float128
+foo (void *p)
+{
+  signed char c = *(_BitInt(128) *) p;
+  _Float128 f = *(_Float128 *) p;
+  W w = *(W *) p;
+  signed char r = ((union { W a; signed char b[16]; }) w).b[1];
+  return r + f;
+}