From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9050 invoked by alias); 19 Oct 2009 19:38:27 -0000 Received: (qmail 9042 invoked by uid 22791); 19 Oct 2009 19:38:26 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from fanny.its.uu.se (HELO fanny.its.uu.se) (130.238.4.241) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 19 Oct 2009 19:38:20 +0000 Received: by fanny.its.uu.se (Postfix, from userid 212) id BA43B63FD; Mon, 19 Oct 2009 21:38:17 +0200 (MSZ) Received: from pilspetsen.it.uu.se (pilspetsen.it.uu.se [130.238.18.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by fanny.its.uu.se (Postfix) with ESMTP id 454E0642C for ; Mon, 19 Oct 2009 21:38:09 +0200 (MSZ) Received: (from mikpe@localhost) by pilspetsen.it.uu.se (8.13.8+Sun/8.13.8) id n9JJc8NO010556; Mon, 19 Oct 2009 21:38:08 +0200 (MEST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19164.49184.902198.421414@pilspetsen.it.uu.se> Date: Mon, 19 Oct 2009 20:18:00 -0000 From: Mikael Pettersson To: gcc-patches@gcc.gnu.org Subject: [PATCH 4.4] backport PR fortran/39352 fix to unbreak ARM EABI and ia64 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2009-10/txt/msg01240.txt.bz2 The fortran pr39318.f90 test case ICEs gcc-4.4 on ARM EABI because fortran sets eh_personality_libfunc to NULL, causing a crash in output_addr_const(). The same issue was reported for ia64 in PR39352, and fixed for 4.5. This patch backports that fix to 4.4. Bootstrapped and regtested on {i686,powerpc64}-linux and armv5tel-linux-gnueabi. Verified to unbreak pr39318.f90 on ARM EABI. It probably also unbreaks the test case on ia64, but I cannot test that. Ok for 4.4? (I don't have write access.) gcc/fortran/ 2009-10-19 Mikael Pettersson Backport from mainline: 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. diff -rupN gcc-4.4.2/gcc/fortran/Make-lang.in gcc-4.4.2-pr39352/gcc/fortran/Make-lang.in --- gcc-4.4.2/gcc/fortran/Make-lang.in 2008-12-11 12:29:38.000000000 +0100 +++ gcc-4.4.2-pr39352/gcc/fortran/Make-lang.in 2009-10-18 15:40:48.000000000 +0200 @@ -313,7 +313,8 @@ GFORTRAN_TRANS_DEPS = fortran/gfortran.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 -rupN gcc-4.4.2/gcc/fortran/f95-lang.c gcc-4.4.2-pr39352/gcc/fortran/f95-lang.c --- gcc-4.4.2/gcc/fortran/f95-lang.c 2009-04-22 13:37:04.000000000 +0200 +++ gcc-4.4.2-pr39352/gcc/fortran/f95-lang.c 2009-10-18 15:40:48.000000000 +0200 @@ -43,6 +43,10 @@ along with GCC; see the file COPYING3. #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" @@ -168,6 +172,10 @@ static GTY(()) struct binding_level *fre 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. @@ -1227,5 +1235,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 -rupN gcc-4.4.2/gcc/fortran/gfortran.h gcc-4.4.2-pr39352/gcc/fortran/gfortran.h --- gcc-4.4.2/gcc/fortran/gfortran.h 2009-02-21 23:25:06.000000000 +0100 +++ gcc-4.4.2-pr39352/gcc/fortran/gfortran.h 2009-10-18 15:40:48.000000000 +0200 @@ -2167,6 +2167,9 @@ unsigned int gfc_init_options (unsigned 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 -rupN gcc-4.4.2/gcc/fortran/misc.c gcc-4.4.2-pr39352/gcc/fortran/misc.c --- gcc-4.4.2/gcc/fortran/misc.c 2008-05-03 22:37:48.000000000 +0200 +++ gcc-4.4.2-pr39352/gcc/fortran/misc.c 2009-10-18 15:40:48.000000000 +0200 @@ -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 -rupN gcc-4.4.2/gcc/fortran/openmp.c gcc-4.4.2-pr39352/gcc/fortran/openmp.c --- gcc-4.4.2/gcc/fortran/openmp.c 2009-07-28 18:33:08.000000000 +0200 +++ gcc-4.4.2-pr39352/gcc/fortran/openmp.c 2009-10-18 15:40:48.000000000 +0200 @@ -1504,6 +1504,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: