]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (gnat_to_gnu_entity): Do not convert the expression to the nominal type if...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 30 Aug 2011 16:15:49 +0000 (16:15 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 30 Aug 2011 16:15:49 +0000 (16:15 +0000)
* gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Do not convert
the expression to the nominal type if the latter is a record type with
a variant part and the type of the former is a record type without one.

Co-Authored-By: Laurent Rougé <laurent.rouge@menta.fr>
From-SVN: r178331

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

index a9fa83c7b2d9593e70cc43dc71b2b3f753232876..5bc7819d361cbe46acf731850ea96463ad9cb2e7 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Do not convert
+       the expression to the nominal type if the latter is a record type with
+       a variant part and the type of the former is a record type without one.
+
 2011-08-30  Yannick Moy  <moy@adacore.com>
 
        * exp_aggr.adb, exp_ch11.adb, exp_prag.adb: Remove early exit during
index 512c05ecb158a833345da1000fe82e9d9166686b..54903cfc4037ef57de17a11597cdb03cc5aef2ff 100644 (file)
@@ -1124,13 +1124,19 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
           is a padded record whose field is of self-referential size.  In
           the former case, converting will generate unnecessary evaluations
           of the CONSTRUCTOR to compute the size and in the latter case, we
-          want to only copy the actual data.  */
+          want to only copy the actual data.  Also don't convert to a record
+          type with a variant part from a record type without one, to keep
+          the object simpler.  */
        if (gnu_expr
            && TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE
            && !CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type))
            && !(TYPE_IS_PADDING_P (gnu_type)
                 && CONTAINS_PLACEHOLDER_P
-                   (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type))))))
+                   (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type)))))
+           && !(TREE_CODE (gnu_type) == RECORD_TYPE
+                && TREE_CODE (TREE_TYPE (gnu_expr)) == RECORD_TYPE
+                && get_variant_part (gnu_type) != NULL_TREE
+                && get_variant_part (TREE_TYPE (gnu_expr)) == NULL_TREE))
          gnu_expr = convert (gnu_type, gnu_expr);
 
        /* If this is a pointer that doesn't have an initializing expression,
@@ -1350,13 +1356,19 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
           is a padded record whose field is of self-referential size.  In
           the former case, converting will generate unnecessary evaluations
           of the CONSTRUCTOR to compute the size and in the latter case, we
-          want to only copy the actual data.  */
+          want to only copy the actual data.  Also don't convert to a record
+          type with a variant part from a record type without one, to keep
+          the object simpler.  */
        if (gnu_expr
            && TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE
            && !CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type))
            && !(TYPE_IS_PADDING_P (gnu_type)
                 && CONTAINS_PLACEHOLDER_P
-                   (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type))))))
+                   (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type)))))
+           && !(TREE_CODE (gnu_type) == RECORD_TYPE
+                && TREE_CODE (TREE_TYPE (gnu_expr)) == RECORD_TYPE
+                && get_variant_part (gnu_type) != NULL_TREE
+                && get_variant_part (TREE_TYPE (gnu_expr)) == NULL_TREE))
          gnu_expr = convert (gnu_type, gnu_expr);
 
        /* If this name is external or there was a name specified, use it,
index 0820eaf92fbd6c1ada3b9e84262f654075e375c5..1a1771f7d26101096615dcde9afdc706c28957b5 100644 (file)
@@ -1,3 +1,11 @@
+2011-08-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/aggr3.ads: New test.
+       * gnat.dg/specs/aggr3_pkg.ads: New helper.
+
+       * gnat.dg/specs/aggr1.ads: Remove superfluous space.
+       * gnat.dg/specs/aggr2.ads: Likewise.
+
 2011-08-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/45170
        * gcc.dg/pie-link.c: Use target pie.
 
 2011-06-10  Eric Botcazou  <ebotcazou@adacore.com>
-           Laurent Rougé  <laurent.rouge@menta.fr>
+           Laurent Roug  <laurent.rouge@menta.fr>
 
        * gcc.dg/20020503-1.c: Add back -mflat option on the SPARC.
        * gcc.target/sparc/sparc-ret.c: Skip if -mflat is passed.
index 6c766351374104b6df2b9371a5f4c4584837cc96..f26f4999b49e98cd82a1cf42256045ec44c5bb44 100644 (file)
@@ -1,4 +1,4 @@
---  { dg-do compile }
+-- { dg-do compile }
 
 package aggr1 is
    type Buffer_Array is array (1 .. 2 ** 23) of Integer;
index 8f7ea871733cc7fe4d3f9cc1d230bb8a92a7b579..00bc44f15d82a14949cb548f7fce329a8c1e4962 100644 (file)
@@ -1,4 +1,4 @@
---  { dg-do compile }
+-- { dg-do compile }
 
 package Aggr2 is
 
diff --git a/gcc/testsuite/gnat.dg/specs/aggr3.ads b/gcc/testsuite/gnat.dg/specs/aggr3.ads
new file mode 100644 (file)
index 0000000..09b4466
--- /dev/null
@@ -0,0 +1,18 @@
+-- { dg-do compile }
+
+with Aggr3_Pkg; use Aggr3_Pkg;
+
+package Aggr3 is
+
+   type Enum is (One);
+
+   type R (D : Enum := One) is
+   record
+      case D is
+        when One => The_T : T; 
+      end case;
+   end record;
+
+   My_R : R := (D => One, The_T => My_T);
+
+end Aggr3;
diff --git a/gcc/testsuite/gnat.dg/specs/aggr3_pkg.ads b/gcc/testsuite/gnat.dg/specs/aggr3_pkg.ads
new file mode 100644 (file)
index 0000000..769426e
--- /dev/null
@@ -0,0 +1,9 @@
+package Aggr3_Pkg is
+
+   type Root is abstract tagged null record;
+
+   type T is new Root with null record;
+
+   My_T : T;
+
+end Aggr3_Pkg;