From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 0CDA538346BA for ; Tue, 10 May 2022 08:21:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CDA538346BA Received: by mail-wr1-x436.google.com with SMTP id j15so22701591wrb.2 for ; Tue, 10 May 2022 01:21:11 -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=iUsndZgJ0J/ethJsABc2/lyFkuE6B1VLkrYKDMfmdCo=; b=B++mxww8YwJVwNUPDobEtA6/vMHlk6Vv7rARy2+nL2T5zC7c4mg/fhUnlE5OGsHLkd acWCGzFFNj46sRG4MDitkM2/vHaSZk7lJf9ruWIpmK7Ze9cgfhCdZIi6Ja4OaGq0vGQu wy7fN5Ea86B9z1nCQ4gyPptgPyMT59j1/kShw2PGaDC0OhXCd2D2KxfUTb93wemwxKw0 uI1UqhhortXcDbDjRS2UJCydz5MJm0C+BfnuaqewYRv53kWG4ts8RhbW0eC3DWP+jIEQ tFY2SiMVA3aIBLH2qXSYSxl2bvr5Kn5o692GLWexIO8ZihsO1qKK103UgIv6iQOgm7lH ZRig== X-Gm-Message-State: AOAM533dviqbItJ1Bo/agUTg6IPIflbQPJf6QFrJSbSaaT4avLgYzvkI XheUKdcIUf4vcQYoCG1jPLb5y2GIYAgcpQ== X-Google-Smtp-Source: ABdhPJwor96DiarwFL8E+xKpYjShtmaK9LRqodrPx6JlabfkEMbiKkozJSfxxii+9afls169G8/8OA== X-Received: by 2002:a5d:504e:0:b0:20a:dba2:6fb3 with SMTP id h14-20020a5d504e000000b0020adba26fb3mr17816313wrt.541.1652170869820; Tue, 10 May 2022 01:21:09 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id p2-20020a05600c1d8200b003942a244ec0sm2134398wms.5.2022.05.10.01.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 01:21:09 -0700 (PDT) Date: Tue, 10 May 2022 08:21:08 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Reuse Is_Rewrite_Substitution where possible Message-ID: <20220510082108.GA3029243@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg" 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, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Tue, 10 May 2022 08:21:18 -0000 --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Replace comparisons of Original_Node with semantically equivalent but high-level calls to Is_Rewrite_Substitution. Offending occurrences found with: $ grep -n "Original_Node (\([A-Za-z_]\+\)) /\?= \1" *.adb Code cleanup only; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * atree.adb, exp_ch6.adb, exp_ch9.adb, ghost.adb, sem_ch3.adb, sem_ch4.adb, sem_res.adb, sem_util.adb: Use Is_Rewrite_Substitution where possible. --gKMricLos+KVdGMg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -2146,7 +2146,7 @@ package body Atree is -- not already rewritten the node, as indicated by an Orig_Nodes entry -- that does not reference the Old_Node. - if Original_Node (Old_Node) = Old_Node then + if not Is_Rewrite_Substitution (Old_Node) then Sav_Node := New_Copy (Old_Node); Set_Original_Node (Sav_Node, Sav_Node); Set_Original_Node (Old_Node, Sav_Node); 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 @@ -3932,7 +3932,7 @@ package body Exp_Ch6 is -- First verify the actual is internal elsif not Comes_From_Source (Prev) - and then Original_Node (Prev) = Prev + and then not Is_Rewrite_Substitution (Prev) -- Next check that the actual is a constant diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -6338,7 +6338,7 @@ package body Exp_Ch9 is when N_Expression_With_Actions => -- this may occur in the case of a Count attribute reference - if Original_Node (N) /= N + if Is_Rewrite_Substitution (N) and then Is_Pure_Barrier (Original_Node (N)) /= Abandon then return Skip; diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -1079,7 +1079,7 @@ package body Ghost is function Ultimate_Original_Node (Nod : Node_Id) return Node_Id is Res : Node_Id := Nod; begin - while Original_Node (Res) /= Res loop + while Is_Rewrite_Substitution (Res) loop Res := Original_Node (Res); end loop; diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -20185,20 +20185,14 @@ package body Sem_Ch3 is => return not Comes_From_Source (Exp) and then - -- If the conversion has been rewritten, check Original_Node + -- If the conversion has been rewritten, check Original_Node; + -- otherwise, check the expression of the compiler-generated + -- conversion (which is a conversion that we want to ignore + -- for purposes of the limited-initialization restrictions). - ((Original_Node (Exp) /= Exp - and then - OK_For_Limited_Init_In_05 (Typ, Original_Node (Exp))) - - -- Otherwise, check the expression of the compiler-generated - -- conversion (which is a conversion that we want to ignore - -- for purposes of the limited-initialization restrictions). - - or else - (Original_Node (Exp) = Exp - and then - OK_For_Limited_Init_In_05 (Typ, Expression (Exp)))); + (if Is_Rewrite_Substitution (Exp) + then OK_For_Limited_Init_In_05 (Typ, Original_Node (Exp)) + else OK_For_Limited_Init_In_05 (Typ, Expression (Exp))); when N_Explicit_Dereference | N_Indexed_Component @@ -20547,7 +20541,7 @@ package body Sem_Ch3 is -- its Original_Node points to the old Discr and the access type -- for Discr_Type has already been created. - if Original_Node (Discr) /= Discr then + if Is_Rewrite_Substitution (Discr) then Discr_Type := Etype (Discriminant_Type (Discr)); else Discr_Type := diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -772,7 +772,7 @@ package body Sem_Ch4 is -- type. else - if Original_Node (N) /= N + if Is_Rewrite_Substitution (N) and then Nkind (Original_Node (N)) = N_Allocator then declare diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -2472,7 +2472,7 @@ package body Sem_Res is -- Declare_Expression and requires scope management. if Nkind (N) = N_Expression_With_Actions then - if Comes_From_Source (N) and then N = Original_Node (N) then + if Comes_From_Source (N) and then not Is_Rewrite_Substitution (N) then Resolve_Declare_Expression (N, Typ); else Resolve (Expression (N), Typ); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -10435,7 +10435,7 @@ package body Sem_Util is Discrim_Value_Status := Static_Expr; else if Ada_Version >= Ada_2022 then - if Original_Node (Discrim_Value) /= Discrim_Value + if Is_Rewrite_Substitution (Discrim_Value) and then Nkind (Discrim_Value) = N_Type_Conversion and then Etype (Original_Node (Discrim_Value)) = Etype (Expression (Discrim_Value)) --gKMricLos+KVdGMg--