https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121527
--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
The following avoids such situation:
diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index 032f2770484..d88516e8e41 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -1295,7 +1295,9 @@ build_access_from_expr_1 (tree expr, gimple *stmt, bool
write)
and not the result type. Ada produces such statements. We are also
capable of handling the topmost V_C_E but not any of those buried in
other
handled components. */
- if (TREE_CODE (expr) == VIEW_CONVERT_EXPR)
+ if (TREE_CODE (expr) == VIEW_CONVERT_EXPR
+ && operand_equal_p (TYPE_SIZE (TREE_TYPE (expr)),
+ TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)))))
expr = TREE_OPERAND (expr, 0);
if (contains_view_convert_expr_p (expr))
There is also
/* Search for an access representative for the given expression EXPR and
return it or NULL if it cannot be found. */
static struct access *
get_access_for_expr (tree expr)
{
poly_int64 poffset, psize, pmax_size;
HOST_WIDE_INT offset, max_size;
tree base;
bool reverse;
/* FIXME: This should not be necessary but Ada produces V_C_Es with a type of
a different size than the size of its argument and we need the latter
one. */
if (TREE_CODE (expr) == VIEW_CONVERT_EXPR)
expr = TREE_OPERAND (expr, 0);
but this example shows we need the former, not the latter. In fact I wonder
whether the above is not simply always broken. The following fixes the
bug as well:
diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index 032f2770484..9bf0672cf41 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -4086,12 +4089,6 @@ get_access_for_expr (tree expr)
tree base;
bool reverse;
- /* FIXME: This should not be necessary but Ada produces V_C_Es with a type
of
- a different size than the size of its argument and we need the latter
- one. */
- if (TREE_CODE (expr) == VIEW_CONVERT_EXPR)
- expr = TREE_OPERAND (expr, 0);
-
base = get_ref_base_and_extent (expr, &poffset, &psize, &pmax_size,
&reverse);
if (!known_size_p (pmax_size)