opt.ads (Exception_Mechanism): Now three values: Front_End_SJLJ, Back_End_SJLJ and Back_End_ZCX.

2015-11-23  Olivier Hainque  <hainque@adacore.com>
	    Eric Botcazou  <botcazou@adacore.com>

	* opt.ads (Exception_Mechanism): Now three values: Front_End_SJLJ,
	Back_End_SJLJ and Back_End_ZCX.
	(Back_End_Exceptions, Front_End_Exceptions, ZCX_Exceptions,
	SJLJ_Exceptions): New functions, reflecting properties of the current
	Exception_Mechanism.
	* opt.adb: Implement the new functions.
	* fe.h: Bind the new Exception_Mechanism and helper functions for gigi.

	* exp_ch11.adb (Expand_At_End_Handler): Replace test on mechanism by
	use of property helper and update comments.
	(Expand_Exception_Handlers): Replace tests on mechanism by use of
	helper. Restrict Abort_Defer to ZCX specifically.
	* exp_ch9.adb (Expand_N_Asynchronous_Select): Replace tests on
	mechanism by calls to helper functions. Abort_Undefer for ZCX only,
	paired with Expand_Exception_Handlers.
	* exp_sel.adb (Build_Abort_Block_Handler): Replace tests on mechanism
	by calls to helper functions. Abort_Undefer for ZCX only, paired with
	Expand_Exception_Handlers.

	* lib-writ.ads (P line documentation): Add entry for "FX",
	representative of unit compiled with Frontend_Exceptions True.
	* lib-writ.adb (Output_Main_Program_Line): Add "FX" on P line if
	compiled with Frontend_Exceptions True.

	* ali.ads (ALIs_Record): Ada a Frontend_Exceptions component, to reflect
	whether the ALI file contained an "FX" indication on the P line.
	(Frontend_Exceptions_Specified): New boolean, to keep track of whether
	at least an FX ALI file is in the closure.
	* ali.adb (Scan_ALI): Handle "FX" on the P line.
	(Initialize_ALI): Initialize Frontend_Exceptions_Specified to False.

	* targparm.ads: Update desription of exception schemes.
	(Frontend_Exceptions_On_Target): New flag, reflect Frontend_Exceptions
	set to True in system.ads, or not set at all.
	* targparm.adb (Targparm_Tags): Add FEX to convey Frontend_Exceptions.
	Rename ZCD to ZCX for consistency.
	(FEX_Str, Targparm_Str, Get_Target_Parameters): Adjust accordingly.

	* gnat1drv.adb (Adjust_Global_Switches): Adjust Exception_Mechanism
	setting, now from combination of Frontend_Exceptions and ZCX_By_Default.

	* bcheck.adb (Check_Consistent_Zero_Cost_Exception_Handling): Rename
	as ...
	(Check_Consistent_Exception_Handling): Check consistency of both
	ZCX_By_Default and Frontend_Exceptions.
	(Check_Configuration_Consistency): Check_Consistent_Exception_Handling
	if either flag was set at least once.

	* make.adb (Check): Remove processing of a possible -fsjlj coming from
	lang-specs.h.
	* gnatlink.adb (Gnatlin): Likewise.

	* gcc-interface/Makefile.in (gnatlib-sjlj/zcx): Now set
	both ZCX_By_Default and Frontend_Exceptions.
	* gcc-interface/decl.c (gnat_to_gnu_entity, case E_Variable):
	Use eh property helper to test for back-end exceptions. Adjust
	mechanism name when testing for front-end sjlj.
	(case E_Procedure): Likewise.
	* gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu):
	Likewise, and rename local variables.
	(Exception_Handler_to_gnu_sjlj): Rename as
	Exception_Handler_to_gnu_fe_sjlj.
	(Exception_Handler_to_gnu_zcx): Rename as
	Exception_Handler_to_gnu_gcc and adjust tests on eh mechanisms
	to use property helpers or correct mechanism name.


Co-Authored-By: Eric Botcazou <ebotcazou@adacore.com>

From-SVN: r230752
This commit is contained in:
Olivier Hainque 2015-11-23 11:20:34 +00:00 committed by Olivier Hainque
parent f119bebb36
commit 0ab0bf955a
20 changed files with 298 additions and 127 deletions

View File

@ -1,3 +1,72 @@
2015-11-23 Olivier Hainque <hainque@adacore.com>
Eric Botcazou <botcazou@adacore.com>
* opt.ads (Exception_Mechanism): Now three values: Front_End_SJLJ,
Back_End_SJLJ and Back_End_ZCX.
(Back_End_Exceptions, Front_End_Exceptions, ZCX_Exceptions,
SJLJ_Exceptions): New functions, reflecting properties of the current
Exception_Mechanism.
* opt.adb: Implement the new functions.
* fe.h: Bind the new Exception_Mechanism and helper functions for gigi.
* exp_ch11.adb (Expand_At_End_Handler): Replace test on mechanism by
use of property helper and update comments.
(Expand_Exception_Handlers): Replace tests on mechanism by use of
helper. Restrict Abort_Defer to ZCX specifically.
* exp_ch9.adb (Expand_N_Asynchronous_Select): Replace tests on
mechanism by calls to helper functions. Abort_Undefer for ZCX only,
paired with Expand_Exception_Handlers.
* exp_sel.adb (Build_Abort_Block_Handler): Replace tests on mechanism
by calls to helper functions. Abort_Undefer for ZCX only, paired with
Expand_Exception_Handlers.
* lib-writ.ads (P line documentation): Add entry for "FX",
representative of unit compiled with Frontend_Exceptions True.
* lib-writ.adb (Output_Main_Program_Line): Add "FX" on P line if
compiled with Frontend_Exceptions True.
* ali.ads (ALIs_Record): Ada a Frontend_Exceptions component, to reflect
whether the ALI file contained an "FX" indication on the P line.
(Frontend_Exceptions_Specified): New boolean, to keep track of whether
at least an FX ALI file is in the closure.
* ali.adb (Scan_ALI): Handle "FX" on the P line.
(Initialize_ALI): Initialize Frontend_Exceptions_Specified to False.
* targparm.ads: Update desription of exception schemes.
(Frontend_Exceptions_On_Target): New flag, reflect Frontend_Exceptions
set to True in system.ads, or not set at all.
* targparm.adb (Targparm_Tags): Add FEX to convey Frontend_Exceptions.
Rename ZCD to ZCX for consistency.
(FEX_Str, Targparm_Str, Get_Target_Parameters): Adjust accordingly.
* gnat1drv.adb (Adjust_Global_Switches): Adjust Exception_Mechanism
setting, now from combination of Frontend_Exceptions and ZCX_By_Default.
* bcheck.adb (Check_Consistent_Zero_Cost_Exception_Handling): Rename
as ...
(Check_Consistent_Exception_Handling): Check consistency of both
ZCX_By_Default and Frontend_Exceptions.
(Check_Configuration_Consistency): Check_Consistent_Exception_Handling
if either flag was set at least once.
* make.adb (Check): Remove processing of a possible -fsjlj coming from
lang-specs.h.
* gnatlink.adb (Gnatlin): Likewise.
* gcc-interface/Makefile.in (gnatlib-sjlj/zcx): Now set
both ZCX_By_Default and Frontend_Exceptions.
* gcc-interface/decl.c (gnat_to_gnu_entity, case E_Variable):
Use eh property helper to test for back-end exceptions. Adjust
mechanism name when testing for front-end sjlj.
(case E_Procedure): Likewise.
* gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu):
Likewise, and rename local variables.
(Exception_Handler_to_gnu_sjlj): Rename as
Exception_Handler_to_gnu_fe_sjlj.
(Exception_Handler_to_gnu_zcx): Rename as
Exception_Handler_to_gnu_gcc and adjust tests on eh mechanisms
to use property helpers or correct mechanism name.
2015-11-19 Bob Duff <duff@adacore.com>
* sem_elab.adb (Check_Internal_Call_Continue): Correction to previous

View File

@ -119,6 +119,7 @@ package body ALI is
Static_Elaboration_Model_Used := False;
Task_Dispatching_Policy_Specified := ' ';
Unreserve_All_Interrupts_Specified := False;
Frontend_Exceptions_Specified := False;
Zero_Cost_Exceptions_Specified := False;
end Initialize_ALI;
@ -900,6 +901,7 @@ package body ALI is
Unit_Exception_Table => False,
Ver => (others => ' '),
Ver_Len => 0,
Frontend_Exceptions => False,
Zero_Cost_Exceptions => False);
-- Now we acquire the input lines from the ALI file. Note that the
@ -1091,6 +1093,18 @@ package body ALI is
ALIs.Table (Id).Partition_Elaboration_Policy :=
Partition_Elaboration_Policy_Specified;
-- Processing for FX
elsif C = 'F' then
C := Getc;
if C = 'X' then
ALIs.Table (Id).Frontend_Exceptions := True;
Frontend_Exceptions_Specified := True;
else
Fatal_Error_Ignore;
end if;
-- Processing for GP
elsif C = 'G' then

View File

@ -199,6 +199,10 @@ package ALI is
-- Set to True if unit exception table pointer generated. Not set if 'P'
-- appears in Ignore_Lines.
Frontend_Exceptions : Boolean;
-- Set to True if file was compiled with front-end exceptions. Not set
-- if 'P' appears in Ignore_Lines.
Zero_Cost_Exceptions : Boolean;
-- Set to True if file was compiled with zero cost exceptions. Not set
-- if 'P' appears in Ignore_Lines.
@ -474,6 +478,10 @@ package ALI is
-- Set to False by Initialize_ALI. Set to True if Scan_ALI reads
-- a unit for which dynamic elaboration checking is enabled.
Frontend_Exceptions_Specified : Boolean := False;
-- Set to False by Initialize_ALI. Set to True if an ali file is read that
-- has a P line specifying the generation of front-end exceptions.
GNATprove_Mode_Specified : Boolean := False;
-- Set to True if an ali file was produced in GNATprove mode.

View File

@ -56,7 +56,7 @@ package body Bcheck is
procedure Check_Consistent_Restrictions;
procedure Check_Consistent_Restriction_No_Default_Initialization;
procedure Check_Consistent_SSO_Default;
procedure Check_Consistent_Zero_Cost_Exception_Handling;
procedure Check_Consistent_Exception_Handling;
procedure Consistency_Error_Msg (Msg : String);
-- Produce an error or a warning message, depending on whether an
@ -88,8 +88,10 @@ package body Bcheck is
Check_Consistent_SSO_Default;
end if;
if Zero_Cost_Exceptions_Specified then
Check_Consistent_Zero_Cost_Exception_Handling;
if Zero_Cost_Exceptions_Specified
or else Frontend_Exceptions_Specified
then
Check_Consistent_Exception_Handling;
end if;
Check_Consistent_Normalize_Scalars;
@ -1164,18 +1166,20 @@ package body Bcheck is
end loop;
end Check_Consistent_SSO_Default;
---------------------------------------------------
-- Check_Consistent_Zero_Cost_Exception_Handling --
---------------------------------------------------
-----------------------------------------
-- Check_Consistent_Exception_Handling --
-----------------------------------------
-- Check consistent zero cost exception handling. The rule is that
-- all units must have the same exception handling mechanism.
-- All units must have the same exception handling mechanism.
procedure Check_Consistent_Zero_Cost_Exception_Handling is
procedure Check_Consistent_Exception_Handling is
begin
Check_Mechanism : for A1 in ALIs.First + 1 .. ALIs.Last loop
if ALIs.Table (A1).Zero_Cost_Exceptions /=
ALIs.Table (ALIs.First).Zero_Cost_Exceptions
if (ALIs.Table (A1).Zero_Cost_Exceptions /=
ALIs.Table (ALIs.First).Zero_Cost_Exceptions)
or else
(ALIs.Table (A1).Frontend_Exceptions /=
ALIs.Table (ALIs.First).Frontend_Exceptions)
then
Error_Msg_File_1 := ALIs.Table (A1).Sfile;
Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile;
@ -1184,7 +1188,7 @@ package body Bcheck is
& "exception handling mechanisms");
end if;
end loop Check_Mechanism;
end Check_Consistent_Zero_Cost_Exception_Handling;
end Check_Consistent_Exception_Handling;
-------------------------------
-- Check_Duplicated_Subunits --

View File

@ -116,9 +116,10 @@ package body Exp_Ch11 is
pragma Assert (Present (Clean));
pragma Assert (No (Exception_Handlers (HSS)));
-- Don't expand if back end exception handling active
-- Back end exception schemes don't need explicit handlers to
-- trigger AT-END actions on exceptional paths.
if Exception_Mechanism = Back_End_Exceptions then
if Back_End_Exceptions then
return;
end if;
@ -1025,11 +1026,12 @@ package body Exp_Ch11 is
-- ...
-- end;
-- This expansion is not performed when using GCC ZCX. Gigi
-- will insert a call to initialize the choice parameter.
-- This expansion is only performed when using front-end
-- exceptions. Gigi will insert a call to initialize the
-- choice parameter.
if Present (Choice_Parameter (Handler))
and then (Exception_Mechanism /= Back_End_Exceptions
and then (Front_End_Exceptions
or else CodePeer_Mode)
then
declare
@ -1102,7 +1104,7 @@ package body Exp_Ch11 is
-- are allowed.
if Abort_Allowed
and then Exception_Mechanism /= Back_End_Exceptions
and then not ZCX_Exceptions
then
-- There are some special cases in which we do not do the
-- undefer. In particular a finalization (AT END) handler
@ -1719,7 +1721,7 @@ package body Exp_Ch11 is
-- code which can be formally analyzed.
if not CodePeer_Mode
and then Exception_Mechanism = Back_End_Exceptions
and then Back_End_Exceptions
then
return;
end if;

View File

@ -7785,9 +7785,9 @@ package body Exp_Ch9 is
Is_Asynchronous_Call_Block => True);
-- Aborts are not deferred at beginning of exception handlers in
-- ZCX.
-- ZCX mode.
if Exception_Mechanism = Back_End_Exceptions then
if ZCX_Exceptions then
Handler_Stmt := Make_Null_Statement (Loc);
else

View File

@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@ -73,15 +73,14 @@ package body Exp_Sel is
Stmt : Node_Id;
begin
if Exception_Mechanism = Back_End_Exceptions then
-- With ZCX, aborts are not defered in handlers
-- With ZCX exceptions, aborts are not defered in handlers. With SJLJ,
-- they are deferred at the beginning of Abort_Signal handlers.
if ZCX_Exceptions then
Stmt := Make_Null_Statement (Loc);
else
-- With FE SJLJ, aborts are defered at the beginning of Abort_Signal
-- handlers.
else
Stmt :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),

View File

@ -178,7 +178,9 @@ extern Boolean In_Same_Source_Unit (Node_Id, Node_Id);
#define List_Representation_Info opt__list_representation_info
#define No_Strict_Aliasing_CP opt__no_strict_aliasing
typedef enum {Setjmp_Longjmp, Back_End_Exceptions} Exception_Mechanism_Type;
typedef enum {
Front_End_SJLJ, Back_End_ZCX, Back_End_SJLJ
} Exception_Mechanism_Type;
extern Boolean Back_End_Inlining;
extern Boolean Exception_Extra_Info;
@ -190,6 +192,16 @@ extern Boolean GNAT_Mode;
extern Int List_Representation_Info;
extern Boolean No_Strict_Aliasing_CP;
#define ZCX_Exceptions opt__zcx_exceptions
#define SJLJ_Exceptions opt__sjlj_exceptions
#define Front_End_Exceptions opt__front_end_exceptions
#define Back_End_Exceptions opt__back_end_exceptions
extern Boolean ZCX_Exceptions (void);
extern Boolean SJLJ_Exceptions (void);
extern Boolean Front_End_Exceptions (void);
extern Boolean Back_End_Exceptions (void);
/* restrict: */
#define No_Exception_Handlers_Set restrict__no_exception_handlers_set

View File

@ -3008,10 +3008,12 @@ gnatlib-shared:
gnatlib-sjlj:
$(MAKE) $(FLAGS_TO_PASS) EH_MECHANISM="" \
THREAD_KIND="$(THREAD_KIND)" ../stamp-gnatlib1-$(RTSDIR)
sed -e 's/ZCX_By_Default.*/ZCX_By_Default : constant Boolean := False;/' $(RTSDIR)/system.ads > $(RTSDIR)/s.ads
sed -e 's/\(pragma Linker.*crtbe.*\)/-- \1/' $(RTSDIR)/s.ads > $(RTSDIR)/s2.ads
$(RM) $(RTSDIR)/s.ads
$(MV) $(RTSDIR)/s2.ads $(RTSDIR)/system.ads
sed \
-e 's/Frontend_Exceptions.*/Frontend_Exceptions : constant Boolean := True;/' \
-e 's/ZCX_By_Default.*/ZCX_By_Default : constant Boolean := False;/' \
-e 's/\(pragma Linker.*crtbe.*\)/-- \1/' \
$(RTSDIR)/system.ads > $(RTSDIR)/s.ads
$(MV) $(RTSDIR)/s.ads $(RTSDIR)/system.ads
$(MAKE) $(FLAGS_TO_PASS) \
EH_MECHANISM="" \
GNATLIBFLAGS="$(GNATLIBFLAGS)" \
@ -3025,7 +3027,10 @@ gnatlib-sjlj:
gnatlib-zcx:
$(MAKE) $(FLAGS_TO_PASS) EH_MECHANISM="-gcc" \
THREAD_KIND="$(THREAD_KIND)" ../stamp-gnatlib1-$(RTSDIR)
sed -e 's/ZCX_By_Default.*/ZCX_By_Default : constant Boolean := True;/' $(RTSDIR)/system.ads > $(RTSDIR)/s.ads
sed \
-e 's/Frontend_Exceptions.*/Frontend_Exceptions : constant Boolean := False;/' \
-e 's/ZCX_By_Default.*/ZCX_By_Default : constant Boolean := True;/' \
$(RTSDIR)/system.ads > $(RTSDIR)/s.ads
$(MV) $(RTSDIR)/s.ads $(RTSDIR)/system.ads
$(MAKE) $(FLAGS_TO_PASS) \
EH_MECHANISM="-gcc" \

View File

@ -1501,7 +1501,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
exception handler, and we aren't using the GCC exception mechanism,
we must force this variable in memory in order to avoid an invalid
optimization. */
if (Exception_Mechanism != Back_End_Exceptions
if (Front_End_Exceptions ()
&& Has_Nested_Block_With_Handler (Scope (gnat_entity)))
TREE_ADDRESSABLE (gnu_decl) = 1;
@ -1520,9 +1520,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
/* If we are defining an object with variable size or an object with
fixed size that will be dynamically allocated, and we are using the
setjmp/longjmp exception mechanism, update the setjmp buffer. */
front-end setjmp/longjmp exception mechanism, update the setjmp
buffer. */
if (definition
&& Exception_Mechanism == Setjmp_Longjmp
&& Exception_Mechanism == Front_End_SJLJ
&& get_block_jmpbuf_decl ()
&& DECL_SIZE_UNIT (gnu_decl)
&& (TREE_CODE (DECL_SIZE_UNIT (gnu_decl)) != INTEGER_CST
@ -4099,7 +4100,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
trigger an "abnormal" transfer of control flow; thus they can be
neither "const" nor "pure" in the back-end sense. */
bool const_flag
= (Exception_Mechanism == Back_End_Exceptions
= (Back_End_Exceptions ()
&& Is_Pure (gnat_entity));
bool noreturn_flag = No_Return (gnat_entity);
bool return_by_direct_ref_p = false;

View File

@ -646,7 +646,7 @@ gigi (Node_Id gnat_root,
(TREE_STRING_POINTER (gnat_to_gnu (Ident_String (Main_Unit))));
/* If we are using the GCC exception mechanism, let GCC know. */
if (Exception_Mechanism == Back_End_Exceptions)
if (Back_End_Exceptions ())
gnat_init_gcc_eh ();
/* Initialize the GCC support for FP operations. */
@ -4923,14 +4923,14 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
tree gnu_jmpsave_decl = NULL_TREE;
tree gnu_jmpbuf_decl = NULL_TREE;
/* If just annotating, ignore all EH and cleanups. */
bool gcc_zcx = (!type_annotate_only
&& Present (Exception_Handlers (gnat_node))
&& Exception_Mechanism == Back_End_Exceptions);
bool setjmp_longjmp
bool gcc_eh = (!type_annotate_only
&& Present (Exception_Handlers (gnat_node))
&& Back_End_Exceptions ());
bool fe_sjlj
= (!type_annotate_only && Present (Exception_Handlers (gnat_node))
&& Exception_Mechanism == Setjmp_Longjmp);
&& Exception_Mechanism == Front_End_SJLJ);
bool at_end = !type_annotate_only && Present (At_End_Proc (gnat_node));
bool binding_for_block = (at_end || gcc_zcx || setjmp_longjmp);
bool binding_for_block = (at_end || gcc_eh || fe_sjlj);
tree gnu_inner_block; /* The statement(s) for the block itself. */
tree gnu_result;
tree gnu_expr;
@ -4953,17 +4953,17 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
condition to make it not ZCX specific.
If there are any exceptions or cleanup processing involved, we need an
outer statement group (for Setjmp_Longjmp) and binding level. */
outer statement group (for Fe_Sjlj) and binding level. */
if (binding_for_block)
{
start_stmt_group ();
gnat_pushlevel ();
}
/* If using setjmp_longjmp, make the variables for the setjmp buffer and save
/* If using fe_sjlj, make the variables for the setjmp buffer and save
area for address of previous buffer. Do this first since we need to have
the setjmp buf known for any decls in this block. */
if (setjmp_longjmp)
if (fe_sjlj)
{
gnu_jmpsave_decl
= create_var_decl (get_identifier ("JMPBUF_SAVE"), NULL_TREE,
@ -4973,7 +4973,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
NULL, gnat_node);
/* The __builtin_setjmp receivers will immediately reinstall it. Now
because of the unstructured form of EH used by setjmp_longjmp, there
because of the unstructured form of EH used by fe_sjlj, there
might be forward edges going to __builtin_setjmp receivers on which
it is uninitialized, although they will never be actually taken. */
TREE_NO_WARNING (gnu_jmpsave_decl) = 1;
@ -5008,7 +5008,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
If this is SJLJ, set our jmp_buf as the current buffer. */
start_stmt_group ();
if (setjmp_longjmp)
if (fe_sjlj)
{
gnu_expr = build_call_n_expr (set_jmpbuf_decl, 1,
build_unary_op (ADDR_EXPR, NULL_TREE,
@ -5031,7 +5031,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
/* Now generate code for the two exception models, if either is relevant for
this block. */
if (setjmp_longjmp)
if (fe_sjlj)
{
tree *gnu_else_ptr = 0;
tree gnu_handler;
@ -5103,7 +5103,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
gnu_jmpbuf_decl))),
gnu_handler, gnu_inner_block);
}
else if (gcc_zcx)
else if (gcc_eh)
{
tree gnu_handlers;
location_t locus;
@ -5147,11 +5147,11 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
}
/* Subroutine of gnat_to_gnu to translate gnat_node, an N_Exception_Handler,
to a GCC tree, which is returned. This is the variant for Setjmp_Longjmp
to a GCC tree, which is returned. This is the variant for front-end sjlj
exception handling. */
static tree
Exception_Handler_to_gnu_sjlj (Node_Id gnat_node)
Exception_Handler_to_gnu_fe_sjlj (Node_Id gnat_node)
{
/* Unless this is "Others" or the special "Non-Ada" exception for Ada, make
an "if" statement to select the proper exceptions. For "Others", exclude
@ -5216,10 +5216,11 @@ Exception_Handler_to_gnu_sjlj (Node_Id gnat_node)
}
/* Subroutine of gnat_to_gnu to translate gnat_node, an N_Exception_Handler,
to a GCC tree, which is returned. This is the variant for ZCX. */
to a GCC tree, which is returned. This is the variant for GCC exception
schemes. */
static tree
Exception_Handler_to_gnu_zcx (Node_Id gnat_node)
Exception_Handler_to_gnu_gcc (Node_Id gnat_node)
{
tree gnu_etypes_list = NULL_TREE;
tree gnu_current_exc_ptr, prev_gnu_incoming_exc_ptr;
@ -7294,10 +7295,10 @@ gnat_to_gnu (Node_Id gnat_node)
case N_Handled_Sequence_Of_Statements:
/* If there is an At_End procedure attached to this node, and the EH
mechanism is SJLJ, we must have at least a corresponding At_End
mechanism is front-end, we must have at least a corresponding At_End
handler, unless the No_Exception_Handlers restriction is set. */
gcc_assert (type_annotate_only
|| Exception_Mechanism != Setjmp_Longjmp
|| !Front_End_Exceptions ()
|| No (At_End_Proc (gnat_node))
|| Present (Exception_Handlers (gnat_node))
|| No_Exception_Handlers_Set ());
@ -7306,10 +7307,10 @@ gnat_to_gnu (Node_Id gnat_node)
break;
case N_Exception_Handler:
if (Exception_Mechanism == Setjmp_Longjmp)
gnu_result = Exception_Handler_to_gnu_sjlj (gnat_node);
else if (Exception_Mechanism == Back_End_Exceptions)
gnu_result = Exception_Handler_to_gnu_zcx (gnat_node);
if (Exception_Mechanism == Front_End_SJLJ)
gnu_result = Exception_Handler_to_gnu_fe_sjlj (gnat_node);
else if (Back_End_Exceptions ())
gnu_result = Exception_Handler_to_gnu_gcc (gnat_node);
else
gcc_unreachable ();
break;
@ -7317,7 +7318,7 @@ gnat_to_gnu (Node_Id gnat_node)
case N_Raise_Statement:
/* Only for reraise in back-end exceptions mode. */
gcc_assert (No (Name (gnat_node))
&& Exception_Mechanism == Back_End_Exceptions);
&& Back_End_Exceptions ());
start_stmt_group ();
gnat_pushlevel ();

View File

@ -527,9 +527,26 @@ procedure Gnat1drv is
-- Set and check exception mechanism
if Targparm.ZCX_By_Default_On_Target then
Exception_Mechanism := Back_End_Exceptions;
end if;
case Targparm.Frontend_Exceptions_On_Target is
when True =>
case Targparm.ZCX_By_Default_On_Target is
when True =>
Write_Line
("Run-time library configured incorrectly");
Write_Line
("(requesting support for Frontend ZCX exceptions)");
raise Unrecoverable_Error;
when False =>
Exception_Mechanism := Front_End_SJLJ;
end case;
when False =>
case Targparm.ZCX_By_Default_On_Target is
when True =>
Exception_Mechanism := Back_End_ZCX;
when False =>
Exception_Mechanism := Back_End_SJLJ;
end case;
end case;
-- Set proper status for overflow check mechanism

View File

@ -1565,13 +1565,6 @@ begin
Linker_Options.Increment_Last;
Linker_Options.Table
(Linker_Options.Last) := String_Access (Arg);
elsif Arg'Length = 6
and then Arg (Arg'First + 1 .. Arg'First + 5) = "fsjlj"
then
Linker_Options.Increment_Last;
Linker_Options.Table
(Linker_Options.Last) := String_Access (Arg);
end if;
elsif Arg'Length > 5

View File

@ -1182,7 +1182,11 @@ package body Lib.Writ is
Write_Info_Str (" UA");
end if;
if Exception_Mechanism = Back_End_Exceptions then
if Front_End_Exceptions then
Write_Info_Str (" FX");
end if;
if ZCX_Exceptions then
Write_Info_Str (" ZX");
end if;

View File

@ -192,6 +192,9 @@ package Lib.Writ is
-- the units in this file, where x is the first character
-- (upper case) of the policy name (e.g. 'C' for Concurrent).
-- FX Units in this file use front-end exceptions, with explicit
-- handlers to trigger AT-END actions on exception paths.
-- GP Set if this compilation was done in GNATprove mode, either
-- from direct use of GNATprove, or from use of -gnatdF.

View File

@ -1798,9 +1798,7 @@ package body Make is
-- according to the lang-specs.h.settings.
for K in First_Arg .. Last_Arg loop
if Args.Table (K).all = "-mrtp"
or else Args.Table (K).all = "-fsjlj"
then
if Args.Table (K).all = "-mrtp" then
Number_Of_Switches := Number_Of_Switches - 1;
end if;
end loop;

View File

@ -38,6 +38,44 @@ package body Opt is
SU : constant := Storage_Unit;
-- Shorthand for System.Storage_Unit
-------------------------
-- Back_End_Exceptions --
-------------------------
function Back_End_Exceptions return Boolean is
begin
return Exception_Mechanism = Back_End_SJLJ
or else Exception_Mechanism = Back_End_ZCX;
end Back_End_Exceptions;
-------------------------
-- Front_End_Exceptions --
-------------------------
function Front_End_Exceptions return Boolean is
begin
return Exception_Mechanism = Front_End_SJLJ;
end Front_End_Exceptions;
--------------------
-- SJLJ_Exceptions --
--------------------
function SJLJ_Exceptions return Boolean is
begin
return Exception_Mechanism = Back_End_SJLJ
or else Exception_Mechanism = Front_End_SJLJ;
end SJLJ_Exceptions;
--------------------
-- ZCX_Exceptions --
--------------------
function ZCX_Exceptions return Boolean is
begin
return Exception_Mechanism = Back_End_ZCX;
end ZCX_Exceptions;
----------------------------------
-- Register_Opt_Config_Switches --
----------------------------------

View File

@ -573,27 +573,41 @@ package Opt is
-- currently active.
type Exception_Mechanism_Type is
-- Determines the handling of exceptions. See Exp_Ch11 for details
-- Determines the kind of mechanism used to handle exceptions
--
(Front_End_Setjmp_Longjmp_Exceptions,
(Front_End_SJLJ,
-- Exceptions use setjmp/longjmp generated explicitly by the front end
-- (this includes gigi or other equivalent parts of the code generator).
-- AT END handlers are converted into exception handlers by the front
-- end in this mode.
Back_End_Exceptions);
Back_End_ZCX,
-- Exceptions are handled by the back end. The front end simply
-- generates the handlers as they appear in the source, and AT END
-- handlers are left untouched (they are not converted into exception
-- handlers when operating in this mode.
-- handlers when operating in this mode). Propagation is performed
-- using a frame unwinding scheme and requires no particular setup code
-- at handler sites on regular execution paths.
Back_End_SJLJ);
-- 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);
Exception_Mechanism : Exception_Mechanism_Type :=
Front_End_Setjmp_Longjmp_Exceptions;
Exception_Mechanism : Exception_Mechanism_Type := Front_End_SJLJ;
-- GNAT
-- Set to the appropriate value depending on the default as given in
-- system.ads (ZCX_By_Default). The C convention is there to make this
-- variable accessible to gigi.
-- Set to the appropriate value depending on the flags in system.ads
-- (Frontend_Exceptions + ZCX_By_Default). The C convention is there to
-- allow access by gigi.
function Back_End_Exceptions return Boolean;
function Front_End_Exceptions return Boolean;
function ZCX_Exceptions return Boolean;
function SJLJ_Exceptions return Boolean;
-- GNAT
-- Various properties of the active Exception_Mechanism
Exception_Tracebacks : Boolean := False;
-- GNATBIND

View File

@ -49,6 +49,7 @@ package body Targparm is
DEN, -- Denorm
EXS, -- Exit_Status_Supported
FEL, -- Frontend_Layout
FEX, -- Frontend_Exceptions
FFO, -- Fractional_Fixed_Ops
MOV, -- Machine_Overflows
MRN, -- Machine_Rounds
@ -64,7 +65,7 @@ package body Targparm is
SNZ, -- Signed_Zeros
SSL, -- Suppress_Standard_Library
UAM, -- Use_Ada_Main_Program_Name
ZCD); -- ZCX_By_Default
ZCX); -- ZCX_By_Default
Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
-- Flag is set True if corresponding parameter is scanned
@ -82,6 +83,7 @@ package body Targparm is
DEN_Str : aliased constant Source_Buffer := "Denorm";
EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
FEX_Str : aliased constant Source_Buffer := "Frontend_Exceptions";
FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
@ -97,7 +99,7 @@ package body Targparm is
SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
ZCX_Str : aliased constant Source_Buffer := "ZCX_By_Default";
-- The following defines a set of pointers to the above strings,
-- indexed by the tag values.
@ -115,6 +117,7 @@ package body Targparm is
DEN_Str'Access,
EXS_Str'Access,
FEL_Str'Access,
FEX_Str'Access,
FFO_Str'Access,
MOV_Str'Access,
MRN_Str'Access,
@ -130,7 +133,7 @@ package body Targparm is
SNZ_Str'Access,
SSL_Str'Access,
UAM_Str'Access,
ZCD_Str'Access);
ZCX_Str'Access);
-----------------------
-- Local Subprograms --
@ -804,6 +807,7 @@ package body Targparm is
when DEN => Denorm_On_Target := Result;
when EXS => Exit_Status_Supported_On_Target := Result;
when FEL => Frontend_Layout_On_Target := Result;
when FEX => Frontend_Exceptions_On_Target := Result;
when FFO => Fractional_Fixed_Ops_On_Target := Result;
when MOV => Machine_Overflows_On_Target := Result;
when MRN => Machine_Rounds_On_Target := Result;
@ -819,7 +823,7 @@ package body Targparm is
when SSL => Suppress_Standard_Library_On_Target := Result;
when SNZ => Signed_Zeros_On_Target := Result;
when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
when ZCD => ZCX_By_Default_On_Target := Result;
when ZCX => ZCX_By_Default_On_Target := Result;
goto Line_Loop_Continue;
end case;

View File

@ -234,66 +234,51 @@ package Targparm is
-- This approach uses longjmp/setjmp to handle exceptions. It
-- uses less storage, and can often propagate exceptions faster,
-- at the expense of (sometimes considerable) overhead in setting
-- up an exception handler. This approach is available on all
-- targets, and is the default where it is the only approach.
-- up an exception handler.
-- The generation of the setjmp and longjmp calls is handled by
-- the front end of the compiler (this includes gigi in the case
-- of the standard GCC back end). It does not use any back end
-- support (such as the GCC3 exception handling mechanism). When
-- this approach is used, the compiler generates special exception
-- handlers for handling cleanups when an exception is raised.
-- Front-End Zero Cost Exceptions
-- This approach uses separate exception tables. These use extra
-- storage, and exception propagation can be quite slow, but there
-- is no overhead in setting up an exception handler (it is to this
-- latter operation that the phrase zero-cost refers). This approach
-- is only available on some targets, and is the default where it is
-- available.
-- The generation of the exception tables is handled by the front
-- end of the compiler. It does not use any back end support (such
-- as the GCC3 exception handling mechanism). When this approach
-- is used, the compiler generates special exception handlers for
-- handling cleanups when an exception is raised.
-- handlers for handling cleanups (AT-END actions) when an exception
-- is raised.
-- Back-End Zero Cost Exceptions
-- With this approach, the back end handles the generation and
-- handling of exceptions. For example, the GCC3 exception handling
-- mechanisms are used in this mode. The front end simply generates
-- code for explicit exception handlers, and AT END cleanup handlers
-- code for explicit exception handlers, and AT-END cleanup handlers
-- are simply passed unchanged to the backend for generating cleanups
-- both in the exceptional and non-exceptional cases.
-- As the name implies, this approach generally uses a zero-cost
-- mechanism with tables, but the tables are generated by the back
-- end. However, since the back-end is entirely responsible for the
-- handling of exceptions, another mechanism might be used. In the
-- case of GCC3 for instance, it might be the case that the compiler
-- is configured for setjmp/longjmp handling, then everything will
-- work correctly. However, it is definitely preferred that the
-- back end provide zero cost exception handling.
-- As the name implies, this approach uses a table-based mechanism,
-- which incurs no setup when entering a region covered by handlers
-- but requires complex unwinding to walk up the call chain and search
-- for handlers at propagation time.
-- Controlling the selection of methods
-- Back-End Setjmp/Longjmp Exceptions
-- On most implementations, back-end zero-cost exceptions are used.
-- Otherwise, Front-End Longjmp/Setjmp approach is used.
-- Note that there is a requirement that all Ada units in a partition
-- be compiled with the same exception model.
-- With this approach, the back end also handles the generation and
-- handling of exceptions, using setjmp/longjmp to setup receivers and
-- propagate. AT-END actions on exceptional paths are also taken care
-- of by the back end and the front end doesn't need to generate
-- explicit exception handlers for these.
-- Control of Available Methods and Defaults
-- The following switches specify whether ZCX is available, and
-- whether it is enabled by default.
-- The following switches specify whether we're using a front-end or a
-- back-end mechanism and whether this is a zero-cost or a sjlj scheme.
-- The per switch default values correspond to the default value of
-- Opt.Exception_Mechanism.
ZCX_By_Default_On_Target : Boolean := False;
-- Indicates if zero cost exceptions are active by default. If this
-- variable is False, then the only possible exception method is the
-- front-end setjmp/longjmp approach, and this is the default. If
-- this variable is True, then GCC ZCX is used.
-- Indicates if zero cost scheme for exceptions
Frontend_Exceptions_On_Target : Boolean := True;
-- Indicates if we're using a front-end scheme for exceptions
------------------------------------
-- Run-Time Library Configuration --