* [COMMITTED] ada: Remove redundant protection against empty lists
@ 2023-05-26 7:36 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2023-05-26 7:36 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
From: Piotr Trojanek <trojanek@adacore.com>
Calls to Length on No_List intentionally return 0, so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.
gcc/ada/
* sem_ch13.adb (Check_Component_List): Local variable Compl is now
a constant; a nested block is no longer needed.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_ch13.adb | 238 +++++++++++++++++++++----------------------
1 file changed, 116 insertions(+), 122 deletions(-)
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 593e6f8c169..b13af26b561 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -11978,163 +11978,157 @@ package body Sem_Ch13 is
Sbit : Uint;
Abit : out Uint)
is
- Compl : Integer;
+ Compl : constant Natural :=
+ Natural (List_Length (Component_Items (CL)) + List_Length (DS));
- begin
- Compl := Integer (List_Length (Component_Items (CL)));
-
- if DS /= No_List then
- Compl := Compl + Integer (List_Length (DS));
- end if;
-
- declare
- Comps : array (Natural range 0 .. Compl) of Entity_Id;
- -- Gather components (zero entry is for sort routine)
+ Comps : array (Natural range 0 .. Compl) of Entity_Id;
+ -- Gather components (zero entry is for sort routine)
- Ncomps : Natural := 0;
- -- Number of entries stored in Comps (starting at Comps (1))
+ Ncomps : Natural := 0;
+ -- Number of entries stored in Comps (starting at Comps (1))
- Citem : Node_Id;
- -- One component item or discriminant specification
+ Citem : Node_Id;
+ -- One component item or discriminant specification
- Nbit : Uint;
- -- Starting bit for next component
+ Nbit : Uint;
+ -- Starting bit for next component
- CEnt : Entity_Id;
- -- Component entity
+ CEnt : Entity_Id;
+ -- Component entity
- Variant : Node_Id;
- -- One variant
+ Variant : Node_Id;
+ -- One variant
- function Lt (Op1, Op2 : Natural) return Boolean;
- -- Compare routine for Sort
+ function Lt (Op1, Op2 : Natural) return Boolean;
+ -- Compare routine for Sort
- procedure Move (From : Natural; To : Natural);
- -- Move routine for Sort
+ procedure Move (From : Natural; To : Natural);
+ -- Move routine for Sort
- package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
+ package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
- --------
- -- Lt --
- --------
+ --------
+ -- Lt --
+ --------
- function Lt (Op1, Op2 : Natural) return Boolean is
- K1 : constant Boolean :=
- Known_Component_Bit_Offset (Comps (Op1));
- K2 : constant Boolean :=
- Known_Component_Bit_Offset (Comps (Op2));
- -- Record representation clauses can be incomplete, so the
- -- Component_Bit_Offsets can be unknown.
- begin
- if K1 then
- if K2 then
- return Component_Bit_Offset (Comps (Op1))
- < Component_Bit_Offset (Comps (Op2));
- else
- return True;
- end if;
+ function Lt (Op1, Op2 : Natural) return Boolean is
+ K1 : constant Boolean :=
+ Known_Component_Bit_Offset (Comps (Op1));
+ K2 : constant Boolean :=
+ Known_Component_Bit_Offset (Comps (Op2));
+ -- Record representation clauses can be incomplete, so the
+ -- Component_Bit_Offsets can be unknown.
+ begin
+ if K1 then
+ if K2 then
+ return Component_Bit_Offset (Comps (Op1))
+ < Component_Bit_Offset (Comps (Op2));
else
- return K2;
+ return True;
end if;
- end Lt;
+ else
+ return K2;
+ end if;
+ end Lt;
- ----------
- -- Move --
- ----------
-
- procedure Move (From : Natural; To : Natural) is
- begin
- Comps (To) := Comps (From);
- end Move;
+ ----------
+ -- Move --
+ ----------
+ procedure Move (From : Natural; To : Natural) is
begin
- -- Gather discriminants into Comp
+ Comps (To) := Comps (From);
+ end Move;
- Citem := First (DS);
- while Present (Citem) loop
- if Nkind (Citem) = N_Discriminant_Specification then
- declare
- Ent : constant Entity_Id :=
- Defining_Identifier (Citem);
- begin
- if Ekind (Ent) = E_Discriminant then
- Ncomps := Ncomps + 1;
- Comps (Ncomps) := Ent;
- end if;
- end;
- end if;
+ -- Start of processing for Check_Component_List
- Next (Citem);
- end loop;
+ begin
+ -- Gather discriminants into Comp
- -- Gather component entities into Comp
+ Citem := First (DS);
+ while Present (Citem) loop
+ if Nkind (Citem) = N_Discriminant_Specification then
+ declare
+ Ent : constant Entity_Id :=
+ Defining_Identifier (Citem);
+ begin
+ if Ekind (Ent) = E_Discriminant then
+ Ncomps := Ncomps + 1;
+ Comps (Ncomps) := Ent;
+ end if;
+ end;
+ end if;
- Citem := First (Component_Items (CL));
- while Present (Citem) loop
- if Nkind (Citem) = N_Component_Declaration then
- Ncomps := Ncomps + 1;
- Comps (Ncomps) := Defining_Identifier (Citem);
- end if;
+ Next (Citem);
+ end loop;
- Next (Citem);
- end loop;
+ -- Gather component entities into Comp
- -- Now sort the component entities based on the first bit.
- -- Note we already know there are no overlapping components.
+ Citem := First (Component_Items (CL));
+ while Present (Citem) loop
+ if Nkind (Citem) = N_Component_Declaration then
+ Ncomps := Ncomps + 1;
+ Comps (Ncomps) := Defining_Identifier (Citem);
+ end if;
- Sorting.Sort (Ncomps);
+ Next (Citem);
+ end loop;
- -- Loop through entries checking for holes
+ -- Now sort the component entities based on the first bit.
+ -- Note we already know there are no overlapping components.
- Nbit := Sbit;
- for J in 1 .. Ncomps loop
- CEnt := Comps (J);
- pragma Annotate (CodePeer, Modified, CEnt);
+ Sorting.Sort (Ncomps);
- declare
- CBO : constant Uint := Component_Bit_Offset (CEnt);
+ -- Loop through entries checking for holes
- begin
- -- Skip components with unknown offsets
+ Nbit := Sbit;
+ for J in 1 .. Ncomps loop
+ CEnt := Comps (J);
+ pragma Annotate (CodePeer, Modified, CEnt);
- if Present (CBO) and then CBO >= 0 then
- Error_Msg_Uint_1 := CBO - Nbit;
+ declare
+ CBO : constant Uint := Component_Bit_Offset (CEnt);
- if Warn and then Error_Msg_Uint_1 > 0 then
- Error_Msg_NE
- ("?.h?^-bit gap before component&",
- Component_Name (Component_Clause (CEnt)),
- CEnt);
- end if;
+ begin
+ -- Skip components with unknown offsets
+
+ if Present (CBO) and then CBO >= 0 then
+ Error_Msg_Uint_1 := CBO - Nbit;
- Nbit := CBO + Esize (CEnt);
+ if Warn and then Error_Msg_Uint_1 > 0 then
+ Error_Msg_NE
+ ("?.h?^-bit gap before component&",
+ Component_Name (Component_Clause (CEnt)),
+ CEnt);
end if;
- end;
- end loop;
- -- Set Abit to just after the last nonvariant component
+ Nbit := CBO + Esize (CEnt);
+ end if;
+ end;
+ end loop;
+
+ -- Set Abit to just after the last nonvariant component
- Abit := Nbit;
+ Abit := Nbit;
- -- Process variant parts recursively if present. Set Abit to
- -- the maximum for all variant parts.
+ -- Process variant parts recursively if present. Set Abit to the
+ -- maximum for all variant parts.
- if Present (Variant_Part (CL)) then
- declare
- Var_Start : constant Uint := Nbit;
- begin
- Variant := First (Variants (Variant_Part (CL)));
- while Present (Variant) loop
- Check_Component_List
- (No_List, Component_List (Variant), Var_Start, Nbit);
- Next (Variant);
- if Nbit > Abit then
- Abit := Nbit;
- end if;
- end loop;
- end;
- end if;
- end;
+ if Present (Variant_Part (CL)) then
+ declare
+ Var_Start : constant Uint := Nbit;
+ begin
+ Variant := First (Variants (Variant_Part (CL)));
+ while Present (Variant) loop
+ Check_Component_List
+ (No_List, Component_List (Variant), Var_Start, Nbit);
+ Next (Variant);
+ if Nbit > Abit then
+ Abit := Nbit;
+ end if;
+ end loop;
+ end;
+ end if;
end Check_Component_List;
-- Local variables
--
2.40.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Remove redundant protection against empty lists
@ 2023-05-29 8:29 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2023-05-29 8:29 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
From: Piotr Trojanek <trojanek@adacore.com>
Calls to First on No_List intentionally return Empty, so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.
gcc/ada/
* sem_util.adb (Check_Function_Writable_Actuals): Remove guard against
a membership test with no alternatives; simplify with a membership test.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_util.adb | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index a42b2dff60f..34ea06432cf 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2882,9 +2882,7 @@ package body Sem_Util is
Collect_Identifiers (Right_Opnd (N));
end if;
- if Nkind (N) in N_In | N_Not_In
- and then Present (Alternatives (N))
- then
+ if Nkind (N) in N_Membership_Test then
Expr := First (Alternatives (N));
while Present (Expr) loop
Collect_Identifiers (Expr);
--
2.40.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Remove redundant protection against empty lists
@ 2023-05-22 8:50 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2023-05-22 8:50 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
From: Piotr Trojanek <trojanek@adacore.com>
Calls to List_Length on No_List intentionally return 0 (and likewise
call to First on No_List intentionally return Empty), so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.
gcc/ada/
* exp_aggr.adb (Aggregate_Size): Remove redundant calls to
Present.
* exp_ch5.adb (Expand_N_If_Statement): Likewise.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_warn.adb (Find_Var): Likewise.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_aggr.adb | 8 +++-----
gcc/ada/exp_ch5.adb | 1 -
gcc/ada/sem_prag.adb | 25 ++++++++++---------------
gcc/ada/sem_warn.adb | 2 +-
4 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 58831bd51ca..e4b1991f410 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -7397,7 +7397,7 @@ package body Exp_Aggr is
Comp : Node_Id;
Choice : Node_Id;
Lo, Hi : Node_Id;
- Siz : Int := 0;
+ Siz : Int;
procedure Add_Range_Size;
-- Compute number of components specified by a component association
@@ -7422,11 +7422,9 @@ package body Exp_Aggr is
end Add_Range_Size;
begin
- -- Aggregate is either all positional or all named.
+ -- Aggregate is either all positional or all named
- if Present (Expressions (N)) then
- Siz := List_Length (Expressions (N));
- end if;
+ Siz := List_Length (Expressions (N));
if Present (Component_Associations (N)) then
Comp := First (Component_Associations (N));
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 0c89856b58b..dfe1112f341 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -4743,7 +4743,6 @@ package body Exp_Ch5 is
and then not Opt.Suppress_Control_Flow_Optimizations
and then Nkind (N) = N_If_Statement
and then No (Elsif_Parts (N))
- and then Present (Else_Statements (N))
and then List_Length (Then_Statements (N)) = 1
and then List_Length (Else_Statements (N)) = 1
then
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 36c1add5ea4..5fe5d6a2d0f 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -11699,29 +11699,24 @@ package body Sem_Prag is
-- Preset arguments
- Arg_Count := 0;
- Arg1 := Empty;
+ Arg_Count := List_Length (Pragma_Argument_Associations (N));
+ Arg1 := First (Pragma_Argument_Associations (N));
Arg2 := Empty;
Arg3 := Empty;
Arg4 := Empty;
Arg5 := Empty;
- if Present (Pragma_Argument_Associations (N)) then
- Arg_Count := List_Length (Pragma_Argument_Associations (N));
- Arg1 := First (Pragma_Argument_Associations (N));
-
- if Present (Arg1) then
- Arg2 := Next (Arg1);
+ if Present (Arg1) then
+ Arg2 := Next (Arg1);
- if Present (Arg2) then
- Arg3 := Next (Arg2);
+ if Present (Arg2) then
+ Arg3 := Next (Arg2);
- if Present (Arg3) then
- Arg4 := Next (Arg3);
+ if Present (Arg3) then
+ Arg4 := Next (Arg3);
- if Present (Arg4) then
- Arg5 := Next (Arg4);
- end if;
+ if Present (Arg4) then
+ Arg5 := Next (Arg4);
end if;
end if;
end if;
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 834d48d311c..5dd7c17d4e2 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -353,7 +353,7 @@ package body Sem_Warn is
begin
-- One argument, so check the argument
- if Present (PA) and then List_Length (PA) = 1 then
+ if List_Length (PA) = 1 then
if Nkind (First (PA)) = N_Parameter_Association then
Find_Var (Explicit_Actual_Parameter (First (PA)));
else
--
2.40.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Remove redundant protection against empty lists
@ 2023-05-15 9:43 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2023-05-15 9:43 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
From: Piotr Trojanek <trojanek@adacore.com>
Calls to First on No_List intentionally return Empty node, so explicit
guards against No_List are unnecessary. Code cleanup; semantics is
unaffected.
gcc/ada/
* sem_util.adb (New_Copy_Tree): Remove redundant calls to Present.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_util.adb | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 5ec0140d090..eb0d08a1851 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -24167,14 +24167,12 @@ package body Sem_Util is
-- Note that the element of a syntactic list is always a node, never
-- an entity or itype, hence the call to Visit_Node.
- if Present (List) then
- Elmt := First (List);
- while Present (Elmt) loop
- Visit_Node (Elmt);
+ Elmt := First (List);
+ while Present (Elmt) loop
+ Visit_Node (Elmt);
- Next (Elmt);
- end loop;
- end if;
+ Next (Elmt);
+ end loop;
end Visit_List;
----------------
@@ -24206,8 +24204,7 @@ package body Sem_Util is
-- If the node is a block, we need to process all declarations
-- in the block and make new entities for each.
- if Nkind (N) = N_Block_Statement and then Present (Declarations (N))
- then
+ if Nkind (N) = N_Block_Statement then
declare
Decl : Node_Id := First (Declarations (N));
--
2.40.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-29 8:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26 7:36 [COMMITTED] ada: Remove redundant protection against empty lists Marc Poulhiès
-- strict thread matches above, loose matches on Subject: below --
2023-05-29 8:29 Marc Poulhiès
2023-05-22 8:50 Marc Poulhiès
2023-05-15 9:43 Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).