This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, fortran] Patch for PR fortran/39352, using -fexceptions.
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org, Steve Ellcey <sje at cup dot hp dot com>, Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 15 May 2009 01:00:06 +0200
- Subject: Re: [patch, fortran] Patch for PR fortran/39352, using -fexceptions.
- References: <20090513120925.GA7526@net-b.de>
Tobias Burnus wrote:
>>> This patch for PR fortran/39352 initializes eh_personality_libfunc
>>>
This is an updated patch. The only difference to the previous version is
that the newly added headers are moved up to avoid the #define/undefine
trickery - and a completely unrelated patch to misc.c which avoids a
similar define trickery for gfc_free by using "(free)" instead of
"free". (Both suggested by Jakub. Thanks!)
The patch does the same as C does (c-decl.c's c_maybe_initialize_eh). It
only adds the eh_personality_libfunc if -fexception is set (which is the
default for C++ but not for C and Fortran) and then it only adds it when
OpenMP directives (other than atomic) are used. This is also in line
with C, cf. c-parser.c's c_parser_omp_construct.
The modified patch has been tested and bootstrapped on x86-64-linux. The
original patch has been bootstrapped successfully by Steve Ellcey on
IA64 Linux and HP-UX.
Ian today looked at the patch an concluded: the patch looks reasonable
though I don't understand all the details here. I think Jakub also
agreed with the patch (he gave some advices when I initially created
patch and suggested to get rid of the define trickery).
Unless there are objections, I plan to commit the patch tomorrow.
Tobias
2009-05-15 Tobias Burnus <burnus@net-b.de>
PR fortran/39352
* f95-lang.c: Add gfc_maybe_initialize_eh.
* gfortran.h: Add gfc_maybe_initialize_eh prototype.
* Make-lang.in: Add new .h dendencies for f95-lang.c
* openmp.c (resolve_omp_do): Call gfc_maybe_initialize_eh.
* misc.c (gfc_free): Avoid #define trickery for free.
Index: gcc/fortran/openmp.c
===================================================================
--- gcc/fortran/openmp.c (Revision 147534)
+++ gcc/fortran/openmp.c (Arbeitskopie)
@@ -1503,6 +1503,9 @@
void
gfc_resolve_omp_directive (gfc_code *code, gfc_namespace *ns ATTRIBUTE_UNUSED)
{
+ if (code->op != EXEC_OMP_ATOMIC)
+ gfc_maybe_initialize_eh ();
+
switch (code->op)
{
case EXEC_OMP_DO:
Index: gcc/fortran/Make-lang.in
===================================================================
--- gcc/fortran/Make-lang.in (Revision 147534)
+++ gcc/fortran/Make-lang.in (Arbeitskopie)
@@ -313,7 +313,8 @@
fortran/f95-lang.o: $(GFORTRAN_TRANS_DEPS) fortran/mathbuiltins.def \
gt-fortran-f95-lang.h gtype-fortran.h $(CGRAPH_H) $(TARGET_H) fortran/cpp.h \
- $(BUILTINS_DEF) fortran/types.def
+ $(BUILTINS_DEF) fortran/types.def \
+ libfuncs.h expr.h except.h
fortran/scanner.o: toplev.h fortran/cpp.h
fortran/convert.o: $(GFORTRAN_TRANS_DEPS)
fortran/trans.o: $(GFORTRAN_TRANS_DEPS) tree-iterator.h
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (Revision 147534)
+++ gcc/fortran/gfortran.h (Arbeitskopie)
@@ -2198,6 +2198,9 @@
int gfc_handle_option (size_t, const char *, int);
bool gfc_post_options (const char **);
+/* f95-lang.c */
+void gfc_maybe_initialize_eh (void);
+
/* iresolve.c */
const char * gfc_get_string (const char *, ...) ATTRIBUTE_PRINTF_1;
bool gfc_find_sym_in_expr (gfc_symbol *, gfc_expr *);
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c (Revision 147534)
+++ gcc/fortran/f95-lang.c (Arbeitskopie)
@@ -43,6 +43,10 @@
#include "diagnostic.h"
#include "tree-dump.h"
#include "cgraph.h"
+/* For gfc_maybe_initialize_eh. */
+#include "libfuncs.h"
+#include "expr.h"
+#include "except.h"
#include "gfortran.h"
#include "cpp.h"
@@ -165,6 +169,10 @@
It is indexed by a RID_... value. */
tree *ridpointers = NULL;
+/* True means we've initialized exception handling. */
+bool gfc_eh_initialized_p;
+
+
/* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
or validate its data type for an `if' or `while' statement or ?..: exp.
@@ -1223,5 +1231,21 @@
tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
}
+void
+gfc_maybe_initialize_eh (void)
+{
+ if (!flag_exceptions || gfc_eh_initialized_p)
+ return;
+
+ gfc_eh_initialized_p = true;
+ eh_personality_libfunc
+ = init_one_libfunc (USING_SJLJ_EXCEPTIONS
+ ? "__gcc_personality_sj0"
+ : "__gcc_personality_v0");
+ default_init_unwind_resume_libfunc ();
+ using_eh_for_cleanups ();
+}
+
+
#include "gt-fortran-f95-lang.h"
#include "gtype-fortran.h"
Index: gcc/fortran/misc.c
===================================================================
--- gcc/fortran/misc.c (Revision 147534)
+++ gcc/fortran/misc.c (Arbeitskopie)
@@ -42,23 +42,16 @@
}
-/* gfortran.h defines free to something that triggers a syntax error,
- but we need free() here. */
-
-#define temp free
-#undef free
-
void
gfc_free (void *p)
{
+ /* The parentheses around free are needed in order to call not
+ the redefined free of gfortran.h. */
if (p != NULL)
- free (p);
+ (free) (p);
}
-#define free temp
-#undef temp
-
/* Get terminal width. */
int