This change ensures that the representation aspects Atomic, Independent and Volatile_Full_Access are copied from the base type to the subtype when it is declared with an explicit constraint.
For the following package: package P is type Bit is mod 2**1 with Size => 1; type UInt2 is mod 2**2 with Size => 2; type UInt22 is mod 2**22 with Size => 22; type MODE_ENUM is ( Function_0_Default, Function_1, Function_2, Function_3, Function_4, Function_5, Function_6, Function_7) with Size => 3; type EPD_ENUM is ( Disable_Pull_Down, Enable_Pull_Down) with Size => 1; type EPUN_ENUM is ( Enable_Pull_Up, Disable_Pull_Up) with Size => 1; type EHS_ENUM is ( Slow_Low_Noise_With, Fast_Medium_Noise_W) with Size => 1; type EZI_ENUM is ( Disable_Input_Buffer, Enable_Input_Buffer) with Size => 1; type ZIF_ENUM is ( Enable_Input_Glitch, Disable_Input_Glitch) with Size => 1; type EHD_ENUM is ( Normal_Drive_4_Ma_D, Medium_Drive_8_Ma_D, High_Drive_14_Ma_Dr, Ultra_High_Drive_20) with Size => 2; type Pin_Type is (Normal_Drive, High_Drive, High_Speed); type SFS_Register(Pin : Pin_Type := Normal_Drive) is record MODE : MODE_ENUM; EPD : EPD_ENUM; EPUN : EPUN_ENUM; EZI : EZI_ENUM; ZIF : ZIF_ENUM; RESERVED : UInt22; case Pin is when Normal_Drive => ND_EHS_RESERVED : Bit; ND_EHD_RESERVED : UInt2; when High_Drive => EHD : EHD_ENUM; HD_EHS_RESERVED : Bit; when High_Speed => EHS : EHS_ENUM; HS_EHD_RESERVED : UInt2; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access; for SFS_Register use record MODE at 0 range 0 .. 2; EPD at 0 range 3 .. 3; EPUN at 0 range 4 .. 4; ND_EHS_RESERVED at 0 range 5 .. 5; HD_EHS_RESERVED at 0 range 5 .. 5; EHS at 0 range 5 .. 5; EZI at 0 range 6 .. 6; ZIF at 0 range 7 .. 7; ND_EHD_RESERVED at 0 range 8 .. 9; EHD at 0 range 8 .. 9; HS_EHD_RESERVED at 0 range 8 .. 9; RESERVED at 0 range 10 .. 31; end record; type Arr is array (Integer range <>) of SFS_Register(Normal_Drive); end P; the components of the Arr type must inherit the Volatile_Full_Access aspect. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-08 Eric Botcazou <ebotca...@adacore.com> * sem_util.ads (Set_Rep_Info): New inline procedure. * sem_util.adb (Set_Rep_Info): Implement it. * sem_ch3.adb (Process_Subtype): If the case of a constraint present, always copy the representation aspects onto the subtype.
Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 251877) +++ sem_ch3.adb (working copy) @@ -21556,9 +21556,11 @@ Error_Msg_N ("invalid subtype mark in subtype indication", S); end case; - -- Size and Convention are always inherited from the base type + -- Size, Alignment, Representation aspects and Convention are always + -- inherited from the base type. Set_Size_Info (Def_Id, (Subtype_Mark_Id)); + Set_Rep_Info (Def_Id, (Subtype_Mark_Id)); Set_Convention (Def_Id, Convention (Subtype_Mark_Id)); return Def_Id; Index: sem_util.adb =================================================================== --- sem_util.adb (revision 251880) +++ sem_util.adb (working copy) @@ -21659,6 +21659,20 @@ end if; end Set_Referenced_Modified; + ------------------ + -- Set_Rep_Info -- + ------------------ + + procedure Set_Rep_Info (T1, T2 : Entity_Id) is + begin + Set_Is_Atomic (T1, Is_Atomic (T2)); + Set_Is_Independent (T1, Is_Independent (T2)); + Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2)); + if Is_Base_Type (T1) then + Set_Is_Volatile (T1, Is_Volatile (T2)); + end if; + end Set_Rep_Info; + ---------------------------- -- Set_Scope_Is_Transient -- ---------------------------- Index: sem_util.ads =================================================================== --- sem_util.ads (revision 251875) +++ sem_util.ads (working copy) @@ -2473,6 +2473,12 @@ -- (Referenced_As_LHS if Out_Param is False, Referenced_As_Out_Parameter -- if Out_Param is True) is set True, and the other flag set False. + procedure Set_Rep_Info (T1, T2 : Entity_Id); + pragma Inline (Set_Rep_Info); + -- Copies the Is_Atomic, Is_Independent and Is_Volatile_Full_Access flags + -- from sub(type) entity T2 to (sub)type entity T1, as well as Is_Volatile + -- if T1 is a base type. + procedure Set_Scope_Is_Transient (V : Boolean := True); -- Set the flag Is_Transient of the current scope