https://gcc.gnu.org/g:62cd58056282f2fb6002bb94a024dcfd9d231a33
commit r17-1210-g62cd58056282f2fb6002bb94a024dcfd9d231a33 Author: Eric Botcazou <[email protected]> Date: Fri Jan 23 09:28:38 2026 +0100 ada: Fix Scalar_Storage_Order not honored for misaligned wrapped scalar 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. Diff: --- 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 f4fc0cec8286..f74b6361b404 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
