From patchwork Thu Apr 21 08:25:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 613015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3qrBfL4rvSz9sDk for ; Thu, 21 Apr 2016 18:26:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=kVbwAkjZ; dkim-atps=neutral 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=a+QoKVk2z24KTJBEOTY2ZYvvYYtVQi+LkOW+vbHreD8AURI1vB erO/rp/tHKgmgWNCd+EvyXd9q7MVhkJmb+ir6VLvj21Leg/urpHdx5m1bV/5Gl6a AkQm/As7uPItVp/89Z4AlBfv0bQlTe4vZ+9U0fInPNyIhrOcPQxgFgMOs= 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=B43p3qwoX40+4VBrjsis+eTBCi4=; b=kVbwAkjZWe7CsWwD6NtU OSep3JIgy3yvNy8leeLdjvZolZyLzCLEhVA86qE2EDhIKhc/LmPSeSDtfJNLko7Z JT94d1BljWjzhA5OaCcKe1hgM8EQi9sxkqMmhtM5/vJnOjaAs7rl4UWQW++yTrM8 08TsYS75M+G3GKdAb8XooxY= Received: (qmail 59055 invoked by alias); 21 Apr 2016 08:25:51 -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 58963 invoked by uid 89); 21 Apr 2016 08:25:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.6 required=5.0 tests=BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=Soft, elsif, Schonberg, schonbergadacorecom 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 (AES256-SHA encrypted) ESMTPS; Thu, 21 Apr 2016 08:25:36 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D7631116D97; Thu, 21 Apr 2016 04:25:34 -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 ReqzEgt2rnII; Thu, 21 Apr 2016 04:25:34 -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 C5C19116D5A; Thu, 21 Apr 2016 04:25:34 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id C484A3F0; Thu, 21 Apr 2016 04:25:34 -0400 (EDT) Date: Thu, 21 Apr 2016 04:25:34 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Freezing a subprogram does not always freeze its profile Message-ID: <20160421082534.GA112576@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) AI05-019 specifies the conditions under which freezing a subprogram also freezes the profile of the subprogram. Prior to this patch the profile was frozen unconditionally, leading to spurious errors. Examples in ACATS test BDD2004. Tested on x86_64-pc-linux-gnu, committed on trunk 2016-04-21 Ed Schonberg * freeze.ads, freeze.adb (Freeze_Entity, Freeze_Before): Add boolean parameter to determine whether freezing an overloadable entity freezes its profile as well. This is required by AI05-019. The call to Freeze_Profile within Freeze_Entity is conditioned by the value of this flag, whose default is True. * sem_attr.adb (Resolve_Attribute, case 'Access): The attribute reference freezes the prefix, but it the prefix is a subprogram it does not freeze its profile. Index: freeze.adb =================================================================== --- freeze.adb (revision 235267) +++ freeze.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -1908,9 +1908,17 @@ -- Freeze_Before -- ------------------- - procedure Freeze_Before (N : Node_Id; T : Entity_Id) is - Freeze_Nodes : constant List_Id := Freeze_Entity (T, N); + procedure Freeze_Before + (N : Node_Id; + T : Entity_Id; + F_P : Boolean := True) + is + -- Freeze T, then insert the generated Freeze nodes before the node N. + -- The flag F_P is used when T is an overloadable entity, and indicates + -- whether its profile should be frozen at the same time. + Freeze_Nodes : constant List_Id := Freeze_Entity (T, N, F_P); + begin if Ekind (T) = E_Function then Check_Expression_Function (N, T); @@ -1925,7 +1933,11 @@ -- Freeze_Entity -- ------------------- - function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is + function Freeze_Entity + (E : Entity_Id; + N : Node_Id; + F_P : Boolean := True) return List_Id + is Loc : constant Source_Ptr := Sloc (N); Atype : Entity_Id; Comp : Entity_Id; @@ -4990,12 +5002,13 @@ -- In Ada 2012, freezing a subprogram does not always freeze -- the corresponding profile (see AI05-019). An attribute - -- reference is not a freezing point of the profile. + -- reference is not a freezing point of the profile. The boolean + -- Flag F_P indicates whether the profile should be frozen now. -- Other constructs that should not freeze ??? -- This processing doesn't apply to internal entities (see below) - if not Is_Internal (E) then + if not Is_Internal (E) and then F_P then if not Freeze_Profile (E) then Ghost_Mode := Save_Ghost_Mode; return Result; Index: freeze.ads =================================================================== --- freeze.ads (revision 235192) +++ freeze.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -187,13 +187,19 @@ -- If Initialization_Statements (E) is an N_Compound_Statement, insert its -- actions in the enclosing list and reset the attribute. - function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id; + function Freeze_Entity + (E : Entity_Id; + N : Node_Id; + F_P : Boolean := True) return List_Id; -- Freeze an entity, and return Freeze nodes, to be inserted at the point -- of call. N is a node whose source location corresponds to the freeze -- point. This is used in placing warning messages in the situation where -- it appears that a type has been frozen too early, e.g. when a primitive -- operation is declared after the freezing point of its tagged type. -- Returns No_List if no freeze nodes needed. + -- The defaulted parameter F_P is used when E is a subprogram, and + -- determines whether the profile of the subprogram should be frozen as + -- well. procedure Freeze_All (From : Entity_Id; After : in out Node_Id); -- Before a non-instance body, or at the end of a declarative part, @@ -209,8 +215,13 @@ -- in the scope. It is used to prevent a quadratic traversal over already -- frozen entities. - procedure Freeze_Before (N : Node_Id; T : Entity_Id); + procedure Freeze_Before + (N : Node_Id; + T : Entity_Id; + F_P : Boolean := True); -- Freeze T then Insert the generated Freeze nodes before the node N + -- The flag F_P is used when T is an overloadable entity, and indicates + -- whether its profile should be frozen at the same time. procedure Freeze_Expression (N : Node_Id); -- Freezes the required entities when the Expression N causes freezing. Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 235267) +++ sem_attr.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -10161,18 +10161,20 @@ end loop; -- If Prefix is a subprogram name, this reference freezes, - -- but not if within spec expression mode + -- but not if within spec expression mode. The profile of + -- the subprogram is not frozen at this point. if not In_Spec_Expression then - Freeze_Before (N, Entity (P)); + Freeze_Before (N, Entity (P), False); end if; - -- If it is a type, there is nothing to resolve. If it is an - -- object, complete its resolution. + -- If it is a type, there is nothing to resolve. + -- If it is a subprogram, do not freeze its profile. + -- If it is an object, complete its resolution. elsif Is_Overloadable (Entity (P)) then if not In_Spec_Expression then - Freeze_Before (N, Entity (P)); + Freeze_Before (N, Entity (P), False); end if; -- Nothing to do if prefix is a type name