[Ada] Introduce a Frontend_Exceptions flag in system.ads
Mon Nov 23 11:06:00 GMT 2015
The Ada compiler supports different sorts of exception schemes today. The two
most commonly used are what we commonly refer to as "frontend-sjlj", and
"gcc-zcx". The former is entirely managed by the front-end (gigi included),
relying on builtin_setjmp / builtin_longjmp pairs. The latter exposes the
exception related constructs to the middle-end, most often configured for
table based unwinding. We refer to table based schemes as "zero cost" with
respect to what happens in absence of propagation, hence the "zcx" abbrev
to denote "zero cost exceptions".
We can configure compilers to use the sjlj eh model as well but the front-end
internals aren't really prepared for this and this leads to bugs in some
The frontend perception of the EH scheme in use is currently controlled by the
"ZCX_By_Default" flag in system.ads. Very roughly, True is taken to denote
"gcc-zcx" and False conveys "frontend-sjlj". To allow proper support of
"gcc-sjlj", we introduce a "Frontend_Exceptions" flag and adjust the compiler
and runtimes accordingly.
This patch contains the front-end + Makefile part and a couple of adjustments
to the "tools", compensating for changes that were done preventively before,
when we had a different scheme in mind.
The compiler part involves a few general steps:
- Adjust the possible values of the Exception_Scheme variable (opt)
- Reflect this update in fe.h for gigi's consumption
- Handle the new flag throughout (targparm, lib-writ, ali, bcheck, gnat1drv)
- Adjust the abort_defer/abort_undefer call expansions to
trigger for ZCX instead of back-end eh (exp_ch9, exp_ch11, exp_sel).
- Adjust gigi to use the new mechanism values and helpers.
Then all the system.ads files will be updated with a correct value of the
Bootstrapped and regression tested on x86_64-linux-gnu. Committing to trunk.
* 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
* 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
* 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
(Check_Consistent_Exception_Handling): Check consistency of both
ZCX_By_Default and Frontend_Exceptions.
if either flag was set at least once.
* make.adb (Check): Remove processing of a possible -fsjlj coming from
* gnatlink.adb (Gnatlin): Likewise.
* 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
(case E_Procedure): Likewise.
* trans.c (Handled_Sequence_Of_Statements_to_gnu): Likewise, and rename
(Exception_Handler_to_gnu_sjlj): Rename as
(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.
* Makefile.in (gnatlib-sjlj/zcx): Now set both ZCX_By_Default and
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 36065 bytes
Desc: not available
-------------- next part --------------
More information about the Gcc-patches