From 720425fa2dca0b7a69e28b1853932d5a77bf9333 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Fri, 15 May 2020 15:11:18 +0200 Subject: [PATCH] [Ada] Accept aspect Relaxed_Initialization on generic subprograms gcc/ada/ * sem_attr.adb (Analyze_Attribute): Correct prefix of 'Result this prefix is a generic function but the enclosing aspect or pragma is attached to its instance. * sem_ch12.adb (Analyze_Generic_Subprogram_Declaration): Analyze generic subprogram formal parameters (including the implicit result of a generic function) and only then analyse its aspects, because with Relaxed_Initialization the aspect expression might refer to those formal parameters. * sem_ch13.adb (Analyze_Aspect_Relaxed_Initialization): Accept aspect on generic subprograms; install formal parameters of a generic subprogram but not formal parameters of the generic unit itself (the previous code was inspired by aspects Post and Depends, where both kinds of formals are allowed). * sem_util.ads (Enter_Name): Fix name of a subprogram referenced in comment. --- gcc/ada/sem_attr.adb | 12 ++++++++++-- gcc/ada/sem_ch12.adb | 14 +++++++------- gcc/ada/sem_ch13.adb | 16 ++++++++++------ gcc/ada/sem_util.ads | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 0d1f9c59e88..fbaaa656a2d 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -5512,8 +5512,16 @@ package body Sem_Attr is if Is_Entity_Name (P) then Pref_Id := Entity (P); - if Ekind_In (Pref_Id, E_Function, E_Generic_Function) - and then Ekind (Spec_Id) = Ekind (Pref_Id) + -- Either both the prefix and the annotated spec must be + -- generic functions, or they both must be non-generic + -- functions, or the prefix must be generic and the spec + -- must be non-generic (i.e. it must denote an instance). + + if (Ekind_In (Pref_Id, E_Function, E_Generic_Function) + and then Ekind (Pref_Id) = Ekind (Spec_Id)) + or else + (Ekind (Pref_Id) = E_Generic_Function + and then Ekind (Spec_Id) = E_Function) then if Denote_Same_Function (Pref_Id, Spec_Id) then diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index c04a20af7c6..4307111f090 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -3873,13 +3873,6 @@ package body Sem_Ch12 is Set_Ekind (Id, E_Generic_Procedure); end if; - -- Analyze the aspects of the generic copy to ensure that all generated - -- pragmas (if any) perform their semantic effects. - - if Has_Aspects (N) then - Analyze_Aspect_Specifications (N, Id); - end if; - -- Set SPARK_Mode from context Set_SPARK_Pragma (Id, SPARK_Mode_Pragma); @@ -3951,6 +3944,13 @@ package body Sem_Ch12 is Set_Etype (Id, Standard_Void_Type); end if; + -- Analyze the aspects of the generic copy to ensure that all generated + -- pragmas (if any) perform their semantic effects. + + if Has_Aspects (N) then + Analyze_Aspect_Specifications (N, Id); + end if; + -- For a library unit, we have reconstructed the entity for the unit, -- and must reset it in the library tables. We also make sure that -- Body_Required is set properly in the original compilation unit node. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 88d3124e105..808c77af0e8 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -2276,7 +2276,9 @@ package body Sem_Ch13 is -- Annotation of a subprogram; aspect expression is required - elsif Is_Subprogram_Or_Entry (E) then + elsif Is_Subprogram_Or_Entry (E) + or else Is_Generic_Subprogram (E) + then if Present (Expr) then -- If we analyze subprogram body that acts as its own @@ -2291,11 +2293,13 @@ package body Sem_Ch13 is Restore_Scope := True; Push_Scope (E); - if Is_Generic_Subprogram (E) then - Install_Generic_Formals (E); - else - Install_Formals (E); - end if; + -- Only formals of the subprogram itself can appear + -- in Relaxed_Initialization aspect expression, not + -- formals of the enclosing generic unit. (This is + -- different that in Precondition or Depends aspects, + -- where both kinds of formals are allowed.) + + Install_Formals (E); end if; -- Aspect expression is either an aggregate with list of diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 99ceec00e9a..79a6a21b284 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -741,7 +741,7 @@ package Sem_Util is -- Insert new name in symbol table of current scope with check for -- duplications (error message is issued if a conflict is found). -- Note: Enter_Name is not used for overloadable entities, instead these - -- are entered using Sem_Ch6.Enter_Overloadable_Entity. + -- are entered using Sem_Ch6.Enter_Overloaded_Entity. function Entity_Of (N : Node_Id) return Entity_Id; -- Obtain the entity of arbitrary node N. If N is a renaming, return the -- 2.30.2