decl.c (gnat_to_gnu_entity): When there is a representation clause on an extension...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 15 May 2017 08:00:41 +0000 (08:00 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 15 May 2017 08:00:41 +0000 (08:00 +0000)
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Type>: When there
is a representation clause on an extension, propagate the alignment of
the parent type only if the platform requires strict alignment.

From-SVN: r248049

gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c

index 0dd6d04bc7c1cba586d5ce5b8d01be3a15e8fe30..dc2916e5278f02354451b07bd5d21882dae171d4 100644 (file)
@@ -1,3 +1,9 @@
+2017-05-15  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Type>: When there
+       is a representation clause on an extension, propagate the alignment of
+       the parent type only if the platform requires strict alignment.
+
 2017-05-12  Eric Botcazou  <ebotcazou@adacore.com>
 
        * system-linux-arm.ads (Memory_Size): Use Long_Integer'Size
index af4574d2c622bd8e348766d8b2b049c9a28bc879..b39b75a852b106f817101c777cafb311c888c5bc 100644 (file)
@@ -204,6 +204,7 @@ static tree elaborate_expression_2 (tree, Entity_Id, const char *, bool, bool,
 static tree elaborate_reference (tree, Entity_Id, bool, tree *);
 static tree gnat_to_gnu_component_type (Entity_Id, bool, bool);
 static tree gnat_to_gnu_subprog_type (Entity_Id, bool, bool, tree *);
+static int adjust_packed (tree, tree, int);
 static tree gnat_to_gnu_field (Entity_Id, tree, int, bool, bool);
 static tree gnu_ext_name_for_subprog (Entity_Id, tree);
 static tree change_qualified_type (tree, int);
@@ -3094,6 +3095,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
            Entity_Id gnat_parent = Parent_Subtype (gnat_entity);
            tree gnu_dummy_parent_type = make_node (RECORD_TYPE);
            tree gnu_parent;
+           int parent_packed = 0;
 
            /* A major complexity here is that the parent subtype will
               reference our discriminants in its Stored_Constraint list.
@@ -3172,7 +3174,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
               be created with a component clause below, then we need
               to apply the same adjustment as in gnat_to_gnu_field.  */
            if (has_rep && TYPE_ALIGN (gnu_type) < TYPE_ALIGN (gnu_parent))
-             SET_TYPE_ALIGN (gnu_type, TYPE_ALIGN (gnu_parent));
+             {
+               /* ??? For historical reasons, we do it on strict-alignment
+                  platforms only, where it is really required.  This means
+                  that a confirming representation clause will change the
+                  behavior of the compiler on the other platforms.  */
+               if (STRICT_ALIGNMENT)
+                 SET_TYPE_ALIGN (gnu_type, TYPE_ALIGN (gnu_parent));
+               else
+                 parent_packed
+                   = adjust_packed (gnu_parent, gnu_type, parent_packed);
+             }
 
            /* Finally we fix up both kinds of twisted COMPONENT_REF we have
               initially built.  The discriminants must reference the fields
@@ -3218,7 +3230,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
                                   ? TYPE_SIZE (gnu_parent) : NULL_TREE,
                                   has_rep
                                   ? bitsize_zero_node : NULL_TREE,
-                                  0, 1);
+                                  parent_packed, 1);
            DECL_INTERNAL_P (gnu_field) = 1;
            TREE_OPERAND (gnu_get_parent, 1) = gnu_field;
            TYPE_FIELDS (gnu_type) = gnu_field;