This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[gcjx] Patch: FYI: 'try' lowering bug fix


I'm checking this in on the gcjx branch.

It turns out that you aren't supposed to create a TRY_CATCH_EXPR with
an empty 'catch' part.  That causes crashes.  This patch fixes the
problem.

I'm collecting a list of tree oddities as I discover them, hopefully
I'll turn them into a documentation patch.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* tree.cc (visit_try): Don't create TRY_CATCH_EXPR if there are no
	catch blocks.

Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.29
diff -u -r1.1.2.29 tree.cc
--- tree.cc 27 Mar 2005 02:53:26 -0000 1.1.2.29
+++ tree.cc 27 Mar 2005 02:53:44 -0000
@@ -849,21 +849,31 @@
   body->visit (this);
   tree body_tree = current;
 
-  // Now generate trees for the catch clauses.
-  tree catch_tree = alloc_stmt_list ();
-  tree_stmt_iterator out = tsi_start (catch_tree);
-  for (std::list<ref_catch>::const_iterator i = catchers.begin ();
-       i != catchers.end ();
-       ++i)
+  assert (finally || ! catchers.empty ());
+
+  // Now generate trees for the catch clauses, but only if there are
+  // any.
+  tree result;
+
+  if (catchers.empty ())
+    result = body_tree;
+  else
     {
-      (*i)->visit (this);
-      // It is fine to simply link in CURRENT here, since we know that
-      // each catcher will just generate a CATCH_EXPR.
-      tsi_link_after (&out, current, TSI_CONTINUE_LINKING);
-    }
+      tree catch_tree = alloc_stmt_list ();
+      tree_stmt_iterator out = tsi_start (catch_tree);
+      for (std::list<ref_catch>::const_iterator i = catchers.begin ();
+	   i != catchers.end ();
+	   ++i)
+	{
+	  (*i)->visit (this);
+	  // It is fine to simply link in CURRENT here, since we know
+	  // that each catcher will just generate a CATCH_EXPR.
+	  tsi_link_after (&out, current, TSI_CONTINUE_LINKING);
+	}
 
-  // Generate an internal try-catch.
-  tree result = build2 (TRY_CATCH_EXPR, NULL_TREE, body_tree, catch_tree);
+      // Generate the internal try-catch.
+      result = build2 (TRY_CATCH_EXPR, NULL_TREE, body_tree, catch_tree);
+    }
 
   // Generate code for 'finally' if needed.
   if (finally)


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