From: Jakub Jelinek Date: Mon, 4 Mar 2024 10:15:07 +0000 (+0100) Subject: bitint: Fix tree node sharing bug [PR114209] X-Git-Tag: basepoints/gcc-15~848 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c27148f2f40654a638bcf429633be1c0561529d5;p=thirdparty%2Fgcc.git bitint: Fix tree node sharing bug [PR114209] 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 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. --- diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 15a27126d44a..e3c8518f745f 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -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 index 000000000000..a85997893310 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-97.c @@ -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; +}