From: Steve Baird Date: Mon, 29 Aug 2022 20:26:30 +0000 (-0700) Subject: [Ada] bugbox referencing INOX prefixed view of primitive op of modular type X-Git-Tag: basepoints/gcc-14~4612 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1588e8872ac0eb0d34a35b2f4dc9539ce10f4746;p=thirdparty%2Fgcc.git [Ada] bugbox referencing INOX prefixed view of primitive op of modular type The -gnatX switch enables naming a prefixed view of a subprogram with an untagged prefix. Compiling such a reference where the prefix is of a modular type could result in an internal compiler error. gcc/ada/ * sem_ch4.adb (Analyze_Selected_Component): Avoid initializing the local variable Comp if the variable is not going to be subsequently referenced. This is a correctness issue because the call to First_Entity can fail. --- diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index b63b5c862c62..6c817326ee3e 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -5187,7 +5187,16 @@ package body Sem_Ch4 is and then not Is_Derived_Type (Prefix_Type) and then Is_Entity_Name (Name); - Comp := First_Entity (Type_To_Use); + -- Avoid initializing Comp if that initialization is not needed + -- (and, more importantly, if the call to First_Entity could fail). + + if Has_Discriminants (Type_To_Use) + or else Is_Record_Type (Type_To_Use) + or else Is_Private_Type (Type_To_Use) + or else Is_Concurrent_Type (Type_To_Use) + then + Comp := First_Entity (Type_To_Use); + end if; -- If the selector has an original discriminant, the node appears in -- an instance. Replace the discriminant with the corresponding one