OSDN Git Service

* gcc-interface/utils.c (convert): When converting to a padded type
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 17 Oct 2009 11:17:27 +0000 (11:17 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 17 Oct 2009 11:17:27 +0000 (11:17 +0000)
with an inner type of self-referential size, pad the expression before
doing the unchecked conversion.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@152935 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/aggr11.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/aggr11_pkg.ads [new file with mode: 0644]

index 80103fb..c5388ac 100644 (file)
@@ -1,5 +1,11 @@
 2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
 
+       * gcc-interface/utils.c (convert): When converting to a padded type
+       with an inner type of self-referential size, pad the expression before
+       doing the unchecked conversion.
+
+2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
+
        * gcc-interface/utils2.c (build_binary_op) <ARRAY_RANGE_REF>: Mak
        sure the element type is consistent.
 
index 86575b5..a8225b0 100644 (file)
@@ -3856,12 +3856,17 @@ convert (tree type, tree expr)
                     == TYPE_NAME (TREE_TYPE (TYPE_FIELDS (type))))))
        return convert (type, TREE_OPERAND (expr, 0));
 
-      /* If the result type is a padded type with a self-referentially-sized
-        field and the expression type is a record, do this as an unchecked
-        conversion.  */
+      /* If the inner type is of self-referential size and the expression type
+        is a record, do this as an unchecked conversion.  But first pad the
+        expression if possible to have the same size on both sides.  */
       if (TREE_CODE (etype) == RECORD_TYPE
          && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type))))
-       return unchecked_convert (type, expr, false);
+       {
+         if (TREE_CONSTANT (TYPE_SIZE (etype)))
+           expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty,
+                           false, false, false, true), expr);
+         return unchecked_convert (type, expr, false);
+       }
 
       /* If we are converting between array types with variable size, do the
         final conversion as an unchecked conversion, again to avoid the need
index acbbe36..2e9f67d 100644 (file)
@@ -1,5 +1,10 @@
 2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
 
+       * gnat.dg/aggr11.adb: New test.
+       * gnat.dg/aggr11_pkg.ads: New helper.
+
+2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
+
        * gnat.dg/slice8.adb: New test.
        * gnat.dg/slice8_pkg1.ads: New helper.
        * gnat.dg/slice8_pkg2.ads: Likewise.
diff --git a/gcc/testsuite/gnat.dg/aggr11.adb b/gcc/testsuite/gnat.dg/aggr11.adb
new file mode 100644 (file)
index 0000000..1771d62
--- /dev/null
@@ -0,0 +1,17 @@
+-- { dg-do compile }\r
+-- { dg-options "-O" }\r
+\r
+with Aggr11_Pkg; use Aggr11_Pkg;\r
+\r
+procedure Aggr11 is\r
+\r
+  A : Arr := ((1 => (Kind  => No_Error, B => True),\r
+               2 => (Kind => Error),\r
+               3 => (Kind => Error),\r
+               4 => (Kind  => No_Error, B => True),\r
+               5 => (Kind  => No_Error, B => True),\r
+               6 => (Kind  => No_Error, B => True)));\r
+\r
+begin\r
+   null;\r
+end;\r
diff --git a/gcc/testsuite/gnat.dg/aggr11_pkg.ads b/gcc/testsuite/gnat.dg/aggr11_pkg.ads
new file mode 100644 (file)
index 0000000..3700860
--- /dev/null
@@ -0,0 +1,14 @@
+package Aggr11_Pkg is\r
+\r
+   type Error_Type is (No_Error, Error);\r
+\r
+   type Rec (Kind : Error_Type := No_Error) is record\r
+     case Kind is\r
+       when Error => null;\r
+       when others => B : Boolean;\r
+     end case;\r
+   end record;\r
+\r
+   type Arr is array (1..6) of Rec;\r
+\r
+end Aggr11_Pkg;\r