From: Eric Botcazou <[email protected]>

This occurs when the construct is totally scalarized by the SRA pass.

gcc/ada/ChangeLog:

        * gcc-interface/utils.cc (maybe_pad_type): Propagate the flag
        TYPE_REVERSE_STORAGE_ORDER from the inner type to the record type
        if the former is also an aggregate type.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/gcc-interface/utils.cc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index f4fc0cec828..f74b6361b40 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1763,6 +1763,16 @@ maybe_pad_type (tree type, tree size, unsigned int align,
               size_binop (EXACT_DIV_EXPR, TYPE_SIZE (record),
                           bitsize_unit_node));
 
+  /* Propagate the storage order from an aggregate type to the padded type.
+     Ideally this should not be necessary, because the flag on the padded
+     type has no semantic effects given that its only field is not scalar.
+     However, when the aggregate type contains a single scalar field, SRA
+     may totally scalarize the padded type without taking into account the
+     intermediate aggregate type and, therefore, may test the flag on the
+     former instead of the latter to generate a reverse memory access.  */
+  if (AGGREGATE_TYPE_P (type))
+    TYPE_REVERSE_STORAGE_ORDER (record) = TYPE_REVERSE_STORAGE_ORDER (type);
+
   /* If we are changing the alignment and the input type is a record with
      BLKmode and a small constant size, try to make a form that has an
      integral mode.  This might allow the padding record to also have an
-- 
2.53.0

Reply via email to