From patchwork Mon Jan 10 09:41:41 2022 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: 1577842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=w8bMDdEn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JXTbh3rkYz9s9c for ; Mon, 10 Jan 2022 20:50:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 549063891C16 for ; Mon, 10 Jan 2022 09:50:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 549063891C16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641808254; bh=a0WfXYdplMdnx2d4zzsv6fnQD4q+TRYXH46T65l9StA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=w8bMDdEnxsuwvezfsCXT2FMa6DfqS8VagYE4NEB8h7LGX5OCgLNMMfjF1QdP4Sqkv DaSvw7p+pdfmEsBeaXof7UibI64DjsyJMc8JCiF3ZQzyFFJiBjBKbrzNIvsDme+l3+ zgyhM49Uo9zCaWszzqWQ0MRFsQqzqjeD7FFaAlJs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id ADE083891C1F for ; Mon, 10 Jan 2022 09:41:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ADE083891C1F Received: by mail-wr1-x42c.google.com with SMTP id l25so14690717wrb.13 for ; Mon, 10 Jan 2022 01:41:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=a0WfXYdplMdnx2d4zzsv6fnQD4q+TRYXH46T65l9StA=; b=RF5Q5mq6MptD8y3dIg2Vy8JhzPxPqrZshzUSOLVLTljZpe5pFxplbnNNnKKNEYEVy1 d90v9qhfZagk2b3YDJ3u6QjFH73TAPYHlTGkgr9BZL5wSlJFp/oyXCLW2gQzs4Y30gRy ngDYfXkdrTz7e5jnlvjdwsKCdeZZHWPTRbo+xe+WsozlQQix/cKn+4qQmvScfRqM++2V zLPXClJkHnQU7Wx60G07S4Daq1/be7mwIFl+hjCpTCWt6MPDiAmjnqmNSGLhzCtcGBHA XNXWuD5Fm9UwtrISdbORv/23mBkar9/mElp4+mQjCad46WBzC4f1MY4WLN8cDX+yruDn ud1w== X-Gm-Message-State: AOAM532M3IstFkEQvAL4HFPhoQUXBbRlF7eSj7KmrLCG13PvUlTLppsp aIccXIr/gslarTrpSaUYeh+XRNDQiM23jQ== X-Google-Smtp-Source: ABdhPJwCBK6pDk2vxKX9fDc0ZbYPU0+C68ASIm41PzU5BO69NQTzZCpHTjAYzhJyy0Q2TW9+EcrpRA== X-Received: by 2002:a05:6000:2a6:: with SMTP id l6mr64083776wry.76.1641807702690; Mon, 10 Jan 2022 01:41:42 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id f6sm7020345wmq.6.2022.01.10.01.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jan 2022 01:41:42 -0800 (PST) Date: Mon, 10 Jan 2022 09:41:41 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix bogus error on call to subprogram with incomplete profile Message-ID: <20220110094141.GA586206@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This fixes a bad interaction between the machinery used to build subprogram types referencing incomplete types and the Copy-In/Copy-Out mechanism used to implement In/Out and Out parameters of elementary types in subprograms. The latter mechanism cannot be finalized until after incomplete types are replaced with their full view, both of which actions needing to take place before the first call to the subprogram is translated. The first constraint was not effectively met, leading to a confused error message. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/trans.c (Identifier_to_gnu): Use correct subtype. (elaborate_profile): New function. (Call_to_gnu): Call it on the formals and the result type before retrieving the translated result type from the subprogram type. diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -1171,7 +1171,7 @@ Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p) specific circumstances only, so evaluated lazily. < 0 means unknown, > 0 means known true, 0 means known false. */ int require_lvalue = -1; - Node_Id gnat_result_type; + Entity_Id gnat_result_type; tree gnu_result, gnu_result_type; /* If the Etype of this node is not the same as that of the Entity, then @@ -4457,6 +4457,22 @@ return_slot_opt_for_pure_call_p (tree target, tree call) return !bitmap_bit_p (decls, DECL_UID (target)); } +/* Elaborate types referenced in the profile (FIRST_FORMAL, RESULT_TYPE). */ + +static void +elaborate_profile (Entity_Id first_formal, Entity_Id result_type) +{ + Entity_Id formal; + + for (formal = first_formal; + Present (formal); + formal = Next_Formal_With_Extras (formal)) + (void) gnat_to_gnu_type (Etype (formal)); + + if (Present (result_type) && Ekind (result_type) != E_Void) + (void) gnat_to_gnu_type (result_type); +} + /* Subroutine of gnat_to_gnu to translate gnat_node, either an N_Function_Call or an N_Procedure_Call_Statement, to a GCC tree, which is returned. GNU_RESULT_TYPE_P is a pointer to where we should place the result type. @@ -4481,7 +4497,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, /* The FUNCTION_TYPE node giving the GCC type of the subprogram. */ tree gnu_subprog_type = TREE_TYPE (gnu_subprog); /* The return type of the FUNCTION_TYPE. */ - tree gnu_result_type = TREE_TYPE (gnu_subprog_type); + tree gnu_result_type;; const bool frontend_builtin = (TREE_CODE (gnu_subprog) == FUNCTION_DECL && DECL_BUILT_IN_CLASS (gnu_subprog) == BUILT_IN_FRONTEND); @@ -4496,6 +4512,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, bool variadic; bool by_descriptor; Entity_Id gnat_formal; + Entity_Id gnat_result_type; Node_Id gnat_actual; atomic_acces_t aa_type; bool aa_sync; @@ -4510,6 +4527,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, = Underlying_Type (Etype (Prefix (gnat_subprog))); gnat_formal = First_Formal_With_Extras (Etype (gnat_subprog)); + gnat_result_type = Etype (Etype (gnat_subprog)); variadic = IN (Convention (gnat_prefix_type), Convention_C_Variadic); /* If the access type doesn't require foreign-compatible representation, @@ -4523,6 +4541,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, { /* Assume here that this must be 'Elab_Body or 'Elab_Spec. */ gnat_formal = Empty; + gnat_result_type = Empty; variadic = false; by_descriptor = false; } @@ -4532,6 +4551,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, gcc_checking_assert (Is_Entity_Name (gnat_subprog)); gnat_formal = First_Formal_With_Extras (Entity (gnat_subprog)); + gnat_result_type = Etype (Entity_Id (gnat_subprog)); variadic = IN (Convention (Entity (gnat_subprog)), Convention_C_Variadic); by_descriptor = false; @@ -4549,6 +4569,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, if (returning_value) { + gnu_result_type = TREE_TYPE (gnu_subprog_type); *gnu_result_type_p = gnu_result_type; return build1 (NULL_EXPR, gnu_result_type, call_expr); } @@ -4557,7 +4578,13 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, } } + /* We must elaborate the entire profile now because, if it references types + that were initially incomplete,, their elaboration changes the contents + of GNU_SUBPROG_TYPE and, in particular, may change the result type. */ + elaborate_profile (gnat_formal, gnat_result_type); + gcc_assert (FUNC_OR_METHOD_TYPE_P (gnu_subprog_type)); + gnu_result_type = TREE_TYPE (gnu_subprog_type); if (TREE_CODE (gnu_subprog) == FUNCTION_DECL) {