decl.c (gnat_to_gnu_entity): Create TYPE_DECL for the padded type built in order...
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 23 Mar 2011 09:38:07 +0000 (09:38 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 23 Mar 2011 09:38:07 +0000 (09:38 +0000)
* gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Create TYPE_DECL
for the padded type built in order to support a specified alignment.
Fix incorrect formatting.

From-SVN: r171342

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

index b2d88618040114dbe194ed6736c562dbadd83018..1ae98609ba6352351983bce3cc55915895d78b70 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Create TYPE_DECL
+       for the padded type built in order to support a specified alignment.
+       Fix incorrect formatting.
+
 2011-03-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR bootstrap/48216
index 2f9b2ecec23621be6b483d57d4cf9e7d5d2adf6a..313841ab873ea27c80feddd071bc3e2d18583344 100644 (file)
@@ -687,6 +687,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
        if (kind != E_Exception && Known_Alignment (gnat_entity))
          {
            gcc_assert (Present (Alignment (gnat_entity)));
+
            align = validate_alignment (Alignment (gnat_entity), gnat_entity,
                                        TYPE_ALIGN (gnu_type));
 
@@ -695,9 +696,20 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
            if (Present (Address_Clause (gnat_entity)))
              align = 0;
            else
-             gnu_type
-               = maybe_pad_type (gnu_type, NULL_TREE, align, gnat_entity,
-                                 false, false, definition, true);
+             {
+               tree orig_type = gnu_type;
+
+               gnu_type
+                 = maybe_pad_type (gnu_type, NULL_TREE, align, gnat_entity,
+                                   false, false, definition, true);
+
+               /* If a padding record was made, declare it now since it will
+                  never be declared otherwise.  This is necessary to ensure
+                  that its subtrees are properly marked.  */
+               if (gnu_type != orig_type && !DECL_P (TYPE_NAME (gnu_type)))
+                 create_type_decl (TYPE_NAME (gnu_type), gnu_type, NULL, true,
+                                   debug_info_p, gnat_entity);
+             }
          }
 
        /* If we are defining the object, see if it has a Size and validate it
@@ -865,16 +877,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
        if (Is_Constr_Subt_For_UN_Aliased (Etype (gnat_entity))
            && Is_Array_Type (Etype (gnat_entity))
            && !type_annotate_only)
-       {
-         tree gnu_fat
-           = TREE_TYPE (gnat_to_gnu_type (Base_Type (Etype (gnat_entity))));
-
-         gnu_type
-           = build_unc_object_type_from_ptr (gnu_fat, gnu_type,
-                                             concat_name (gnu_entity_name,
-                                                          "UNC"),
-                                             debug_info_p);
-       }
+         {
+           tree gnu_fat
+             = TREE_TYPE (gnat_to_gnu_type (Base_Type (Etype (gnat_entity))));
+           gnu_type
+             = build_unc_object_type_from_ptr (gnu_fat, gnu_type,
+                                               concat_name (gnu_entity_name,
+                                                            "UNC"),
+                                               debug_info_p);
+         }
 
 #ifdef MINIMUM_ATOMIC_ALIGNMENT
        /* If the size is a constant and no alignment is specified, force
index bd44c6c9ab8c6014dc4a1435c46ee5bbdb7d2776..8bc06037175d9e67f59e25cd16ffb88db4b3ecde 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/array14.ad[sb]: New test.
+       * gnat.dg/array14_pkg.ads: New helper.
+
 2011-03-22  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.c-torture/execute/920501-8.x: Remove.
diff --git a/gcc/testsuite/gnat.dg/array14.adb b/gcc/testsuite/gnat.dg/array14.adb
new file mode 100644 (file)
index 0000000..aed2901
--- /dev/null
@@ -0,0 +1,35 @@
+-- { dg-do compile }\r
+-- { dg-options "-gnatws" }\r
+\r
+with Array14_Pkg; use Array14_Pkg;\r
+\r
+package body Array14 is\r
+\r
+  package Nested is\r
+\r
+    Length : constant SSE.Storage_Count := Length2;\r
+\r
+    subtype Encoded_Index_Type is SSE.Storage_Count range 1 .. Length;\r
+    subtype Encoded_Type is SSE.Storage_Array (Encoded_Index_Type'Range);\r
+\r
+    procedure Encode (Input : in Integer; Output : out Encoded_Type);\r
+\r
+  end;\r
+\r
+  package body Nested is\r
+\r
+    procedure Encode (Input : in Integer; Output : out Encoded_Type) is\r
+    begin\r
+      Encode2 (Input, Output);\r
+    end;\r
+\r
+  end;\r
+\r
+  procedure Init is\r
+    O : Nested.Encoded_Type;\r
+    for O'Alignment use 4;\r
+  begin\r
+    null;\r
+  end;\r
+\r
+end Array14;\r
diff --git a/gcc/testsuite/gnat.dg/array14.ads b/gcc/testsuite/gnat.dg/array14.ads
new file mode 100644 (file)
index 0000000..9d38eeb
--- /dev/null
@@ -0,0 +1,5 @@
+package Array14 is\r
+\r
+  procedure Init;\r
+\r
+end Array14;\r
diff --git a/gcc/testsuite/gnat.dg/array14_pkg.ads b/gcc/testsuite/gnat.dg/array14_pkg.ads
new file mode 100644 (file)
index 0000000..8040905
--- /dev/null
@@ -0,0 +1,16 @@
+with System.Storage_Elements;\r
+\r
+package Array14_Pkg is\r
+\r
+  package SSE renames System.Storage_Elements;\r
+\r
+  function Parity_Byte_Count return SSE.Storage_Count;\r
+\r
+  Length2 : constant SSE.Storage_Count := Parity_Byte_Count;\r
+\r
+  subtype Encoded_Index_Type2 is SSE.Storage_Count range 1 .. Length2;\r
+  subtype Encoded_Type2 is SSE.Storage_Array (Encoded_Index_Type2'Range);\r
+\r
+  procedure Encode2 (Input : in Integer; Output : out Encoded_Type2);\r
+\r
+end Array14_Pkg;\r