aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2023-06-08 14:59:32 -0700
committerMarc Poulhiès <poulhies@adacore.com>2023-08-01 10:06:45 +0200
commit04c297101019316eb8c3191ffb2ff0bf34f4d869 (patch)
treecea96f70d19cb28f92e07bb4787ea75daa250b91 /gcc
parent46640bafbbe69fbd6960b21ed5a8ed635f99afa5 (diff)
downloadgcc-04c297101019316eb8c3191ffb2ff0bf34f4d869.zip
gcc-04c297101019316eb8c3191ffb2ff0bf34f4d869.tar.gz
gcc-04c297101019316eb8c3191ffb2ff0bf34f4d869.tar.bz2
ada: Incorrect optimization for unconstrained limited record component type
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem_ch3.adb18
1 files changed, 0 insertions, 18 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 85019df..ed337f5 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