From d118bc58f56a7aa0bcd4e0371782e59ffb8cde73 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Sat, 22 Jan 2022 19:38:10 +0100 Subject: [PATCH] [Ada] Reuse Is_Rewrite_Substitution where possible 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. 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. --- gcc/ada/atree.adb | 2 +- gcc/ada/exp_ch6.adb | 2 +- gcc/ada/exp_ch9.adb | 2 +- gcc/ada/ghost.adb | 2 +- gcc/ada/sem_ch3.adb | 22 ++++++++-------------- gcc/ada/sem_ch4.adb | 2 +- gcc/ada/sem_res.adb | 2 +- gcc/ada/sem_util.adb | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index e6dc419..bb4c3b4 100644 --- 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 index 2447619..3ceb55d 100644 --- 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 index 81f4d7c..04a87fb 100644 --- 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 index 1f21c33..962941d 100644 --- 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 index 2ab273b..53b0ec9 100644 --- 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 index 915a7b4..c913e8b 100644 --- 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 index 5a57d62..538f860 100644 --- 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 index 1d915ab..d0cbf3f 100644 --- 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)) -- 2.7.4