decl.c (build_subst_list): Convert the expression of the constraint to the type of...
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 21 Oct 2009 10:20:06 +0000 (10:20 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 21 Oct 2009 10:20:06 +0000 (10:20 +0000)
* gcc-interfaces/decl.c (build_subst_list): Convert the expression of
the constraint to the type of the discriminant.

From-SVN: r153054

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

index 5d69cee059425b180402975aeedb71f1d18a6417..e4761d82e1fed09bd31af8be4fc7b195375225ca 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interfaces/decl.c (build_subst_list): Convert the expression of
+       the constraint to the type of the discriminant.
+
 2009-10-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interfaces/decl.c (gnat_to_gnu_entity): Do not create a new
index 70ced844fb6af81ef802b4ddff4f32285e844a9e..d0b52f2e7457b855fd6f3d832ce04786afe1dd90 100644 (file)
@@ -7374,12 +7374,16 @@ build_subst_list (Entity_Id gnat_subtype, Entity_Id gnat_type, bool definition)
        gnat_value = Next_Elmt (gnat_value))
     /* Ignore access discriminants.  */
     if (!Is_Access_Type (Etype (Node (gnat_value))))
-      gnu_list = tree_cons (gnat_to_gnu_field_decl (gnat_discrim),
-                           elaborate_expression
-                           (Node (gnat_value), gnat_subtype,
-                            get_entity_name (gnat_discrim), definition,
-                            true, false),
-                           gnu_list);
+      {
+       tree gnu_field = gnat_to_gnu_field_decl (gnat_discrim);
+       gnu_list = tree_cons (gnu_field,
+                             convert (TREE_TYPE (gnu_field),
+                                      elaborate_expression
+                                      (Node (gnat_value), gnat_subtype,
+                                       get_entity_name (gnat_discrim),
+                                       definition, true, false)),
+                             gnu_list);
+      }
 
   return gnu_list;
 }
index ae7687def7058156059400c170c377c3ffbe3f4d..e827cc9eec7425f5130a6d82ed2f5b0f719206d4 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/discr22.adb: New test.
+
 2009-10-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/loop_optimization7.ad[sb]: New test.
diff --git a/gcc/testsuite/gnat.dg/discr22.adb b/gcc/testsuite/gnat.dg/discr22.adb
new file mode 100644 (file)
index 0000000..af4f9ab
--- /dev/null
@@ -0,0 +1,23 @@
+-- { dg-do compile }
+-- { dg-options "-gnatws" }
+
+procedure Discr22 is
+
+   subtype Precision is Integer range 1 .. 5;
+
+   type Rec(D1 : Precision; D2 : Integer) is record
+      case D1 is
+         when 1 => I : Integer;
+         when others => null;
+      end case;
+   end record;
+   for Rec use record
+      D1 at 0 range 0 .. 7;
+   end record;
+
+   P : Precision;
+   X : Rec(P, 0);
+
+begin
+   null;
+end;