From patchwork Thu Jan 11 09:05:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 858941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-470787-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZXPND0uy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zHKjK2GkDz9t3F for ; Thu, 11 Jan 2018 20:05:41 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=oTBtknF3d0agRThGPpsvb9nxrD6ZlANt04oD6h+TmtZbHS4Gfu 38xbog7jnqujzxr3H6SOQ7iAGlpcDPAIwJ5ZHNqjIgCXw57UgeBYHHIdji47wFrj iPzWs4zqTUuLq016lQEsd7x/AZbL9fh2TEp5FRBIayGtjB05BLl41A814= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=7sYzDCYbFnvOF68SWblA5xojpq0=; b=ZXPND0uy5vHaR7Qdqpe6 4hUU3UM73u4orUOAJUWCI/D0xvcu1zV+aGjbUJRnG+iiBsZS9yFMwOhKukB/kBIU XmX1Zg9kE52pnPuoA0SDpTGpoxUAszGyrDp/uBHWU80mz3R3GKVJUFxsMRvtBojI lxPSx/1N7CPiNbzuHAg1E2c= Received: (qmail 18320 invoked by alias); 11 Jan 2018 09:05:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 17996 invoked by uid 89); 11 Jan 2018 09:05:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:corresp, Par X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Jan 2018 09:05:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 32929117BC0; Thu, 11 Jan 2018 04:05:19 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id L+oaermhwDKK; Thu, 11 Jan 2018 04:05:19 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 2205B117BBE; Thu, 11 Jan 2018 04:05:19 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id 20C2950B; Thu, 11 Jan 2018 04:05:19 -0500 (EST) Date: Thu, 11 Jan 2018 04:05:19 -0500 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Finding proper scope when inside entry body Message-ID: <20180111090519.GA102950@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes 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. Tested on x86_64-pc-linux-gnu, committed on trunk 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. --- gcc/ada/sem_util.adb +++ 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