From patchwork Fri Apr 28 13:33:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 756403 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 3wDvsr5jKhz9s8G for ; Fri, 28 Apr 2017 23:33:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QZW5xJ+K"; 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=UIQEXH3QUDP1tQZ5NDFF3N+pRUnqBIQ5PmJUMTr/DctgXhuiy0 MTG61EfmBzMCo+7tpBHcNtSob7Vy7/ZuKuu4l3USnTdpCwCdMqKGPWdPl7w1iliJ Z09wcZiT37uzV2WTz9w50yYZ+2a2kJUaIqx/oFqXCwD753DFun2Nk/Mbs= 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=PdkrXV+lkOAFB2PzDmwHcsdsurQ=; b=QZW5xJ+Kr7mECDfRoXw4 RZe0tdoMfkwnWiqBwJ9+Lv+bNPYRHMEx9JVltxcphPK0SsANVG+Ark5kmtWXfP2a KlMA8uTsAy7Epu0nC/FVDGizaiZgz1sSb0qF34ZKExBea/qsrrvXkmggiRnjaUmb pkEKIR+ld9ayJce70wWSM6o= Received: (qmail 93765 invoked by alias); 28 Apr 2017 13:33: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 93672 invoked by uid 89); 28 Apr 2017 13:33:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 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=expresion 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; Fri, 28 Apr 2017 13:33:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 93C5C7AA8; Fri, 28 Apr 2017 09:33:33 -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 Ycp5MRHa+kSY; Fri, 28 Apr 2017 09:33:33 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 83F507946; Fri, 28 Apr 2017 09:33:33 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 82CCD3B2; Fri, 28 Apr 2017 09:33:33 -0400 (EDT) Date: Fri, 28 Apr 2017 09:33:33 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Freezing in expression function that is a completion. Message-ID: <20170428133333.GA9075@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) The expresion in an expression function that is a completion freezes. This is implemented by first freezing the return type of the function, and then traversing the analyzed expression and freezing explicitly all type references within. If the expression includes a type conversion between access to interface types we must also freeze the interface types themselves so that dispatch table pointers are properly declared before the expression function. The following must compile quietly: --- with Gen; package Small is type I1 is interface; type I2 is interface; type I1_Ptr is access all I1'Class; type I2_Ptr is access all I2'Class; type Reference (Data : access I2'Class) is null record; package Instance is new Gen (I1); function Get return Reference; private function Get return Reference is ((Data => I2_Ptr (I1_Ptr'(Instance.Get)))); end; --- generic type Iface is interface; package Gen is function Get return access Iface'Class; end; --- package body Gen is function Get return access Iface'Class is begin return null; end; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-28 Ed Schonberg * sem_ch6.adb (Freeze_Type_Refs): For an interface conversion node between access types, freeze the designated type as well, so that dispatch table pointers are created in the proper scope, and not in the constructed body of the expression function. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 247338) +++ sem_ch6.adb (working copy) @@ -3110,6 +3110,18 @@ end if; end; end if; + + -- Freezing an access type does not freeze the designated + -- type, but freezing conversions between access to interfaces + -- requires that the interface types themselves be frozen, so + -- that dispatch table entities are properly created. + -- Unclear whether a more general rule is needed ??? + + elsif Nkind (Node) = N_Type_Conversion + and then Is_Access_Type (Etype (Node)) + and then Is_Interface (Designated_Type (Etype (Node))) + then + Freeze_Before (N, Designated_Type (Etype (Node))); end if; return OK;