public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Cleanup inconsistent iteration over exception handlers
@ 2023-05-23  8:09 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-05-23  8:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

From: Piotr Trojanek <trojanek@adacore.com>

When detecting duplicate choices in exception handlers we had
inconsistent pairs of First/Next_Non_Pragma and First_Non_Pragma/Next.
This was harmless, because exception choices don't allow pragmas at all,
e.g.:

   when Program_Error | Constraint_Error | ...; --  pragma not allowed

and exception handlers only allow pragmas to appear as the first item
on the list, e.g.:

   exception
      pragma Inspection_Point;   --  first item on the list of handlers
      when Program_Error =>
         <statements>
      pragma Inspection_Point;   --  last item on the list of statements
      when Constraint_Error =>
         ...

However, it still seems cleaner to have consistent pairs of First/Next
and First_Non_Pragma/Next_Non_Pragma.

gcc/ada/

	* sem_ch11.adb
	(Check_Duplication): Fix inconsistent iteration.
	(Others_Present): Iterate over handlers using First_Non_Pragma and
	Next_Non_Pragma just like in Check_Duplication.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch11.adb | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/sem_ch11.adb b/gcc/ada/sem_ch11.adb
index 6d519ebdd41..5471111d682 100644
--- a/gcc/ada/sem_ch11.adb
+++ b/gcc/ada/sem_ch11.adb
@@ -136,10 +136,10 @@ package body Sem_Ch11 is
                   end if;
                end if;
 
-               Next_Non_Pragma (Id1);
+               Next (Id1);
             end loop;
 
-            Next (Handler);
+            Next_Non_Pragma (Handler);
          end loop;
       end Check_Duplication;
 
@@ -151,15 +151,13 @@ package body Sem_Ch11 is
          H : Node_Id;
 
       begin
-         H := First (L);
+         H := First_Non_Pragma (L);
          while Present (H) loop
-            if Nkind (H) /= N_Pragma
-              and then Nkind (First (Exception_Choices (H))) = N_Others_Choice
-            then
+            if Nkind (First (Exception_Choices (H))) = N_Others_Choice then
                return True;
             end if;
 
-            Next (H);
+            Next_Non_Pragma (H);
          end loop;
 
          return False;
-- 
2.40.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-23  8:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23  8:09 [COMMITTED] ada: Cleanup inconsistent iteration over exception handlers 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).