[Ada] Fix bogus error on array with overaligned scalar component
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 3 Jul 2019 08:14:15 +0000 (08:14 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Wed, 3 Jul 2019 08:14:15 +0000 (08:14 +0000)
The compiler would wrongly reject an alignment clause larger than 8 on
the component type of an array of scalars, which is valid albeit
pathological.

2019-07-03  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* layout.adb (Layout_Type): Do not set the component size of an
array with a scalar component if the component type is
overaligned.

gcc/testsuite/

* gnat.dg/alignment14.adb: New testcase.

From-SVN: r272968

gcc/ada/ChangeLog
gcc/ada/layout.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/alignment14.adb [new file with mode: 0644]

index 443947c..e932dab 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-03  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * layout.adb (Layout_Type): Do not set the component size of an
+       array with a scalar component if the component type is
+       overaligned.
+
 2019-07-03  Ed Schonberg  <schonberg@adacore.com>
 
        * inline.adb (Make_Loop_Labels_Unique):  New procedure to modify
index f5f6aa8..5637946 100644 (file)
@@ -443,9 +443,12 @@ package body Layout is
             Set_RM_Size (E, Esize (E));
          end if;
 
-         --  For array base types, set component size if object size of the
+         --  For array base types, set the component size if object size of the
          --  component type is known and is a small power of 2 (8, 16, 32, 64),
-         --  since this is what will always be used.
+         --  since this is what will always be used, except if a very large
+         --  alignment was specified and so Adjust_Esize_For_Alignment gave up
+         --  because, in this case, the object size is not a multiple of the
+         --  alignment and, therefore, cannot be the component size.
 
          if Ekind (E) = E_Array_Type and then Unknown_Component_Size (E) then
             declare
@@ -458,6 +461,9 @@ package body Layout is
                if Present (CT)
                  and then Is_Scalar_Type (CT)
                  and then Known_Static_Esize (CT)
+                 and then not (Known_Alignment (CT)
+                                and then Alignment_In_Bits (CT) >
+                                              Standard_Long_Long_Integer_Size)
                then
                   declare
                      S : constant Uint := Esize (CT);
index 925e8b7..245bf25 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-03  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/alignment14.adb: New testcase.
+
 2019-07-03  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/predicate4.adb, gnat.dg/predicate4_pkg.ads: New
diff --git a/gcc/testsuite/gnat.dg/alignment14.adb b/gcc/testsuite/gnat.dg/alignment14.adb
new file mode 100644 (file)
index 0000000..48ef6bd
--- /dev/null
@@ -0,0 +1,17 @@
+--  { dg-do compile }
+
+procedure Alignment14 is
+
+  type My_Int1 is new Integer;
+  for My_Int1'Alignment use 8;
+
+  type Arr1 is array (1 .. 2) of My_Int1;
+
+  type My_Int2 is new Integer;
+  for My_Int2'Alignment use 16;
+
+  type Arr2 is array (1 .. 2) of My_Int2;
+
+begin
+   null;
+end Alignment14;