]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix Scalar_Storage_Order not honored for misaligned wrapped scalar
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 23 Jan 2026 08:28:38 +0000 (09:28 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 2 Jun 2026 08:42:32 +0000 (10:42 +0200)
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.

gcc/ada/gcc-interface/utils.cc

index f4fc0cec8286a6185758100eefc94733a324c7f8..f74b6361b404dff5e41f39b24a1dfee86533430b 100644 (file)
@@ -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