From patchwork Mon Nov 7 08:39:28 2022 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: 60049 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 554E6385AE65 for ; Mon, 7 Nov 2022 08:40:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554E6385AE65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667810448; bh=kO1xcOrWTwnuxxIxD/nNrJW/GRx64A+wtYQL51MhII0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uw0jfqer4cuSpsx9f+XJelfzr8Xhbb2HQVJekuxqBxQeNJUtUS2RkiIzaOOWQ2aII ez73QPYm/kHlXP5VpJqOkWF8eYXSs8okuy7xih4SPIECCrdlkem+67ThNF3ZWJW9dL qtUwPI2DwDlvK6EsNqM0RkexmGHL6PvNWjaNCrZU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 3254E38582A6 for ; Mon, 7 Nov 2022 08:39:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3254E38582A6 Received: by mail-wr1-x42d.google.com with SMTP id z14so15043080wrn.7 for ; Mon, 07 Nov 2022 00:39:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=kO1xcOrWTwnuxxIxD/nNrJW/GRx64A+wtYQL51MhII0=; b=AAg6cVnAf2AmekpsPLwBBQU4WyP4pda27Skg9/z6tVnu9pxxWju/xfHQmCkamH/cYr qJW+lADPas6nTrNnoJcBfGOIfvMVv/xWjhV9W+cnaNP+SmowRHINu7nt2456k8EUO2wl oTJPAGdCuSYgdF64l/iIq6TPege72QqpSZEwqpP1EXFt6Aq0Sb7hwlWRNBfk5OIXqvEM YaudczL6id2pXILxUjNtL+KzfsK19GjhwlapXJQQDiMaQE37XmAe/V4ldlthnL3cPCte z6rrNh2hi16sA0XE4hhR/DF6ACdD1FeB7kfwm8K2KxxRK9ACqRpAOzftg1P6MtE7GqG5 Sn9w== X-Gm-Message-State: ANoB5pmaGxiNVlio3rY9x9lrrd810t4PXHvRkOvkY3abzftMG4PE24FW Lf7T5YdoEoCoq9psk+YWIvz3BZpEha91MA== X-Google-Smtp-Source: AA0mqf6lA6AeVBqMNHQ7DVRdZajT0dDyj3kYyimPcC+yl7MOz8RPq0QzqueKzESayv6LQMGyqBwPWA== X-Received: by 2002:a5d:544a:0:b0:236:77f4:6e15 with SMTP id w10-20020a5d544a000000b0023677f46e15mr8260849wrv.117.1667810371053; Mon, 07 Nov 2022 00:39:31 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id s12-20020adfeb0c000000b0023657e1b980sm6690028wrn.53.2022.11.07.00.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:39:30 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Don't reuse operator nodes in expansion Date: Mon, 7 Nov 2022 09:39:28 +0100 Message-Id: <20221107083928.150465-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 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.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: Piotr Trojanek This patch removes handling of references to unset objects that relied on Original_Node. This handling was only needed because of rewriting that reused operator nodes, for example, when an array inequality like: A < B was rewritten into: System.Compare_Array_Unsigned_8.Compare_Array_U8 (A'Address, B'Address, A'Length, B'Length) < 0 by keeping the node for operator "<" and only substituting its operands. It seems safer to simply create an new operator node when rewriting and not rely on Original_Node afterwards. Cleanup related to improved detection uninitialized objects. gcc/ada/ * checks.adb (Apply_Arithmetic_Overflow_Strict): Rewrite using a newly created operator node. * exp_ch4.adb (Expand_Array_Comparison): Likewise. * exp_ch6.adb (Add_Call_By_Copy_Code): Rewriting actual parameter using its own location and not the location of the subprogram call. * sem_warn.adb (Check_References): Looping with Original_Node is no longer needed. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/checks.adb | 27 +++++++++++-------- gcc/ada/exp_ch4.adb | 63 ++++++++++++++++++++++++++++---------------- gcc/ada/exp_ch6.adb | 2 +- gcc/ada/sem_warn.adb | 25 ------------------ 4 files changed, 58 insertions(+), 59 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 47412948b78..a91c1cd5568 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -999,21 +999,26 @@ package body Checks is Determine_Range (N, VOK, Vlo, Vhi, Assume_Valid => True); if VOK and then Tlo <= Vlo and then Vhi <= Thi then - Rewrite (Left_Opnd (N), - Make_Type_Conversion (Loc, - Subtype_Mark => New_Occurrence_Of (Target_Type, Loc), - Expression => Relocate_Node (Left_Opnd (N)))); - - Rewrite (Right_Opnd (N), - Make_Type_Conversion (Loc, - Subtype_Mark => New_Occurrence_Of (Target_Type, Loc), - Expression => Relocate_Node (Right_Opnd (N)))); - -- Rewrite the conversion operand so that the original -- node is retained, in order to avoid the warning for -- redundant conversions in Resolve_Type_Conversion. - Rewrite (N, Relocate_Node (N)); + declare + Op : constant Node_Id := New_Op_Node (Nkind (N), Loc); + begin + Set_Left_Opnd (Op, + Make_Type_Conversion (Loc, + Subtype_Mark => + New_Occurrence_Of (Target_Type, Loc), + Expression => Relocate_Node (Left_Opnd (N)))); + Set_Right_Opnd (Op, + Make_Type_Conversion (Loc, + Subtype_Mark => + New_Occurrence_Of (Target_Type, Loc), + Expression => Relocate_Node (Right_Opnd (N)))); + + Rewrite (N, Op); + end; Set_Etype (N, Target_Type); diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 7a3a414ca0d..bbbcf4f6952 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -1424,33 +1424,52 @@ package body Exp_Ch4 is Remove_Side_Effects (Op1, Name_Req => True); Remove_Side_Effects (Op2, Name_Req => True); - Rewrite (Op1, - Make_Function_Call (Sloc (Op1), - Name => New_Occurrence_Of (RTE (Comp), Loc), + declare + Comp_Call : constant Node_Id := + Make_Function_Call (Loc, + Name => New_Occurrence_Of (RTE (Comp), Loc), - Parameter_Associations => New_List ( - Make_Attribute_Reference (Loc, - Prefix => Relocate_Node (Op1), - Attribute_Name => Name_Address), + Parameter_Associations => New_List ( + Make_Attribute_Reference (Loc, + Prefix => Relocate_Node (Op1), + Attribute_Name => Name_Address), - Make_Attribute_Reference (Loc, - Prefix => Relocate_Node (Op2), - Attribute_Name => Name_Address), + Make_Attribute_Reference (Loc, + Prefix => Relocate_Node (Op2), + Attribute_Name => Name_Address), - Make_Attribute_Reference (Loc, - Prefix => Relocate_Node (Op1), - Attribute_Name => Name_Length), + Make_Attribute_Reference (Loc, + Prefix => Relocate_Node (Op1), + Attribute_Name => Name_Length), - Make_Attribute_Reference (Loc, - Prefix => Relocate_Node (Op2), - Attribute_Name => Name_Length)))); + Make_Attribute_Reference (Loc, + Prefix => Relocate_Node (Op2), + Attribute_Name => Name_Length))); + + Zero : constant Node_Id := + Make_Integer_Literal (Loc, + Intval => Uint_0); - Rewrite (Op2, - Make_Integer_Literal (Sloc (Op2), - Intval => Uint_0)); + Comp_Op : Node_Id; - Analyze_And_Resolve (Op1, Standard_Integer); - Analyze_And_Resolve (Op2, Standard_Integer); + begin + case Nkind (N) is + when N_Op_Lt => + Comp_Op := Make_Op_Lt (Loc, Comp_Call, Zero); + when N_Op_Le => + Comp_Op := Make_Op_Le (Loc, Comp_Call, Zero); + when N_Op_Gt => + Comp_Op := Make_Op_Gt (Loc, Comp_Call, Zero); + when N_Op_Ge => + Comp_Op := Make_Op_Ge (Loc, Comp_Call, Zero); + when others => + raise Program_Error; + end case; + + Rewrite (N, Comp_Op); + end; + + Analyze_And_Resolve (N, Standard_Boolean); return; end if; end if; @@ -9819,7 +9838,7 @@ package body Exp_Ch4 is -- avoids anomalies when the replacement is done in an instance and -- is epsilon more efficient. - Set_Entity (N, Standard_Entity (S_Op_Rem)); + pragma Assert (Entity (N) = Standard_Op_Rem); Set_Etype (N, Typ); Set_Do_Division_Check (N, DDC); Expand_N_Op_Rem (N); diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index cf64e82bc99..9380f3dab0f 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1806,7 +1806,7 @@ package body Exp_Ch6 is Expr := New_Occurrence_Of (Temp, Loc); end if; - Rewrite (Actual, New_Occurrence_Of (Temp, Loc)); + Rewrite (Actual, New_Occurrence_Of (Temp, Sloc (Actual))); Analyze (Actual); -- If the actual is a conversion of a packed reference, it may diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index 83b9b20b44e..4552d907bac 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -1460,31 +1460,6 @@ package body Sem_Warn is and then not Known_To_Have_Preelab_Init (Etype (E1)) then - -- For other than access type, go back to original node to - -- deal with case where original unset reference has been - -- rewritten during expansion. - - -- In some cases, the original node may be a type - -- conversion, a qualification or an attribute reference and - -- in this case we want the object entity inside. Same for - -- an expression with actions. - - UR := Original_Node (UR); - loop - if Nkind (UR) in N_Expression_With_Actions - | N_Qualified_Expression - | N_Type_Conversion - then - UR := Expression (UR); - - elsif Nkind (UR) = N_Attribute_Reference then - UR := Prefix (UR); - - else - exit; - end if; - end loop; - -- Don't issue warning if appearing inside Initial_Condition -- pragma or aspect, since that expression is not evaluated -- at the point where it occurs in the source.