From patchwork Wed Aug 21 08:31:42 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: 1150698 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-507427-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="u+dmYYzR"; 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 46D1Bl6kvfz9sN6 for ; Wed, 21 Aug 2019 18:33:03 +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=tnjwBTuZjdX4NohwmXpqQjM1FFKgpNjRd5nX/2b5ziKIFjcwrV cdpY6ea4ii13k0QU5ViN7QgAL54kJSau8uQmHC91C5eNzrC/ByCmfR3tsMpGAibU JA+wGwnmeptAtmEpB26COkheTunVOdH9T4iIgNXWOG4Na42stYX09uIpU= 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=kKzeij1Jp6hu8IE7L0G9HQfptNo=; b=u+dmYYzRqD71oMK+X7iW qHMhKS5tc37GecpirpSMx8PigoinKyDF3niEVgXWoPJKQE8mhFsZo7WiBiHDDMUC BpqSbVInXx1kda4WrwFwWEqJBVa7AceZkxP9GdJgGmtSQ4e0j9AY+erWiOci8IQx 4Ciacuqy0FmEUgqLLOrN9j8= Received: (qmail 95790 invoked by alias); 21 Aug 2019 08:31:48 -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 95702 invoked by uid 89); 21 Aug 2019 08:31:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= 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, 21 Aug 2019 08:31:46 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DFBDA1163FB; Wed, 21 Aug 2019 04:31:42 -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 gUfA+N036qUz; Wed, 21 Aug 2019 04:31:42 -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 CEA9A1163EA; Wed, 21 Aug 2019 04:31:42 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id CD6FA646; Wed, 21 Aug 2019 04:31:42 -0400 (EDT) Date: Wed, 21 Aug 2019 04:31:42 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Fix type mismatch in extended return statement expansion Message-ID: <20190821083142.GA71874@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This fixes a (sub)type mismatch in the expansion of an extended return statement generated for a built-in-place function that doesn't need a BIP_Alloc_Form parameter but returns unconstrained. No functional changes. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-08-21 Eric Botcazou gcc/ada/ * exp_ch6.adb (Expand_N_Extended_Return_Statement): In the case of a built-in-place function that doesn't need a BIP_Alloc_Form parameter but returns unconstrained, build the return consistently using the function's result subtype. Remove bypass added in previous change. --- gcc/ada/exp_ch6.adb +++ gcc/ada/exp_ch6.adb @@ -5199,7 +5199,7 @@ package body Exp_Ch6 is end if; -- When the function's subtype is unconstrained, a run-time - -- test is needed to determine the form of allocation to use + -- test may be needed to decide the form of allocation to use -- for the return object. The function has an implicit formal -- parameter indicating this. If the BIP_Alloc_Form formal has -- the value one, then the caller has passed access to an @@ -5235,13 +5235,6 @@ package body Exp_Ch6 is SS_Allocator : Node_Id; begin - -- Reuse the itype created for the function's implicit - -- access formal. This avoids the need to create a new - -- access type here, plus it allows assigning the access - -- formal directly without applying a conversion. - - -- Ref_Type := Etype (Object_Access); - -- Create an access type designating the function's -- result subtype. @@ -5572,6 +5565,64 @@ package body Exp_Ch6 is Obj_Acc_Formal := Alloc_Obj_Id; end; + + -- When the function's subtype is unconstrained and a run-time + -- test is not needed, we nevertheless need to build the return + -- using the function's result subtype. + + elsif not Is_Constrained (Underlying_Type (Etype (Func_Id))) + then + declare + Alloc_Obj_Id : Entity_Id; + Alloc_Obj_Decl : Node_Id; + Ptr_Type_Decl : Node_Id; + Ref_Type : Entity_Id; + + begin + -- Create an access type designating the function's + -- result subtype. + + Ref_Type := Make_Temporary (Loc, 'A'); + + Ptr_Type_Decl := + Make_Full_Type_Declaration (Loc, + Defining_Identifier => Ref_Type, + Type_Definition => + Make_Access_To_Object_Definition (Loc, + All_Present => True, + Subtype_Indication => + New_Occurrence_Of (Ret_Obj_Typ, Loc))); + + Insert_Before (Ret_Obj_Decl, Ptr_Type_Decl); + + -- Create an access object initialized to the conversion + -- of the implicit access value passed in by the caller. + + Alloc_Obj_Id := Make_Temporary (Loc, 'R'); + Set_Etype (Alloc_Obj_Id, Ref_Type); + + -- See the ??? comment a few lines above about the use of + -- an unchecked conversion here. + + Alloc_Obj_Decl := + Make_Object_Declaration (Loc, + Defining_Identifier => Alloc_Obj_Id, + Object_Definition => + New_Occurrence_Of (Ref_Type, Loc), + Expression => + Make_Unchecked_Type_Conversion (Loc, + Subtype_Mark => + New_Occurrence_Of (Ref_Type, Loc), + Expression => + New_Occurrence_Of (Obj_Acc_Formal, Loc))); + + Insert_Before (Ret_Obj_Decl, Alloc_Obj_Decl); + + -- Remember the local access object for use in the + -- dereference of the renaming created below. + + Obj_Acc_Formal := Alloc_Obj_Id; + end; end if; -- Replace the return object declaration with a renaming of a @@ -5615,23 +5666,7 @@ package body Exp_Ch6 is Set_Comes_From_Extended_Return_Statement (Return_Stmt); Rewrite (N, Result); - - declare - T : constant Entity_Id := Etype (Ret_Obj_Id); - begin - Analyze (N, Suppress => All_Checks); - - -- In some cases, analysis of N can set the Etype of an N_Identifier - -- to a subtype of the Etype of the Entity of the N_Identifier, which - -- gigi doesn't like. Reset the Etypes correctly here. - - if Nkind (Expression (Return_Stmt)) = N_Identifier - and then Entity (Expression (Return_Stmt)) = Ret_Obj_Id - then - Set_Etype (Ret_Obj_Id, T); - Set_Etype (Expression (Return_Stmt), T); - end if; - end; + Analyze (N, Suppress => All_Checks); end Expand_N_Extended_Return_Statement; ----------------------------