decl.c (gnat_to_gnu_field): Adjust again the packing for a field without strict align...
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 11 Oct 2019 09:09:40 +0000 (09:09 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 11 Oct 2019 09:09:40 +0000 (09:09 +0000)
* gcc-interface/decl.c (gnat_to_gnu_field): Adjust again the packing
for a field without strict alignment and with an oversized clause.

From-SVN: r276873

gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/size_clause4.ads [new file with mode: 0644]

index 792db56748130ef503318dcd422b97aeea81b148..ae9fd4c2b6ab68a77635e0b4583d8ba70f1f3291 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_field): Adjust again the packing
+       for a field without strict alignment and with an oversized clause.
+
 2019-10-11  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/decl.c (annotate_value) <INTEGER_CST>: Really test the
index 2c5f5732f74cc8b0e5c35b54f11790ffedc8cf73..b3f8d589682cf4b00af7cc0f611fd97dfcea8635 100644 (file)
@@ -7229,10 +7229,17 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
          && INTEGRAL_TYPE_P (TREE_TYPE (TYPE_FIELDS (gnu_field_type))))
        gnu_field_type = TREE_TYPE (TYPE_FIELDS (gnu_field_type));
 
+      orig_field_type = gnu_field_type;
       gnu_field_type
        = make_type_from_size (gnu_field_type, gnu_size,
                               Has_Biased_Representation (gnat_field));
 
+      /* If the type has been extended, we may need to cap the alignment.  */
+      if (!needs_strict_alignment
+         && gnu_field_type != orig_field_type
+         && tree_int_cst_lt (TYPE_SIZE (orig_field_type), gnu_size))
+       packed = adjust_packed (gnu_field_type, gnu_record_type, packed);
+
       orig_field_type = gnu_field_type;
       gnu_field_type = maybe_pad_type (gnu_field_type, gnu_size, 0, gnat_field,
                                       false, false, definition, true);
index c565dae1a8058870b896e78678c42b9b07a44090..07dc579c7b501b4d078b73cd9e93c8cdff3112d5 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/size_clause4.ads: New test.
+
 2019-10-11  Ilya Leoshkevich  <iii@linux.ibm.com>
 
        PR target/77918
diff --git a/gcc/testsuite/gnat.dg/specs/size_clause4.ads b/gcc/testsuite/gnat.dg/specs/size_clause4.ads
new file mode 100644 (file)
index 0000000..4aa8c8f
--- /dev/null
@@ -0,0 +1,20 @@
+-- { dg-do compile }
+
+with System;
+
+package Size_Clause4 is
+
+  type Rec is record
+    A1 : System.Address;  
+    A2 : System.Address;  
+    I  : aliased Integer; 
+  end record;
+       
+  for Rec use record
+    A1 at 0  range 0 .. 63; 
+    A2 at 8  range 0 .. 63;
+    I  at 16 range 0 .. 31;  
+  end record;
+  for Rec'Size use 160;
+
+end Size_Clause4;