From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Remove redundant protection against empty lists
Date: Fri, 26 May 2023 09:36:12 +0200 [thread overview]
Message-ID: <20230526073612.2068697-1-poulhies@adacore.com> (raw)
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
next reply other threads:[~2023-05-26 7:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 7:36 Marc Poulhiès [this message]
-- 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230526073612.2068697-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).