From patchwork Tue May 30 07:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 70287 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19A3F388202C for ; Tue, 30 May 2023 07:24:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19A3F388202C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431467; bh=/5FEW6tn6TBjuVlF+8pPiaJH2H11/5jyW8IgWXiOX1k=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qx/xPgs+dtUNTPc1MjNTSrQiUh80UlVR5mAB/0X5V1XfYbNRFTF9iWSOhwXt9dwsH wNe8GZ15/enCITrQ5+OdrBLtyj3iQ3Qb6BT30ta8rg9pTU67o5m0JashSUJOkvf9Iw aPn8A8uA4nymG2SYYkyB/RJrtbeHTJ3IcCOMBUlQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 4184F3854E6E for ; Tue, 30 May 2023 07:21:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4184F3854E6E Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-30aa1eb95a0so4096424f8f.1 for ; Tue, 30 May 2023 00:21:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431263; x=1688023263; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/5FEW6tn6TBjuVlF+8pPiaJH2H11/5jyW8IgWXiOX1k=; b=ViIxwhCFvOjQ1Db2/LAHf3bBD/7U/Bl1uURr1WZYaZ2pmvw8lE8hkjU5MfMqx7Y72C 2qD0XYDc9w2tkViAE5c2Run7TODTSx6DoSF/oI0ZyEcc+wV1WIY5y/jnawBbz3ogTM7I fRmgz/x9F+lGrpxgMkJQiR0LzDyX98JaFQZ59ynAXMfzB2KG7DqwT2JsHPCzudvFlAdp 1UbhcDM+vJp3QAA8/9OZ++JBr1XcHgufHlbkVlN9lwD3naD4WLn5yXIPBI5FvaQRk11j +KSHMhM7srSQT7R8l/V50KwasKeMYeB+haQAsZ5DJe02EQEo8jeZSV835RzYsxgjFgxy huIg== X-Gm-Message-State: AC+VfDwB3uvFrg90LsGtnFzeRYvF5Xbc3jdtBuWegSCr4pFwnINoJni4 LI8iEu40ponnCBMzLVGI2/U5gWTuTwyB4T064JNtAw== X-Google-Smtp-Source: ACHHUZ4n3nPWVChi01/B7dzrmgofg2d5tvwGtBnQcLji/dxhgh+Cds3G6yNPQ/CqhJ5vJVCspEEAWg== X-Received: by 2002:adf:ec89:0:b0:306:44a9:76a1 with SMTP id z9-20020adfec89000000b0030644a976a1mr745087wrn.17.1685431263077; Tue, 30 May 2023 00:21:03 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id f4-20020adff984000000b0030ae849c70csm2251112wrr.37.2023.05.30.00.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:21:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix wrong expansion of array aggregate with noncontiguous choices Date: Tue, 30 May 2023 09:21:01 +0200 Message-Id: <20230530072101.2500176-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou This extends an earlier fix done for the others choice of an array aggregate to all the choices of the aggregate, since the same sharing issue may happen when the choices are not contiguous. gcc/ada/ * exp_aggr.adb (Build_Array_Aggr_Code.Get_Assoc_Expr): Duplicate the expression here instead of... (Build_Array_Aggr_Code): ...here. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 93fcac5439e..da31d2480f2 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -2215,21 +2215,32 @@ package body Exp_Aggr is -- Get_Assoc_Expr -- -------------------- + -- Duplicate the expression in case we will be generating several loops. + -- As a result the expression is no longer shared between the loops and + -- is reevaluated for each such loop. + function Get_Assoc_Expr (Assoc : Node_Id) return Node_Id is Typ : constant Entity_Id := Base_Type (Etype (N)); begin if Box_Present (Assoc) then if Present (Default_Aspect_Component_Value (Typ)) then - return Default_Aspect_Component_Value (Typ); + return New_Copy_Tree (Default_Aspect_Component_Value (Typ)); elsif Needs_Simple_Initialization (Ctype) then - return Get_Simple_Init_Val (Ctype, N); + return New_Copy_Tree (Get_Simple_Init_Val (Ctype, N)); else return Empty; end if; else - return Expression (Assoc); + -- The expression will be passed to Gen_Loop, which immediately + -- calls Parent_Kind on it, so we set Parent when it matters. + + return + Expr : constant Node_Id := New_Copy_Tree (Expression (Assoc)) + do + Copy_Parent (To => Expr, From => Expression (Assoc)); + end return; end if; end Get_Assoc_Expr; @@ -2394,8 +2405,7 @@ package body Exp_Aggr is if Present (Others_Assoc) then declare - First : Boolean := True; - Dup_Expr : Node_Id; + First : Boolean := True; begin for J in 0 .. Nb_Choices loop @@ -2429,23 +2439,11 @@ package body Exp_Aggr is end if; end if; - if First - or else not Empty_Range (Low, High) - then + if First or else not Empty_Range (Low, High) then First := False; - - -- Duplicate the expression in case we will be generating - -- several loops. As a result the expression is no longer - -- shared between the loops and is reevaluated for each - -- such loop. - - Expr := Get_Assoc_Expr (Others_Assoc); - Dup_Expr := New_Copy_Tree (Expr); - Copy_Parent (To => Dup_Expr, From => Expr); - Set_Loop_Actions (Others_Assoc, New_List); - Append_List - (Gen_Loop (Low, High, Dup_Expr), To => New_Code); + Expr := Get_Assoc_Expr (Others_Assoc); + Append_List (Gen_Loop (Low, High, Expr), To => New_Code); end if; end loop; end;