diff mbox series

[Ada] Cleanups related to front-end SJLJ

Message ID 20220517082751.GA1090664@adacore.com
State New
Headers show
Series [Ada] Cleanups related to front-end SJLJ | expand

Commit Message

Pierre-Marie de Rodat May 17, 2022, 8:27 a.m. UTC
This patch cleans up some code that is left over from the front-end SJLJ
exception handling mechanism, which has been removed.
This is in preparation for fixing a finalization-related bug.

Most importantly:

    The documentation is changed: a Handled_Sequence_Of_Statements node
    CAN contain both Exception_Handlers and an At_End_Proc.

    The assertion contradicting that is removed from
    Expand_At_End_Handler.

    The From_At_End field is removed.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sinfo.ads: Remove From_At_End.  Update comments.
	* gen_il-fields.ads, gen_il-gen-gen_nodes.adb, sem_ch11.adb:
	Remove From_At_End.
	* exp_ch11.adb (Expand_At_End_Handler): Remove assertion.
	* fe.h (Exception_Mechanism, Exception_Mechanism_Type, Has_DIC,
	Has_Invariants, Is_List_Member, List_Containing): Remove
	declarations that are not used in gigi.
	* opt.ads (Exception_Mechanism): This is not used in gigi.
	* exp_util.ads: Minor comment fix.
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -85,8 +85,6 @@  package body Exp_Ch11 is
       pragma Unreferenced (Blk_Id);
    begin
       pragma Assert (Present (Entity (At_End_Proc (HSS))));
-      pragma Assert (No (Exception_Handlers (HSS)));
-      return;
    end Expand_At_End_Handler;
 
    -------------------------------


diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -1105,8 +1105,8 @@  package Exp_Util is
    --    1) controlled objects
    --    2) library-level tagged types
    --
-   --  These cases require special actions on scope exit. The flag Lib_Level
-   --  is set True if the construct is at library level, and False otherwise.
+   --  These cases require special actions on scope exit. Lib_Level is True if
+   --  the construct is at library level, and False otherwise.
 
    function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean;
    --  Given the node for an N_Unchecked_Type_Conversion, return True if this


diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -207,7 +207,6 @@  extern Boolean In_Extended_Main_Code_Unit	(Entity_Id);
 #define Enable_128bit_Types		opt__enable_128bit_types
 #define Exception_Extra_Info		opt__exception_extra_info
 #define Exception_Locations_Suppressed	opt__exception_locations_suppressed
-#define Exception_Mechanism		opt__exception_mechanism
 #define Generate_SCO_Instance_Table	opt__generate_sco_instance_table
 #define GNAT_Mode			opt__gnat_mode
 #define List_Representation_Info	opt__list_representation_info
@@ -218,10 +217,6 @@  typedef enum {
   Ada_83, Ada_95, Ada_2005, Ada_2012, Ada_2022, Ada_With_Extensions
 } Ada_Version_Type;
 
-typedef enum {
-  Back_End_ZCX, Back_End_SJLJ
-} Exception_Mechanism_Type;
-
 extern Ada_Version_Type Ada_Version;
 extern Boolean Assume_No_Invalid_Values;
 extern Boolean Back_End_Inlining;
@@ -229,7 +224,6 @@  extern Boolean Debug_Generated_Code;
 extern Boolean Enable_128bit_Types;
 extern Boolean Exception_Extra_Info;
 extern Boolean Exception_Locations_Suppressed;
-extern Exception_Mechanism_Type Exception_Mechanism;
 extern Boolean Generate_SCO_Instance_Table;
 extern Boolean GNAT_Mode;
 extern Int List_Representation_Info;
@@ -645,12 +639,6 @@  B Is_Floating_Point_Type                      (E Id);
 #define Is_Record_Type einfo__utils__is_record_type
 B Is_Record_Type                      (E Id);
 
-#define Has_DIC einfo__utils__has_dic
-B Has_DIC (E Id);
-
-#define Has_Invariants einfo__utils__has_invariants
-B Has_Invariants (E Id);
-
 #define Is_Full_Access einfo__utils__is_full_access
 B Is_Full_Access (E Id);
 
@@ -668,12 +656,6 @@  E Next_Stored_Discriminant (E Id);
 // fe.h is included before einfo.h.
 Entity_Kind Parameter_Mode (E Id);
 
-#define Is_List_Member einfo__utils__is_list_member
-B Is_List_Member (N Node);
-
-#define List_Containing einfo__utils__list_containing
-S List_Containing (N Node);
-
 // The following is needed because Convention in Sem_Util is a renaming
 // of Basic_Convention.
 


diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -191,7 +191,6 @@  package Gen_IL.Fields is
       Formal_Type_Definition,
       Forwards_OK,
       From_Aspect_Specification,
-      From_At_End,
       From_At_Mod,
       From_Conditional_Expression,
       From_Default,


diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -1043,8 +1043,7 @@  begin -- Gen_IL.Gen.Gen_Nodes
 
    Cc (N_Raise_Statement, N_Statement_Other_Than_Procedure_Call,
        (Sy (Name, Node_Id, Default_Empty),
-        Sy (Expression, Node_Id, Default_Empty),
-        Sm (From_At_End, Flag)));
+        Sy (Expression, Node_Id, Default_Empty)));
 
    Cc (N_Raise_When_Statement, N_Statement_Other_Than_Procedure_Call,
        (Sy (Name, Node_Id, Default_Empty),


diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads
--- a/gcc/ada/opt.ads
+++ b/gcc/ada/opt.ads
@@ -585,16 +585,11 @@  package Opt is
       --  Similar to Back_End_ZCX with respect to the front-end processing
       --  of regular and AT-END handlers. A setjmp/longjmp scheme is used to
       --  propagate and setup handler contexts on regular execution paths.
-   pragma Convention (C, Exception_Mechanism_Type);
-
-   --  WARNING: There is a matching C declaration of this type in fe.h
 
    Exception_Mechanism : Exception_Mechanism_Type := Back_End_SJLJ;
    --  GNAT
    --  Set to the appropriate value depending on the flags in system.ads
-   --  (ZCX_By_Default). The C convention is there to allow access by gigi.
-
-   --  WARNING: There is a matching C declaration of this variable in fe.h
+   --  (ZCX_By_Default).
 
    function ZCX_Exceptions return Boolean;
    function SJLJ_Exceptions return Boolean;


diff --git a/gcc/ada/sem_ch11.adb b/gcc/ada/sem_ch11.adb
--- a/gcc/ada/sem_ch11.adb
+++ b/gcc/ada/sem_ch11.adb
@@ -611,15 +611,7 @@  package body Sem_Ch11 is
 
          else
             Set_Local_Raise_Not_OK (P);
-
-            --  Do not check the restriction if the reraise statement is part
-            --  of the code generated for an AT-END handler. That's because
-            --  if the restriction is actually active, we never generate this
-            --  raise anyway, so the apparent violation is bogus.
-
-            if not From_At_End (N) then
-               Check_Restriction (No_Exception_Propagation, N);
-            end if;
+            Check_Restriction (No_Exception_Propagation, N);
          end if;
 
       --  Normal case with exception id present


diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -1354,13 +1354,6 @@  package Sinfo is
    --    These generated nodes have the From_Aspect_Specification flag set to
    --    indicate that they came from aspect specifications originally.
 
-   --  From_At_End
-   --    This flag is set on an N_Raise_Statement node if it corresponds to
-   --    the reraise statement generated as the last statement of an AT END
-   --    handler when SJLJ exception handling is active. It is used to stop
-   --    a bogus violation of restriction (No_Exception_Propagation), bogus
-   --    because if the restriction is set, the reraise is not generated.
-
    --  From_At_Mod
    --    This flag is set on the attribute definition clause node that is
    --    generated by a transformation of an at mod phrase in a record
@@ -6811,38 +6804,24 @@  package Sinfo is
 
       --  The AT END phrase is a GNAT extension to provide for cleanups. It is
       --  used only internally currently, but is considered to be syntactic.
-      --  At the moment, the only cleanup action allowed is a single call to
-      --  a parameterless procedure, and the Identifier field of the node is
-      --  the procedure to be called. The cleanup action occurs whenever the
-      --  sequence of statements is left for any reason. The possible reasons
-      --  are:
+      --  At the moment, the only cleanup action allowed is a single call to a
+      --  parameterless procedure; this restriction could be lifted if we make
+      --  some changes in gigi. The At_End_Proc field is an N_Identifier node
+      --  that denotes the procedure to be called. The cleanup action occurs
+      --  whenever the sequence of statements is left for any reason. The
+      --  possible reasons are:
+      --
       --      1. reaching the end of the sequence
       --      2. exit, return, or goto
       --      3. exception or abort
-      --  For some back ends, such as gcc with ZCX, "at end" is implemented
-      --  entirely in the back end. In this case, a handled sequence of
-      --  statements with an "at end" cannot also have exception handlers.
-      --  For other back ends, such as gcc with front-end SJLJ, the
-      --  implementation is split between the front end and back end; the front
-      --  end implements 3, and the back end implements 1 and 2. In this case,
-      --  if there is an "at end", the front end inserts the appropriate
-      --  exception handler, and this handler takes precedence over "at end"
-      --  in case of exception.
-
-      --  The inserted exception handler is of the form:
-
-      --     when all others =>
-      --        cleanup;
-      --        raise;
-
-      --  where cleanup is the procedure to be called. The reason we do this is
-      --  so that the front end can handle the necessary entries in the
-      --  exception tables, and other exception handler actions required as
-      --  part of the normal handling for exception handlers.
+      --
+      --  The cleanup action also occurs whenever the exception handlers are
+      --  left.
 
       --  The AT END cleanup handler protects only the sequence of statements
-      --  (not the associated declarations of the parent), just like exception
-      --  handlers. The big difference is that the cleanup procedure is called
+      --  and the exception handlers (not the associated declarations of
+      --  the parent), just like exception handlers do not protect the
+      --  declarations. The big difference is that the cleanup actions occur
       --  on either a normal or an abnormal exit from the statement sequence.
 
       --  Note: the list of Exception_Handlers can contain pragmas as well
@@ -6873,6 +6852,9 @@  package Sinfo is
       --  At_End_Proc (set to Empty if no clean up procedure)
       --  First_Real_Statement
 
+      --  Note: A Handled_Sequence_Of_Statements can contain both
+      --  Exception_Handlers and an At_End_Proc.
+
       --  Note: the parent always contains a Declarations field which contains
       --  declarations associated with the handled sequence of statements. This
       --  is true even in the case of an accept statement (see description of
@@ -6936,7 +6918,6 @@  package Sinfo is
       --  Sloc points to RAISE
       --  Name (set to Empty if no exception name present)
       --  Expression (set to Empty if no expression present)
-      --  From_At_End
 
       ----------------------------
       -- 11.3  Raise Expression --