From: Steve Baird <ba...@adacore.com> If the discriminants of an immutably limited record type have defaults, then it is safe to assume that a discriminant of an object of this type will never change once it is initialized. In some cases, this means that the default discriminant values can be treated like a constraint for purposes of determining the amount of storage needed for an unconstrained object. However, it is not safe to perform this optimization when determining the size needed for an unconstrained component of an enclosing type. This optimization was sometimes being incorrectly performed in this case. This could save storage in some cases, but in other cases a constraint check could incorrectly fail when initializing a component of an aggregate if the discriminant values of the component differ from the default values.
gcc/ada/ * sem_ch3.adb (Analyze_Component_Declaration): Remove Build_Default_Subtype_OK call and code that could only executed in the case where the removed call would have returned True. Other calls to Build_Default_Subtype_Ok are unaffected by this change. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch3.adb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 85019dfffa5..ed337f5408e 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -1868,7 +1868,6 @@ package body Sem_Ch3 is ----------------------------------- procedure Analyze_Component_Declaration (N : Node_Id) is - Loc : constant Source_Ptr := Sloc (Component_Definition (N)); Id : constant Entity_Id := Defining_Identifier (N); E : constant Node_Id := Expression (N); Typ : constant Node_Id := @@ -2205,23 +2204,6 @@ package body Sem_Ch3 is end if; end if; - -- When possible, build the default subtype - - if Build_Default_Subtype_OK (T) then - declare - Act_T : constant Entity_Id := Build_Default_Subtype (T, N); - - begin - Set_Etype (Id, Act_T); - - -- Rewrite component definition to use the constrained subtype - - Rewrite (Component_Definition (N), - Make_Component_Definition (Loc, - Subtype_Indication => New_Occurrence_Of (Act_T, Loc))); - end; - end if; - Set_Original_Record_Component (Id, Id); if Has_Aspects (N) then -- 2.40.0