From 3b78393b39a848dadfe6f7b703cda01b9870b6bd Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 24 Oct 2024 19:20:30 +0200 Subject: ada: Get rid of Kill_Range_Checks flag on entities This flag is set in a single context, namely semantic analysis of record type definitions, to avoid generating spurious range checks from it, and a large testing campaign showed that, in practice, it makes a difference in a single case, namely an access-to-constrained-array component with a default expression, for example: type Acc_String is access all String (1 .. 100); type Rec (D : Positive) is record A : Acc_String := new String (1 .. D); end record; Now there is another mechanism implemented in Process_Range_Expr_In_Decl to avoid generating spurious range checks, which does not work in this specific case but can be made to work with a small tweak to Denotes_Discriminant. gcc/ada/ChangeLog: * checks.adb (Range_Checks_Suppressed): Remove test on the Kill_Range_Checks flag. * einfo.ads (Kill_Range_Checks): Delete. * gen_il-fields.ads (Opt_Field_Enum): Remove Kill_Range_Checks. * gen_il-gen-gen_entities.adb (Entity_Kind): Likewise. * sem_ch3.adb (Record_Type_Declaration): Do not set the Kill_Range_Checks flag. * sem_util.adb (Denotes_Discriminant): In a default expression, also return True for a discriminal. --- gcc/ada/sem_ch3.adb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'gcc/ada/sem_ch3.adb') diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 28fc25d..aa95069 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -23079,22 +23079,7 @@ package body Sem_Ch3 is Set_Direct_Primitive_Operations (T, New_Elmt_List); end if; - -- We must suppress range checks when processing record components in - -- the presence of discriminants, since we don't want spurious checks to - -- be generated during their analysis, but Suppress_Range_Checks flags - -- must be reset the after processing the record definition. - - -- Note: this is the only use of Kill_Range_Checks, and is a bit odd, - -- couldn't we just use the normal range check suppression method here. - -- That would seem cleaner ??? - - if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then - Set_Kill_Range_Checks (T, True); - Record_Type_Definition (Def, Prev); - Set_Kill_Range_Checks (T, False); - else - Record_Type_Definition (Def, Prev); - end if; + Record_Type_Definition (Def, Prev); -- Exit from record scope -- cgit v1.1