From 775192706061030d927945619d3a41c5825e455d Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Thu, 11 Jan 2018 08:51:09 +0000 Subject: [PATCH] [Ada] Finding proper scope when inside entry body This patch modifies routine Find_Enclosing_Scope which obtains the scope of an arbitrary node to return the unique defining entity of an enclosing body. This automatically takes care of the following corner cases: * The body is a subprogram body which does not complete a previous declaration. In this case the proper scope is the entity of the body. * The body is an entry body. Due to a limitation in the AST, the entry body does not store its correcponsing spec, but utilizes a roundabout way of obtaining it. Regardless of the limitation, the proper scope is the entity of the entry declaration. The issue was discovered during the development of the GNATprove tool and is not visible to end users. No simple test is available because this would require a debug session. 2018-01-11 Hristian Kirtchev gcc/ada/ * sem_util.adb (Find_Enclosing_Scope): Return the unique defining entity when the enclosing construct is a body. From-SVN: r256489 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_util.adb | 23 ++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ca74b1c6530..d05467d69f9 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-01-11 Hristian Kirtchev + + * sem_util.adb (Find_Enclosing_Scope): Return the unique defining + entity when the enclosing construct is a body. + 2018-01-11 Patrick Bernardi * exp_ch9.adb (Expand_N_Task_Type_Declaration): Simplified diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 932454c51a6..c1e16e3037a 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -7847,8 +7847,7 @@ package body Sem_Util is -------------------------- function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is - Par : Node_Id; - Spec_Id : Entity_Id; + Par : Node_Id; begin -- Examine the parent chain looking for a construct which defines a @@ -7877,7 +7876,8 @@ package body Sem_Util is return Defining_Entity (Par); -- The construct denotes a body, the proper scope is the entity of - -- the corresponding spec. + -- the corresponding spec or that of the body if the body does not + -- complete a previous declaration. when N_Entry_Body | N_Package_Body @@ -7885,22 +7885,7 @@ package body Sem_Util is | N_Subprogram_Body | N_Task_Body => - Spec_Id := Corresponding_Spec (Par); - - -- The defining entity of a stand-alone subprogram body defines - -- a scope. - - if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then - return Defining_Entity (Par); - - -- Otherwise there should be corresponding spec which defines a - -- scope. - - else - pragma Assert (Present (Spec_Id)); - - return Spec_Id; - end if; + return Unique_Defining_Entity (Par); -- Special cases -- 2.30.2