[Ada] Bug box on object of derived array type with repped enumeration index

Message ID 20100617084940.GA17066@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 17, 2010, 8:49 a.m.
The compiler blows up on an object of a derived array type where the index
is of an enumeration type with specified representation and the component
is of a floating-point type. In this case, the derived type and its parent
type were not considered to have the same representation, because the component
size of the parent was not getting set by the front end's layout phase (only
array types with discrete components were set), whereas the derived type
had its component size set properly in Freeze_Type (because its parent type
was treated as packed due to the nonstandard representation of its index).
The layout for array types now sets the component size in the case of arrays
with components of any scalar type. This change also helps avoid expensive
(and unnecessary) representation conversions between derived array types
of this kind.

The package init_scalar_bug.adb, given below, must compile with only the
following warning output (or quietly with -gnatws):

init_scalar_bug.adb:13:11: warning: default initialization of "Result" may modify overlaid storage
init_scalar_bug.adb:13:11: warning: use pragma Import for "Result" to suppress initialization (RM B.1(24))

pragma Initialize_Scalars;

package Float_Arr_Pkg is

   type Repped_Enum is (Enum_1, Enum_2, Enum_3);

   for Repped_Enum use (Enum_1 => 1, Enum_2 => 2, Enum_3 => 3);

   type Float_Array is array (Repped_Enum) of Float;

end Float_Arr_Pkg;

with System;

package Init_Scalar_Bug is

   procedure Proc (Addr : System.Address);

end Init_Scalar_Bug;

pragma Initialize_Scalars;

with Float_Arr_Pkg;

package body Init_Scalar_Bug is

   type New_Float_Array is new Float_Arr_Pkg.Float_Array;

   procedure Proc (Addr : System.Address) is

      Result : New_Float_Array;

      for Result use at Addr;

   end Proc;

end Init_Scalar_Bug;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-17  Gary Dismukes  <dismukes@adacore.com>

	* layout.adb (Layout_Type): Broaden test for setting an array type's
	Component_Size to include all scalar types, not just discrete types
	(components of real types were missed).
	* sem_ch3.adb (Constrain_Index): Add missing setting of First_Literal
	on the itype created for an index (consistent with Make_Index and
	avoids possible Assert_Failures).


Index: sem_ch3.adb
--- sem_ch3.adb	(revision 160843)
+++ sem_ch3.adb	(working copy)
@@ -11071,6 +11071,7 @@  package body Sem_Ch3 is
          Set_Ekind (Def_Id, E_Enumeration_Subtype);
          Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
+         Set_First_Literal     (Def_Id, First_Literal (T));
       end if;
       Set_Size_Info      (Def_Id,                (T));
Index: layout.adb
--- layout.adb	(revision 160834)
+++ layout.adb	(working copy)
@@ -2560,10 +2560,10 @@  package body Layout is
                --  For some reasons, access types can cause trouble, So let's
-               --  just do this for discrete types ???
+               --  just do this for scalar types ???
                if Present (CT)
-                 and then Is_Discrete_Type (CT)
+                 and then Is_Scalar_Type (CT)
                  and then Known_Static_Esize (CT)