diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5b963a1d532..bc6dd0b9645 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2009-05-15 Tobias Burnus + + 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. + 2009-05-14 Steven G. Kargl * dump-parse-tree.c (show_code_node): Add ERRMSG to the dumping diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in index ba81b93b688..5885a621933 100644 --- a/gcc/fortran/Make-lang.in +++ b/gcc/fortran/Make-lang.in @@ -313,7 +313,8 @@ GFORTRAN_TRANS_DEPS = fortran/gfortran.h fortran/libgfortran.h \ 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 diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 1aab3bf6cc3..97a071d06f9 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -43,6 +43,10 @@ along with GCC; see the file COPYING3. If not see #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 @@ static GTY(()) struct binding_level *free_binding_level; 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 @@ gfc_init_ts (void) 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" diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 86f2c5bf252..bc066bc8b8e 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2198,6 +2198,9 @@ unsigned int gfc_init_options (unsigned int, const char **); 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 *); diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c index 136b751a196..94d61c9ec86 100644 --- a/gcc/fortran/misc.c +++ b/gcc/fortran/misc.c @@ -42,22 +42,15 @@ gfc_getmem (size_t n) } -/* 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. */ diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 0e9dda80ce6..608d605c951 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -1503,6 +1503,9 @@ resolve_omp_do (gfc_code *code) 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: