public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Pettersson <mikpe@it.uu.se>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 4.4] backport PR fortran/39352 fix to unbreak ARM EABI and ia64
Date: Mon, 19 Oct 2009 20:18:00 -0000	[thread overview]
Message-ID: <19164.49184.902198.421414@pilspetsen.it.uu.se> (raw)

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  <mikpe@it.uu.se>

	Backport from mainline:
	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.

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:

                 reply	other threads:[~2009-10-19 19:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19164.49184.902198.421414@pilspetsen.it.uu.se \
    --to=mikpe@it.uu.se \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).