From 80f0c69c2c698023f76d0e5db7e2b42e1fd7b637 Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Tue, 22 May 2018 13:17:22 +0000 Subject: [PATCH] [Ada] Missing error on illegal categorization dependency This patch modifies the analysis of subprogram declarations to ensure that an aspect which is converted into a categorization pragma is properly taken into account when verifying the dependencies of a subprogram unit. ------------ -- Source -- ------------ -- pack.ads package Pack is end Pack; -- proc1.ads with Pack; procedure Proc1 with Pure; -- proc2.ads with Pack; procedure Proc2; pragma Pure (Proc2); ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c proc1.ads $ gcc -c proc2.ads proc1.ads:1:06: cannot depend on "Pack" (wrong categorization) proc1.ads:1:06: pure unit cannot depend on non-pure unit proc2.ads:1:06: cannot depend on "Pack" (wrong categorization) proc2.ads:1:06: pure unit cannot depend on non-pure unit 2018-05-22 Hristian Kirtchev gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Declaration): Set the proper categorization of the unit after processing the aspects in case one of its aspects is converted into a categorization pragma. From-SVN: r260506 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/sem_ch6.adb | 36 ++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 783519964a3f..71e0aaf1f987 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-05-22 Hristian Kirtchev + + * sem_ch6.adb (Analyze_Subprogram_Declaration): Set the proper + categorization of the unit after processing the aspects in case one of + its aspects is converted into a categorization pragma. + 2018-05-21 Ed Schonberg * freeze.adb (Warn_Overlay): Do not emit a wawrning on an object diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 3dece02f81e1..55298e9602f7 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -4844,18 +4844,6 @@ package body Sem_Ch6 is Set_Kill_Elaboration_Checks (Designator); end if; - if Scop /= Standard_Standard and then not Is_Child_Unit (Designator) then - Set_Categorization_From_Scope (Designator, Scop); - - else - -- For a compilation unit, check for library-unit pragmas - - Push_Scope (Designator); - Set_Categorization_From_Pragmas (N); - Validate_Categorization_Dependency (N, Designator); - Pop_Scope; - end if; - -- For a compilation unit, set body required. This flag will only be -- reset if a valid Import or Interface pragma is processed later on. @@ -4883,19 +4871,35 @@ package body Sem_Ch6 is Write_Eol; end if; - if Is_Protected_Type (Current_Scope) then - - -- Indicate that this is a protected operation, because it may be - -- used in subsequent declarations within the protected type. + -- Indicate that this is a protected operation, because it may be used + -- in subsequent declarations within the protected type. + if Is_Protected_Type (Current_Scope) then Set_Convention (Designator, Convention_Protected); end if; List_Inherited_Pre_Post_Aspects (Designator); + -- Process the aspects before establishing the proper categorization in + -- case the subprogram is a compilation unit and one of its aspects is + -- converted into a categorization pragma. + if Has_Aspects (N) then Analyze_Aspect_Specifications (N, Designator); end if; + + if Scop /= Standard_Standard and then not Is_Child_Unit (Designator) then + Set_Categorization_From_Scope (Designator, Scop); + + -- Otherwise the unit is a compilation unit and/or a child unit. Set the + -- proper categorization of the unit based on its pragmas. + + else + Push_Scope (Designator); + Set_Categorization_From_Pragmas (N); + Validate_Categorization_Dependency (N, Designator); + Pop_Scope; + end if; end Analyze_Subprogram_Declaration; -------------------------------------- -- 2.43.5