From patchwork Sat Oct 14 16:29:32 2017 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: 825833 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-464214-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="vH5UjQzW"; 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 3yDqml12nKz9t39 for ; Sun, 15 Oct 2017 03:29:42 +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=v4Csa+/8zGbl8FXOx3hRevPP+pOyAF3FXSePZHkTrhSxvEjEKP XrTGvG+9CIuVfLrqUz10tTAi9gYd1NqJ3M2IvLsXQFFfGY9SFz29VuK7BJgShT3H 3tSgfYBPQJ8aRxl1+jhrveodtsZksW2ZsmjPkyoXEcXJ0p3kz0di3+ejY= 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=s1nFPep1J6W2/d/B1MxPSslOQHM=; b=vH5UjQzWdCsV7kOFP29G xoy4TesdrVOXeIRP7T5MWTHVA2QnhJrE/dTt5Zk2L4FRnbu5TOoEyQV0L5R868hl 5Eb3YghNAFb8L9dmw1bI2XHXLbd+LWVnwQRa3MITYFCN01OXT+Uhxhu4xNHeHuDP UboJ3ND++Ua4kRaDLe48jjM= Received: (qmail 68517 invoked by alias); 14 Oct 2017 16:29:35 -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 68507 invoked by uid 89); 14 Oct 2017 16:29:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=contract, contracts 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; Sat, 14 Oct 2017 16:29:34 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B22D956079; Sat, 14 Oct 2017 12:29:32 -0400 (EDT) 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 1k+r4rHTtokL; Sat, 14 Oct 2017 12:29:32 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id A136456070; Sat, 14 Oct 2017 12:29:32 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id A01FB319; Sat, 14 Oct 2017 12:29:32 -0400 (EDT) Date: Sat, 14 Oct 2017 12:29:32 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Proper resolution of Initializes and Initial_Condition Message-ID: <20171014162932.GA86859@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch modifies the processing of SPARK annotations Initializes and Initial_Condition to perform the resolution of the related expressions at the end of the enclosing package visible declarations. ------------ -- Source -- ------------ -- init_cond.ads package Init_Cond with SPARK_Mode, Initial_Condition => Vis_Var -- OK and Vis_Func -- OK and Vis_Nested.Var -- OK and Vis_Nested.Func -- OK and Priv_Var -- Error and Priv_Func -- Error and Priv_Nested.Var -- Error and Priv_Nested.Func -- Error is Vis_Var : Boolean := False; function Vis_Func return Boolean; package Vis_Nested is Var : Boolean := True; function Func return Boolean; end Vis_Nested; private Priv_Var : Boolean := False; function Priv_Func return Boolean; package Priv_Nested is Var : Boolean := True; function Func return Boolean; end Priv_Nested; end Init_Cond; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c init_cond.ads init_cond.ads:8:16: "Priv_Var" is undefined init_cond.ads:9:16: "Priv_Func" is undefined init_cond.ads:10:16: "Priv_Nested" is undefined (more references follow) Tested on x86_64-pc-linux-gnu, committed on trunk 2017-10-14 Hristian Kirtchev * sem_ch3.adb (Analyze_Declarations): Analyze the contract of an enclosing package at the end of the visible declarations. * sem_prag.adb (Analyze_Initialization_Item): Suppress the analysis of an initialization item which is undefined due to some illegality. Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 253753) +++ sem_ch3.adb (working copy) @@ -2820,25 +2820,11 @@ -- Analyze the contracts of packages and their bodies - if Nkind (Context) = N_Package_Specification then + if Nkind (Context) = N_Package_Specification + and then L = Visible_Declarations (Context) + then + Analyze_Package_Contract (Defining_Entity (Context)); - -- When a package has private declarations, its contract must be - -- analyzed at the end of the said declarations. This way both the - -- analysis and freeze actions are properly synchronized in case - -- of private type use within the contract. - - if L = Private_Declarations (Context) then - Analyze_Package_Contract (Defining_Entity (Context)); - - -- Otherwise the contract is analyzed at the end of the visible - -- declarations. - - elsif L = Visible_Declarations (Context) - and then No (Private_Declarations (Context)) - then - Analyze_Package_Contract (Defining_Entity (Context)); - end if; - elsif Nkind (Context) = N_Package_Body then Analyze_Package_Body_Contract (Defining_Entity (Context)); end if; Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 253753) +++ sem_prag.adb (working copy) @@ -2818,10 +2818,16 @@ E_Constant, E_Variable) then + -- When the initialization item is undefined, it appears as + -- Any_Id. Do not continue with the analysis of the item. + + if Item_Id = Any_Id then + null; + -- The state or variable must be declared in the visible -- declarations of the package (SPARK RM 7.1.5(7)). - if not Contains (States_And_Objs, Item_Id) then + elsif not Contains (States_And_Objs, Item_Id) then Error_Msg_Name_1 := Chars (Pack_Id); SPARK_Msg_NE ("initialization item & must appear in the visible "