aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-12-04 10:35:38 +0100
committerRichard Biener <rguenther@suse.de>2023-12-05 14:51:34 +0100
commit68d32d02035fc081384ec6d6fd275e49ffa5d016 (patch)
treea56234c183cfaaabd0ebdfcb29a04c03a9abda4f /gcc/gimplify.cc
parent8ff02df62935429d8956361cfdb897122492523d (diff)
downloadgcc-68d32d02035fc081384ec6d6fd275e49ffa5d016.zip
gcc-68d32d02035fc081384ec6d6fd275e49ffa5d016.tar.gz
gcc-68d32d02035fc081384ec6d6fd275e49ffa5d016.tar.bz2
middle-end/112830 - avoid gimplifying non-default addr-space assign to memcpy
The following avoids turning aggregate copy involving non-default address-spaces to memcpy since that is not prepared for that. GIMPLE verification no longer accepts WITH_SIZE_EXPR in aggregate copies, the following re-allows that for the RHS. I also needed to adjust one assert in DCE. get_memory_address is used for string builtin expansion, so instead of fixing that up for non-generic address-spaces I've put an assert there. I'll note that the same issue exists for initialization from an empty CTOR which we gimplify to a memset call but since we are not prepared to handle RTL expansion of the original VLA init and I failed to provide test coverage (without extending the GNU C extension for VLA structs) and the Ada frontend (or other frontends) to not have address-space support the patch instead asserts we only see generic address-spaces there. PR middle-end/112830 * gimplify.cc (gimplify_modify_expr): Avoid turning aggregate copy of non-generic address-spaces to memcpy. (gimplify_modify_expr_to_memcpy): Assert we are dealing with a copy inside the generic address-space. (gimplify_modify_expr_to_memset): Likewise. * tree-cfg.cc (verify_gimple_assign_single): Allow WITH_SIZE_EXPR as part of the RHS of an assignment. * builtins.cc (get_memory_address): Assert we are dealing with the generic address-space. * tree-ssa-dce.cc (ref_may_be_aliased): Handle WITH_SIZE_EXPR. * gcc.target/avr/pr112830.c: New testcase. * gcc.target/i386/pr112830.c: Likewise.
Diffstat (limited to 'gcc/gimplify.cc')
-rw-r--r--gcc/gimplify.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 02f85e7..342e43a 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -4887,6 +4887,8 @@ gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value,
to = TREE_OPERAND (*expr_p, 0);
from = TREE_OPERAND (*expr_p, 1);
+ gcc_assert (ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (to)))
+ && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (from))));
/* Mark the RHS addressable. Beware that it may not be possible to do so
directly if a temporary has been created by the gimplification. */
@@ -4945,6 +4947,7 @@ gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value,
/* Now proceed. */
to = TREE_OPERAND (*expr_p, 0);
+ gcc_assert (ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (to))));
to_ptr = build_fold_addr_expr_loc (loc, to);
gimplify_arg (&to_ptr, seq_p, loc);
@@ -6466,8 +6469,9 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
if (TREE_CODE (from) == CONSTRUCTOR)
return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p);
-
- if (is_gimple_addressable (from))
+ else if (is_gimple_addressable (from)
+ && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (*to_p)))
+ && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (from))))
{
*from_p = from;
return gimplify_modify_expr_to_memcpy (expr_p, size, want_value,