From patchwork Fri Dec 13 09:55:01 2019 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: 1209057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515859-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="vyglF045"; 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 47Z5g31hVLz9sP6 for ; Fri, 13 Dec 2019 20:57:03 +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=oBQeO8K8J9H/VKhuO0VzM1Lpwgz53J8BbYEs7ZUJCZ7B3SUtxL xoh9waFP5yF0J9uWbZrHyjjOvIMsKP6fMriyhpP5WX/aPzIpyIlRvMcKL7JDGWvC Upy2MDTinoE+f7gsr4DlNvKQ9sryoi1zfCUCNLKvkeGV+AcUaO5scm28A= 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=JMzM0WHtiFKeV5/XT0Aemfp8yHU=; b=vyglF0455KF2t4rPcNvt ylMYIyZERL+AVPEptvYfniv/WhQpQzXCTKnc2Zr/LMSBAPD69BvTYIWOTw2PZ+FJ i9CjvE7qygmJHWvZBRGK/JofqJLjktEXmZJKf3dINv4Q30y1s4VFDwWrwuQvm/M+ YmAN6FAkWBC7ieBeM6BEryM= Received: (qmail 37096 invoked by alias); 13 Dec 2019 09:55:13 -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 36927 invoked by uid 89); 13 Dec 2019 09:55:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_NEUTRAL autolearn=ham version=3.3.1 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2019 09:55:09 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifhf9-0006Pj-0C for gcc-patches@gcc.gnu.org; Fri, 13 Dec 2019 04:55:08 -0500 Received: from rock.gnat.com ([2620:20:4000:0:a9e:1ff:fe9b:1d1]:42130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ifhf8-0006Ol-P9 for gcc-patches@gcc.gnu.org; Fri, 13 Dec 2019 04:55:06 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D6B49560D9; Fri, 13 Dec 2019 04:55:01 -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 YicnUqpI3cjx; Fri, 13 Dec 2019 04:55:01 -0500 (EST) 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 B7E07560AD; Fri, 13 Dec 2019 04:55:01 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id B70BE157; Fri, 13 Dec 2019 04:55:01 -0500 (EST) Date: Fri, 13 Dec 2019 04:55:01 -0500 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [Ada] Suppress Base_Address call on init of activation record components Message-ID: <20191213095501.GA13971@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 2620:20:4000:0:a9e:1ff:fe9b:1d1 X-IsSubscribed: yes In the special case of an Address attribute that is used to initialize a component of an activation record object (for handling unnesting in back ends that don't support nested subprograms directly, such as LLVM), we don't want the attribute to be passed to the Base_Address function (that performs pointer displacement for interface objects). The expansion of such a call is suppressed in that case, since we want the address assigned as-is to the AREC component. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-12-13 Gary Dismukes gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference, Attribute_Address): Suppress generation of a call to Base_Address in the case where the Address attribute is being used to initialize a corresponding component of an activation record. (Is_Unnested_Component_Init): New function to determine whether an attribute reference for Address is used to initialized a component of an activation record object that corresponds to the object denoted by the prefix of the attribute (an assignment used in support of unnesting for back ends like LLVM). --- gcc/ada/exp_attr.adb +++ gcc/ada/exp_attr.adb @@ -2316,6 +2316,24 @@ package body Exp_Attr is when Attribute_Address => Address : declare Task_Proc : Entity_Id; + function Is_Unnested_Component_Init (N : Node_Id) return Boolean; + -- Returns True if N is being used to initialize a component of + -- an activation record object where the component corresponds to + -- the object denoted by the prefix of the attribute N. + + function Is_Unnested_Component_Init (N : Node_Id) return Boolean is + begin + return Present (Parent (N)) + and then Nkind (Parent (N)) = N_Assignment_Statement + and then Is_Entity_Name (Pref) + and then Present (Activation_Record_Component (Entity (Pref))) + and then Nkind (Name (Parent (N))) = N_Selected_Component + and then Entity (Selector_Name (Name (Parent (N)))) = + Activation_Record_Component (Entity (Pref)); + end Is_Unnested_Component_Init; + + -- Start of processing for Address + begin -- If the prefix is a task or a task type, the useful address is that -- of the procedure for the task body, i.e. the actual program unit. @@ -2379,13 +2397,19 @@ package body Exp_Attr is -- "displaced" to reference the tag associated with the interface -- type. In order to obtain the real address of such objects we -- generate a call to a run-time subprogram that returns the base - -- address of the object. + -- address of the object. This call is not generated in cases where + -- the attribute is being used to initialize a component of an + -- activation record object where the component corresponds to + -- prefix of the attribute (for back ends that require "unnesting" + -- of nested subprograms), since the address needs to be assigned + -- as-is to such components. elsif Is_Class_Wide_Type (Ptyp) and then Is_Interface (Underlying_Type (Ptyp)) and then Tagged_Type_Expansion and then not (Nkind (Pref) in N_Has_Entity and then Is_Subprogram (Entity (Pref))) + and then not Is_Unnested_Component_Init (N) then Rewrite (N, Make_Function_Call (Loc,