public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-418] ada: Remove guards against traversal of empty list of aspects
@ 2024-05-13 8:37 Marc Poulhi?s
0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-13 8:37 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c1ece0ca7d31f191c97ff0bdc72e0f0416e72774
commit r15-418-gc1ece0ca7d31f191c97ff0bdc72e0f0416e72774
Author: Piotr Trojanek <trojanek@adacore.com>
Date: Wed Jan 31 15:32:22 2024 +0100
ada: Remove guards against traversal of empty list of aspects
When iterating over Aspect_Specifications, we can use First/Next
directly even if the Aspect_Specifications returns a No_List or
the list has no items.
Code cleanup.
gcc/ada/
* aspects.adb (Copy_Aspects): Style fix.
* contracts.adb (Analyze_Contracts): Style fix.
(Save_Global_References_In_Contract): Remove extra guards.
* par_sco.adb (Traverse_Aspects): Move guard to the caller and
make it consistent with Save_Global_References_In_Contract.
* sem_ch12.adb (Has_Contracts): Remove extra guards.
* sem_ch3.adb (Delayed_Aspect_Present, Get_Partial_View_Aspect,
Check_Duplicate_Aspects): Likewise.
* sem_disp.adb (Check_Dispatching_Operation): Likewise.
Diff:
---
gcc/ada/aspects.adb | 1 -
gcc/ada/contracts.adb | 5 +--
gcc/ada/par_sco.adb | 8 ++---
gcc/ada/sem_ch12.adb | 22 +++++--------
gcc/ada/sem_ch3.adb | 91 ++++++++++++++++++++++++---------------------------
gcc/ada/sem_disp.adb | 22 ++++++-------
6 files changed, 65 insertions(+), 84 deletions(-)
diff --git a/gcc/ada/aspects.adb b/gcc/ada/aspects.adb
index 696ee672acd3..b7262c56f3f1 100644
--- a/gcc/ada/aspects.adb
+++ b/gcc/ada/aspects.adb
@@ -433,7 +433,6 @@ package body Aspects is
-------------------
procedure Copy_Aspects (From : Node_Id; To : Node_Id) is
-
begin
if not Has_Aspects (From) then
return;
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 97f387356623..810b360fb94e 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -512,7 +512,6 @@ package body Contracts is
if Present (It) then
Validate_Iterable_Aspect (E, It);
end if;
-
if Present (I_Lit) then
Validate_Literal_Aspect (E, I_Lit);
end if;
@@ -4980,9 +4979,7 @@ package body Contracts is
Push_Scope (Gen_Id);
- if Permits_Aspect_Specifications (Templ)
- and then Has_Aspects (Templ)
- then
+ if Permits_Aspect_Specifications (Templ) then
Save_Global_References_In_Aspects (Templ);
end if;
diff --git a/gcc/ada/par_sco.adb b/gcc/ada/par_sco.adb
index 83c1d001ee53..0b750a6f8de3 100644
--- a/gcc/ada/par_sco.adb
+++ b/gcc/ada/par_sco.adb
@@ -1696,10 +1696,6 @@ package body Par_SCO is
C1 : Character;
begin
- if not Has_Aspects (N) then
- return;
- end if;
-
AN := First (Aspect_Specifications (N));
while Present (AN) loop
AE := Expression (AN);
@@ -2414,7 +2410,9 @@ package body Par_SCO is
end if;
end case;
- Traverse_Aspects (N);
+ if Permits_Aspect_Specifications (N) then
+ Traverse_Aspects (N);
+ end if;
end Traverse_One;
-- Start of processing for Traverse_Declarations_Or_Statements
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index e7b759c4e88b..cb05a71e96f9 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -9663,21 +9663,17 @@ package body Sem_Ch12 is
A_Spec : Node_Id;
A_Id : Aspect_Id;
begin
- if No (A_List) then
- return False;
- else
- A_Spec := First (A_List);
- while Present (A_Spec) loop
- A_Id := Get_Aspect_Id (A_Spec);
- if A_Id = Aspect_Pre or else A_Id = Aspect_Post then
- return True;
- end if;
+ A_Spec := First (A_List);
+ while Present (A_Spec) loop
+ A_Id := Get_Aspect_Id (A_Spec);
+ if A_Id = Aspect_Pre or else A_Id = Aspect_Post then
+ return True;
+ end if;
- Next (A_Spec);
- end loop;
+ Next (A_Spec);
+ end loop;
- return False;
- end if;
+ return False;
end Has_Contracts;
----------
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 1d95b12ff44f..2bff0bb63072 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4153,24 +4153,22 @@ package body Sem_Ch3 is
A_Id : Aspect_Id;
begin
- if Present (Aspect_Specifications (N)) then
- A := First (Aspect_Specifications (N));
+ A := First (Aspect_Specifications (N));
- while Present (A) loop
- A_Id := Get_Aspect_Id (Chars (Identifier (A)));
+ while Present (A) loop
+ A_Id := Get_Aspect_Id (Chars (Identifier (A)));
- if A_Id = Aspect_Address then
+ if A_Id = Aspect_Address then
- -- Set flag on object entity, for later processing at
- -- the freeze point.
+ -- Set flag on object entity, for later processing at the
+ -- freeze point.
- Set_Has_Delayed_Aspects (Id);
- return True;
- end if;
+ Set_Has_Delayed_Aspects (Id);
+ return True;
+ end if;
- Next (A);
- end loop;
- end if;
+ Next (A);
+ end loop;
return False;
end Delayed_Aspect_Present;
@@ -18013,16 +18011,14 @@ package body Sem_Ch3 is
Prev_Asp : Node_Id;
begin
- if Present (Prev_Asps) then
- Prev_Asp := First (Prev_Asps);
- while Present (Prev_Asp) loop
- if Get_Aspect_Id (Prev_Asp) = Asp_Id then
- return Prev_Asp;
- end if;
+ Prev_Asp := First (Prev_Asps);
+ while Present (Prev_Asp) loop
+ if Get_Aspect_Id (Prev_Asp) = Asp_Id then
+ return Prev_Asp;
+ end if;
- Next (Prev_Asp);
- end loop;
- end if;
+ Next (Prev_Asp);
+ end loop;
return Empty;
end Get_Partial_View_Aspect;
@@ -18036,38 +18032,35 @@ package body Sem_Ch3 is
-- Start of processing for Check_Duplicate_Aspects
begin
- if Present (Full_Asps) then
- Full_Asp := First (Full_Asps);
- while Present (Full_Asp) loop
- Part_Asp := Get_Partial_View_Aspect (Full_Asp);
+ Full_Asp := First (Full_Asps);
+ while Present (Full_Asp) loop
+ Part_Asp := Get_Partial_View_Aspect (Full_Asp);
- -- An aspect and its class-wide counterpart are two distinct
- -- aspects and may apply to both views of an entity.
+ -- An aspect and its class-wide counterpart are two distinct
+ -- aspects and may apply to both views of an entity.
- if Present (Part_Asp)
- and then Class_Present (Part_Asp) = Class_Present (Full_Asp)
- then
- Error_Msg_N
- ("aspect already specified in private declaration",
- Full_Asp);
+ if Present (Part_Asp)
+ and then Class_Present (Part_Asp) = Class_Present (Full_Asp)
+ then
+ Error_Msg_N
+ ("aspect already specified in private declaration", Full_Asp);
- Remove (Full_Asp);
- return;
- end if;
+ Remove (Full_Asp);
+ return;
+ end if;
- if Has_Discriminants (Prev)
- and then not Has_Unknown_Discriminants (Prev)
- and then Get_Aspect_Id (Full_Asp) =
- Aspect_Implicit_Dereference
- then
- Error_Msg_N
- ("cannot specify aspect if partial view has known "
- & "discriminants", Full_Asp);
- end if;
+ if Has_Discriminants (Prev)
+ and then not Has_Unknown_Discriminants (Prev)
+ and then Get_Aspect_Id (Full_Asp) =
+ Aspect_Implicit_Dereference
+ then
+ Error_Msg_N
+ ("cannot specify aspect if partial view has known "
+ & "discriminants", Full_Asp);
+ end if;
- Next (Full_Asp);
- end loop;
- end if;
+ Next (Full_Asp);
+ end loop;
end Check_Duplicate_Aspects;
------------------
diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
index e1b35a64ddbe..525a9f7f0a1a 100644
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -1932,19 +1932,17 @@ package body Sem_Disp is
Asp : Node_Id;
begin
- if Present (Aspect_Specifications (W_Decl)) then
- Asp := First (Aspect_Specifications (W_Decl));
- while Present (Asp) loop
- if Chars (Identifier (Asp)) = Name_Yield then
- Error_Msg_Name_1 := Name_Yield;
- Error_Msg_N
- ("specification of inherited aspect% can only confirm "
- & "parent value", Asp);
- end if;
+ Asp := First (Aspect_Specifications (W_Decl));
+ while Present (Asp) loop
+ if Chars (Identifier (Asp)) = Name_Yield then
+ Error_Msg_Name_1 := Name_Yield;
+ Error_Msg_N
+ ("specification of inherited aspect% can only confirm "
+ & "parent value", Asp);
+ end if;
- Next (Asp);
- end loop;
- end if;
+ Next (Asp);
+ end loop;
Set_Has_Yield_Aspect (Wrapped_Entity (Subp));
end;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-13 8:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 8:37 [gcc r15-418] ada: Remove guards against traversal of empty list of aspects 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).