From 48a24fcfc32ab00e84821c25af74252ff26b48b7 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 22 Jan 2013 09:49:14 +0000 Subject: [PATCH] gigi.h (ADT_unhandled_except_decl, [...]): New. * gcc-interface/gigi.h (ADT_unhandled_except_decl, ADT_unhandled_others_decl): New. (unhandled_others_decl, unhandled_except_decl): Define. * gcc-interface/trans.c: Include common/common-target.h. (gigi): Initialize them. (Subprogram_Body_to_gnu): On SEH targets, wrap the body of the main function in a try/catch clause. From-SVN: r195364 --- gcc/ada/ChangeLog | 10 ++++++++++ gcc/ada/gcc-interface/gigi.h | 6 +++++- gcc/ada/gcc-interface/trans.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index daf50ef..426c9a7 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2013-01-22 Tristan Gingold + + * gcc-interface/gigi.h (ADT_unhandled_except_decl, + ADT_unhandled_others_decl): New. + (unhandled_others_decl, unhandled_except_decl): Define. + * gcc-interface/trans.c: Include common/common-target.h. + (gigi): Initialize them. + (Subprogram_Body_to_gnu): On SEH targets, wrap the body of the main + function in a try/catch clause. + 2013-01-11 Eric Botcazou * gcc-interface/Make-lang.in (COMMON_ADAFLAGS): Remove -gnata. diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index 1d0d2fb..6fc3f34 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -6,7 +6,7 @@ * * * C Header File * * * - * Copyright (C) 1992-2012, Free Software Foundation, Inc. * + * Copyright (C) 1992-2013, 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- * @@ -413,8 +413,10 @@ enum standard_datatypes ADT_reraise_zcx_decl, ADT_begin_handler_decl, ADT_end_handler_decl, + ADT_unhandled_except_decl, ADT_others_decl, ADT_all_others_decl, + ADT_unhandled_others_decl, ADT_LAST}; /* Define kind of exception information associated with raise statements. */ @@ -460,7 +462,9 @@ extern GTY(()) tree gnat_raise_decls_ext[(int) LAST_REASON_CODE + 1]; #define begin_handler_decl gnat_std_decls[(int) ADT_begin_handler_decl] #define others_decl gnat_std_decls[(int) ADT_others_decl] #define all_others_decl gnat_std_decls[(int) ADT_all_others_decl] +#define unhandled_others_decl gnat_std_decls[(int) ADT_unhandled_others_decl] #define end_handler_decl gnat_std_decls[(int) ADT_end_handler_decl] +#define unhandled_except_decl gnat_std_decls[(int) ADT_unhandled_except_decl] /* Routines expected by the gcc back-end. They must have exactly the same prototype and names as below. */ diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 6ef6ee8..722ce73 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -37,6 +37,7 @@ #include "bitmap.h" #include "cgraph.h" #include "target.h" +#include "common/common-target.h" #include "ada.h" #include "adadecode.h" @@ -504,6 +505,13 @@ gigi (Node_Id gnat_root, int max_gnat_node, int number_name ATTRIBUTE_UNUSED, Empty); DECL_IGNORED_P (end_handler_decl) = 1; + unhandled_except_decl + = create_subprog_decl (get_identifier ("__gnat_unhandled_except_handler"), + NULL_TREE, + ftype, NULL_TREE, false, true, true, true, NULL, + Empty); + DECL_IGNORED_P (unhandled_except_decl) = 1; + reraise_zcx_decl = create_subprog_decl (get_identifier ("__gnat_reraise_zcx"), NULL_TREE, ftype, NULL_TREE, false, true, true, true, NULL, @@ -639,6 +647,12 @@ gigi (Node_Id gnat_root, int max_gnat_node, int number_name ATTRIBUTE_UNUSED, integer_type_node, NULL_TREE, true, false, true, false, NULL, Empty); + unhandled_others_decl + = create_var_decl (get_identifier ("UNHANDLED_OTHERS"), + get_identifier ("__gnat_unhandled_others_value"), + integer_type_node, NULL_TREE, true, false, true, false, + NULL, Empty); + main_identifier_node = get_identifier ("main"); /* Install the builtins we might need, either internally or as @@ -3495,6 +3509,26 @@ Subprogram_Body_to_gnu (Node_Id gnat_node) set_end_locus_from_node (gnu_result, gnat_node); set_end_locus_from_node (gnu_subprog_decl, gnat_node); + /* On SEH targets, install an exception handler around the main entry + point to catch unhandled exceptions. */ + if (DECL_NAME (gnu_subprog_decl) == main_identifier_node + && targetm_common.except_unwind_info (&global_options) == UI_SEH) + { + tree t; + tree etype; + + t = build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), + 1, integer_zero_node); + t = build_call_n_expr (unhandled_except_decl, 1, t); + + etype = build_unary_op (ADDR_EXPR, NULL_TREE, unhandled_others_decl); + etype = tree_cons (NULL_TREE, etype, NULL_TREE); + + t = build2 (CATCH_EXPR, void_type_node, etype, t); + gnu_result = build2 (TRY_CATCH_EXPR, TREE_TYPE (gnu_result), + gnu_result, t); + } + end_subprog_body (gnu_result); /* Finally annotate the parameters and disconnect the trees for parameters -- 2.7.4