From patchwork Mon May 30 08:33:00 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: 1636850 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=mTjO6Mgh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LBTpj5G3wz9s0r for ; Mon, 30 May 2022 18:58:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B128A3814FE8 for ; Mon, 30 May 2022 08:58:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B128A3814FE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653901115; bh=xuMpV/bHYvdeHifhEWm2z4EECNzwDBB6ul12LWmqcls=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mTjO6MghfYfHLcM+vaeCcfeeRn5KjQDVjQgN+F2GH6BBs60i+goDyzdi+v8O3HbvH BDHRP6MdfZakE7wzftT454MZsAf8LMtoKp1HaWl/Fwkgd0PbI/OvhS4+YafRLiybag q3rHf2gDRJW3t3MaJ8zkpV/BHBDb8edIQyapG+0c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 438F93814FCE for ; Mon, 30 May 2022 08:33:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 438F93814FCE Received: by mail-wr1-x42b.google.com with SMTP id s24so6287161wrb.10 for ; Mon, 30 May 2022 01:33:01 -0700 (PDT) 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=xuMpV/bHYvdeHifhEWm2z4EECNzwDBB6ul12LWmqcls=; b=maPvUtMDBLQ/dFF87Fyik8XmMWuE/VbJHTZhaqM/cW7k3z6HX6VZ7Qh3+/vSgzjf3l g/vRpe0TipOawTCF2uTzNRt6ZPHNLsYmgDrOp+mwATjAQw/yQ6sS38YBNF7asCrHVjeh n4uklQm3l0ZP1tZNMXFSQ1ayHdLOq4AyR29OjvJxnoOEUToozvuH5RpTYBY+jQ70uYkP UPXxH68188fwHU8P3tv3RhDTZVA2KfLpVUbCGRvkj4xq5ewR4mQ0cnfVQw1pmLDSRE/9 1upBenu4DJj7r9cDoXkjRr6pNH/9umKiYC4mEVyMzRhayOJHAYNyTJ1DFgTh/rWqG8i/ 6jgQ== X-Gm-Message-State: AOAM533KmO7IHI5iNjmLrcpgxfjnOrjAS2Hn5WhCLisMIpctnOy6VA5p ZQoqbS0ohXP0hPsFuHBWzDLRtO5pUnvSAg== X-Google-Smtp-Source: ABdhPJzYwu7N/hBU6PFV5ct/hk+Pt7eyk+TbJYaWY60iOTflZNRpakDP1Gj/LcixzEGAYx4qjX3n9w== X-Received: by 2002:a05:6000:1c16:b0:20e:7a44:fdd3 with SMTP id ba22-20020a0560001c1600b0020e7a44fdd3mr39479684wrb.125.1653899580849; Mon, 30 May 2022 01:33:00 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id c17-20020a7bc011000000b0039482d95ab7sm10249561wmb.24.2022.05.30.01.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 01:33:00 -0700 (PDT) Date: Mon, 30 May 2022 08:33:00 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix expansion of structural subprogram variants Message-ID: <20220530083300.GA211053@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When implementing structural subprogram variants we ignored them in expansion of the pragma itself, but not in expansion of a recursive subprogram call. Now fixed. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch6.adb (Check_Subprogram_Variant): Ignore structural variants. diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -3298,19 +3298,33 @@ package body Exp_Ch6 is Variant_Prag : constant Node_Id := Get_Pragma (Current_Scope, Pragma_Subprogram_Variant); + Pragma_Arg1 : Node_Id; Variant_Proc : Entity_Id; begin if Present (Variant_Prag) and then Is_Checked (Variant_Prag) then - -- Analysis of the pragma rewrites its argument with a reference - -- to the internally generated procedure. + Pragma_Arg1 := + Expression (First (Pragma_Argument_Associations (Variant_Prag))); - Variant_Proc := - Entity - (Expression - (First - (Pragma_Argument_Associations (Variant_Prag)))); + -- If pragma parameter is still an aggregate, it comes from a + -- structural variant, which is not expanded and ignored for + -- run-time execution. + + if Nkind (Pragma_Arg1) = N_Aggregate then + pragma Assert + (Chars + (First + (Choices + (First (Component_Associations (Pragma_Arg1))))) = + Name_Structural); + return; + end if; + + -- Otherwise, analysis of the pragma rewrites its argument with a + -- reference to the internally generated procedure. + + Variant_Proc := Entity (Pragma_Arg1); Insert_Action (Call_Node, Make_Procedure_Call_Statement (Loc,