This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix eh ICE with -foptimize-sibling-calls (take 2)


Hi!

The following patch fixes
ftp://people.redhat.com/jakub/gcc/testsuite/eh_sibcall.C
by going throw insn chain and marking all regions which have their labels in
there as used, then removing the rest (with the exception of ERT_THROW
regions which don't create any labels).
Bootstrapped on i386-redhat-linux, no regressions.
Ok to commit?

2002-01-14  Jakub Jelinek  <jakub@redhat.com>

	* except.c (remove_unreachable_regions): New.
	(free_eh_status): Clear exception_handler_labels.
	(convert_from_eh_region_ranges): Call remove_unreachable_regions.
	(find_exception_handler_labels): Don't add the same label more than
	once.
	(remove_exception_handler_label): Don't die if
	find_exception_handler_labels hasn't been called for the current
	function yet.

--- gcc/except.c.jj	Thu Jan  3 12:04:03 2002
+++ gcc/except.c	Mon Jan 14 18:51:39 2002
@@ -263,6 +263,7 @@ static rtx get_exception_filter			PARAMS
 static void collect_eh_region_array		PARAMS ((void));
 static void resolve_fixup_regions		PARAMS ((void));
 static void remove_fixup_regions		PARAMS ((void));
+static void remove_unreachable_regions		PARAMS ((rtx));
 static void convert_from_eh_region_ranges_1	PARAMS ((rtx *, int *, int));
 
 static struct eh_region *duplicate_eh_region_1	PARAMS ((struct eh_region *,
@@ -632,6 +633,7 @@ free_eh_status (f)
 
   free (eh);
   f->eh = NULL;
+  exception_handler_labels = NULL;
 }
 
 
@@ -1212,6 +1214,69 @@ remove_fixup_regions ()
     }
 }
 
+/* Remove all regions whose labels are not reachable from insns.  */
+
+static void
+remove_unreachable_regions (insns)
+     rtx insns;
+{
+  int i, *uid_region_num;
+  char *reachable;
+  struct eh_region *r;
+  rtx insn;
+
+  uid_region_num = xcalloc (get_max_uid (), sizeof(int));
+  reachable = xcalloc (cfun->eh->last_region_number + 1, 1);
+
+  for (i = cfun->eh->last_region_number; i > 0; --i)
+    {
+      r = cfun->eh->region_array[i];
+      if (!r || r->region_number != i)
+	continue;
+
+      if (r->resume)
+        {
+	  if (uid_region_num[INSN_UID (r->resume)])
+	    abort ();
+	  uid_region_num[INSN_UID (r->resume)] = i;
+        }
+      if (r->label)
+        {
+	  if (uid_region_num[INSN_UID (r->label)])
+	    abort ();
+	  uid_region_num[INSN_UID (r->label)] = i;
+        }
+      if (r->type == ERT_TRY && r->u.try.continue_label)
+        {
+	  if (uid_region_num[INSN_UID (r->u.try.continue_label)])
+	    abort ();
+	  uid_region_num[INSN_UID (r->u.try.continue_label)] = i;
+        }
+    }
+
+  for (insn = insns; insn; insn = NEXT_INSN (insn))
+    reachable[uid_region_num[INSN_UID (insn)]] = 1;
+
+  for (i = cfun->eh->last_region_number; i > 0; --i)
+    {
+      r = cfun->eh->region_array[i];
+      if (r && r->region_number == i && !reachable[i])
+	{
+	  /* Don't remove ERT_THROW regions if their outer region
+	     is reachable.  */
+	  if (r->type == ERT_THROW
+	      && r->outer
+	      && reachable[r->outer->region_number])
+	    continue;
+
+	  remove_eh_handler (r);
+	}
+    }
+
+  free (reachable);
+  free (uid_region_num);
+}
+
 /* Turn NOTE_INSN_EH_REGION notes into REG_EH_REGION notes for each
    can_throw instruction in the region.  */
 
@@ -1314,6 +1379,7 @@ convert_from_eh_region_ranges ()
   free (stack);
 
   remove_fixup_regions ();
+  remove_unreachable_regions (insns);
 }
 
 void
@@ -1332,7 +1398,7 @@ find_exception_handler_labels ()
       struct eh_region *region = cfun->eh->region_array[i];
       rtx lab;
 
-      if (! region)
+      if (! region || region->region_number != i)
 	continue;
       if (cfun->eh->built_landing_pads)
 	lab = region->landing_pad;
@@ -2427,6 +2493,11 @@ remove_exception_handler_label (label)
 {
   rtx *pl, l;
 
+  /* If exception_handler_labels was not built yet,
+     there is nothing to do.  */
+  if (exception_handler_labels == NULL)
+    return;
+
   for (pl = &exception_handler_labels, l = *pl;
        XEXP (l, 0) != label;
        pl = &XEXP (l, 1), l = *pl)

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]