diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-03-29 13:29:54 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-05-20 09:47:06 +0200 |
commit | efc7ba5f8f113565b47214d0ffdb27a6638ab8b6 (patch) | |
tree | eda530b1ea6288cdf8307f8b09e898e2c3de38eb | |
parent | cee232f4bf2e7d6891ec68c0100ecc5063e3e748 (diff) | |
download | gcc-efc7ba5f8f113565b47214d0ffdb27a6638ab8b6.zip gcc-efc7ba5f8f113565b47214d0ffdb27a6638ab8b6.tar.gz gcc-efc7ba5f8f113565b47214d0ffdb27a6638ab8b6.tar.bz2 |
ada: Get rid of secondary stack for indefinite record types with size clause
This change eliminates the use of the secondary stack for indefinite record
types for which a valid (object) size clause is specified. In accordance
with the RM, the compiler accepts (object) size clauses on such types only
if all the components, including those of the variants of the variant part
if any, have a size known at compile time, and only if the clauses specify
a value that is at least as large as the largest possible size of objects
of the types when all the variants are considered. However, it would still
have used the secondary stack, despite valid (object) size clauses, before
the change, as soon as a variant part was present in the types.
gcc/ada/
* freeze.ads (Check_Compile_Time_Size): Remove obsolete description
of usage for the Size_Known_At_Compile_Time flag.
* freeze.adb (Check_Compile_Time_Size.Size_Known): In the case where
a variant part is present, do not return False if Esize is known.
* sem_util.adb (Needs_Secondary_Stack.Caller_Known_Size_Record): Add
missing "Start of processing" comment. Return true if either a size
clause or an object size clause has been given for the first subtype
of the type.
-rw-r--r-- | gcc/ada/freeze.adb | 1 | ||||
-rw-r--r-- | gcc/ada/freeze.ads | 11 | ||||
-rw-r--r-- | gcc/ada/sem_util.adb | 12 |
3 files changed, 18 insertions, 6 deletions
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 26e9d01..ea6106e 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -1077,6 +1077,7 @@ package body Freeze is and then No (Discriminant_Default_Value (First_Discriminant (T))) and then not Known_RM_Size (T) + and then not Known_Esize (T) then return False; end if; diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads index fc0b767..066d8f0 100644 --- a/gcc/ada/freeze.ads +++ b/gcc/ada/freeze.ads @@ -156,17 +156,16 @@ package Freeze is -- RM_Size field is set to the required size, allowing for possible front -- end packing of an array using this type as a component type. -- - -- Note: the flag Size_Known_At_Compile_Time is used to determine if the - -- secondary stack must be used to return a value of the type, and also - -- to determine whether a component clause is allowed for a component - -- of the given type. - -- - -- Note: this is public because of one dubious use in Sem_Res??? + -- Note: the flag Size_Known_At_Compile_Time is used to determine whether a + -- size clause is allowed for the type, and also whether a component clause + -- is allowed for a component of the type. -- -- Note: Check_Compile_Time_Size does not test the case of the size being -- known because a size clause is specifically given. That is because we -- do not allow a size clause if the size would not otherwise be known at -- compile time in any case. + -- + -- ??? This is public because of dubious uses in Sem_Ch3 and Sem_Res procedure Check_Inherited_Conditions (R : Entity_Id; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 0935827..15994b4 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -22409,6 +22409,8 @@ package body Sem_Util is return False; end Depends_On_Discriminant; + -- Start of processing for Caller_Known_Size_Record + begin -- This is a protected type without Corresponding_Record_Type set, -- typically because expansion is disabled. The safe thing to do is @@ -22418,6 +22420,16 @@ package body Sem_Util is return True; end if; + -- If either size is specified for the type, then it's known in the + -- caller in particular. Note that, even if the clause is confirming, + -- this does not change the outcome since the size was already known. + + if Has_Size_Clause (First_Subtype (Typ)) + or else Has_Object_Size_Clause (First_Subtype (Typ)) + then + return True; + end if; + -- First see if we have a variant part and return False if it depends -- on discriminants. |