bitint: Fix tree node sharing bug [PR114209]
Checks
Commit Message
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
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.
Jakub
Comments
On Mon, 4 Mar 2024, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 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.jj 2024-03-01 11:04:44.623537149 +0100
> +++ gcc/gimple-lower-bitint.cc 2024-03-03 19:18:30.017909558 +0100
> @@ -620,7 +620,7 @@ bitint_large_huge::limb_access (tree typ
> 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 *s
> = 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
> --- gcc/testsuite/gcc.dg/bitint-97.c.jj 2024-03-03 18:59:31.084588944 +0100
> +++ gcc/testsuite/gcc.dg/bitint-97.c 2024-03-03 19:16:50.114284071 +0100
> @@ -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;
> +}
>
> Jakub
>
>
@@ -620,7 +620,7 @@ bitint_large_huge::limb_access (tree typ
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 *s
= 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
@@ -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;
+}