]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add bypass for internal fields on strict-alignment platforms
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 26 Aug 2024 09:16:41 +0000 (11:16 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Sep 2024 08:10:13 +0000 (10:10 +0200)
This is required to support misalignment of tagged types in legacy code.

gcc/ada/

* gcc-interface/trans.cc (addressable_p) <COMPONENT_REF>: Add bypass
for internal fields on strict-alignment platforms.

gcc/ada/gcc-interface/trans.cc

index 9e9f5f8dcbac0891ac9354ea5ae97862ce64cc79..92e000686fb2f5daf3dfcc37d7ee950595eafbd7 100644 (file)
@@ -10295,9 +10295,14 @@ addressable_p (tree gnu_expr, tree gnu_type)
                   is guaranteed to be not smaller than that of its most
                   aligned field that is not a bit-field.  However, we need
                   to cope with quirks of ABIs that may misalign fields.  */
-               && DECL_ALIGN (TREE_OPERAND (gnu_expr, 1))
-                  >= default_field_alignment (TREE_OPERAND (gnu_expr, 1),
-                                              TREE_TYPE (gnu_expr)))
+               && (DECL_ALIGN (TREE_OPERAND (gnu_expr, 1))
+                   >= default_field_alignment (TREE_OPERAND (gnu_expr, 1),
+                                               TREE_TYPE (gnu_expr))
+                   /* We do not enforce this on strict-alignment platforms for
+                      internal fields in order to keep supporting misalignment
+                      of tagged types in legacy code.  */
+                   || (!STRICT_ALIGNMENT
+                       && DECL_INTERNAL_P (TREE_OPERAND (gnu_expr, 1)))))
               /* The field of a padding record is always addressable.  */
               || TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_expr, 0))))
              && addressable_p (TREE_OPERAND (gnu_expr, 0), NULL_TREE));