From patchwork Wed Sep 26 09:25:32 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: 974942 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-486422-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hp5lMjPP"; 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 42Kszg2xWkz9s89 for ; Wed, 26 Sep 2018 19:27:43 +1000 (AEST) 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=rk4HPRIGnk8R+WoDEKet+Y4UWZ8ntYG0Ue9MiOPDWl/LG+Q72Z CVZQHSKdTV57kah1agR0lulknhDMJrt2nxDck2ClhbXdc2duX2otXPc5t9RmLUrO 3az938B6yi7bvaLi+P/MIyMhFBkMkbx7PhjQVCClqeY4cGmsvBeiSHuUk= 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=JVT1A5iv3Y3dPE34ii+2kbdvAB4=; b=hp5lMjPPkMM2rE0xhg/a FhTIxGFgkBZjkWoC+Uv+SUTl2RqLQm0uCmoTXS8rY01z+kpuukxl62EKTpE2eTia TYYofvhoKWibOAmEIwMfr970m+jGOa+dilaqF3FwFx1ZSB0aou3rF6L/HxU5FoD2 SazUfXrwKv3WHvOHgJd6X24= Received: (qmail 87002 invoked by alias); 26 Sep 2018 09:25:42 -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 86041 invoked by uid 89); 26 Sep 2018 09:25:36 -0000 Authentication-Results: sourceware.org; auth=none 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=configurable 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; Wed, 26 Sep 2018 09:25:34 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B50D2117CB3; Wed, 26 Sep 2018 05:25: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 199aI6iGJbpk; Wed, 26 Sep 2018 05:25:32 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id A2BDB117182; Wed, 26 Sep 2018 05:25:32 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id A19D23499; Wed, 26 Sep 2018 05:25:32 -0400 (EDT) Date: Wed, 26 Sep 2018 05:25:32 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [Ada] Spurious error on interface conversion under ZFP Message-ID: <20180926092532.GA126128@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes The frontend reports an error under ZFP when performing the type conversion of a tagged object to one of its covered interface types. Tested on x86_64-pc-linux-gnu, committed on trunk 2018-09-26 Javier Miranda gcc/ada/ * exp_disp.adb (Expand_Interface_Conversion): No displacement of the pointer needed when the type of the operand is an interface type that maches the target type and we are compiling under configurable runtime. Adding also documentation explaining why this cannot be done when compiling with the full runtime. * exp_intr.adb: Update comment. gcc/testsuite/ * gnat.dg/interface8.adb, gnat.dg/interface8.ads: New testcase. --- gcc/ada/exp_disp.adb +++ gcc/ada/exp_disp.adb @@ -1339,11 +1339,39 @@ package body Exp_Disp is Opnd := Designated_Type (Opnd); end if; + Opnd := Underlying_Record_Type (Opnd); + if not Is_Interface (Opnd) and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True) then return; end if; + + -- When the type of the operand and the target interface type match, + -- it is generally safe to skip generating code to displace the + -- pointer to the object to reference the secondary dispatch table + -- associated with the target interface type. The exception to this + -- general rule is when the underlying object of the type conversion + -- is an object built by means of a dispatching constructor (since in + -- such case the expansion of the constructor call is a direct call + -- to an object primitive, i.e. without thunks, and the expansion of + -- the constructor call adds an explicit conversion to the target + -- interface type to force the displacement of the pointer to the + -- object to reference the corresponding secondary dispatch table + -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)). + + -- At this stage we cannot identify whether the underlying object is + -- a BIP object and hence we cannot skip generating the code to try + -- displacing the pointer to the object. However, under configurable + -- runtime it is safe to skip generating code to displace the pointer + -- to the object, because generic dispatching constructors are not + -- supported. + + if Opnd = Iface_Typ + and then not RTE_Available (RE_Displace) + then + return; + end if; end; -- Evaluate if we can statically displace the pointer to the object --- gcc/ada/exp_intr.adb +++ gcc/ada/exp_intr.adb @@ -402,7 +402,10 @@ package body Exp_Intr is end if; -- Rewrite and analyze the call to the instance as a class-wide - -- conversion of the call to the actual constructor. + -- conversion of the call to the actual constructor. When the result + -- type is a class-wide interface type this conversion is required to + -- force the displacement of the pointer to the object to reference the + -- corresponding dispatch table. Rewrite (N, Convert_To (Result_Typ, Cnstr_Call)); --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/interface8.adb @@ -0,0 +1,9 @@ +-- { dg-do compile } + +package body Interface8 is + function Get_Iface (This : Child) return not null access Iface'Class + is + begin + return This.Interface_1; + end; +end; --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/interface8.ads @@ -0,0 +1,11 @@ +package Interface8 is + type Iface is interface; + + type Root is abstract tagged null record; + + type Child is new Root and Iface with record + Interface_1 : access Iface'Class; + end record; + + function Get_Iface (This : Child) return not null access Iface'Class; +end;