[gcjx] Patch: FYI: fix method call

Tom Tromey tromey@redhat.com
Tue Mar 8 02:36:00 GMT 2005


I'm checking this in on the gcjx branch.

This fixes method calls via the vtable.  We didn't cast the result
properly.  Also this fixes builtins.cc to use build_function_type and
build_method_type_directly; I didn't know these existed.

Tom

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

	* builtins.cc (add): Use build_function_type and
	build_method_type_directly.  Use correct 'self' type for methods.

	* abi.cc (build_method_call): Cast vtable lookup to correct type.

Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 abi.cc
--- abi.cc 8 Mar 2005 00:34:35 -0000 1.1.2.8
+++ abi.cc 8 Mar 2005 01:15:36 -0000
@@ -103,10 +103,11 @@
 
       func = build2 (PLUS_EXPR, type_nativecode_ptr_ptr, dtable,
 		     convert (type_nativecode_ptr_ptr, index));
-      if (TARGET_VTABLE_USES_DESCRIPTORS)
-	func = build1 (NOP_EXPR, type_nativecode_ptr, func);
-      else
+      if (! TARGET_VTABLE_USES_DESCRIPTORS)
 	func = build1 (INDIRECT_REF, type_nativecode_ptr, func);
+      // Cast back to the correct type, not just 'void *'.
+      func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (meth_tree)),
+		     func);
     }
 
   // METH_TREE is a method decl, so we need one TREE_TYPE to get the
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 builtins.cc
--- builtins.cc 8 Mar 2005 00:53:04 -0000 1.1.2.13
+++ builtins.cc 8 Mar 2005 01:15:36 -0000
@@ -81,24 +81,23 @@
 void
 tree_builtins::add (tree context, model_method *meth)
 {
-  // Create a function or method type.
-  tree mtype = make_node (meth->static_p () ? FUNCTION_TYPE : METHOD_TYPE);
-  if (! meth->static_p ())
-    TYPE_METHOD_BASETYPE (mtype) = map_type (meth->get_declaring_class ());
-  TREE_TYPE (mtype) = map_type (meth->get_return_type ());
-
   // Convert argument types.
   std::list<ref_variable_decl> args = meth->get_parameters ();
   tree argt = NULL_TREE;
-  if (! meth->static_p ())
-    argt = tree_cons (NULL_TREE, TYPE_METHOD_BASETYPE (mtype), argt);
   for (std::list<ref_variable_decl>::const_iterator i = args.begin ();
        i != args.end ();
        ++i)
     argt = tree_cons (NULL_TREE, map_type ((*i)->type ()), argt);
-  TYPE_ARG_TYPES (mtype) = chainon (nreverse (argt), void_list_node);
+  argt = chainon (nreverse (argt), void_list_node);
 
-  layout_type (mtype);
+  // Create a function or method type.
+  tree ret_type = map_type (meth->get_return_type ());
+  tree mtype;
+  tree klass_ptr = map_type (meth->get_declaring_class ());
+  if (meth->static_p ())
+    mtype = build_function_type (ret_type, argt);
+  else
+    mtype = build_method_type_directly (TREE_TYPE (klass_ptr), ret_type, argt);
 
   // Now create the function decl.
   tree result = build_decl (FUNCTION_DECL,
@@ -115,7 +114,7 @@
   if (! meth->static_p ())
     {
       tree this_decl = build_decl (PARM_DECL, get_identifier ("this"),
-				   TYPE_METHOD_BASETYPE (mtype));
+				   klass_ptr);
       DECL_CONTEXT (this_decl) = result;
       TREE_CHAIN (this_decl) = formals;
       formals = this_decl;
Index: lower.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/lower.cc,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 lower.cc
--- lower.cc 8 Mar 2005 00:22:45 -0000 1.1.2.5
+++ lower.cc 8 Mar 2005 01:15:37 -0000
@@ -1100,8 +1100,7 @@
 				     ret);
 	    tsi_link_after (&statements, push (ret_label),
 			    TSI_CONTINUE_LINKING);
-	    insn = build1 (GOTO_EXPR, void_type_node,
-			   dest);
+	    insn = build1 (GOTO_EXPR, void_type_node, dest);
 	  }
 	  break;
 
@@ -1110,23 +1109,18 @@
 	    int here = pc - 1;
 	    tree dest = find_label (here + get2s (bytes, pc));
 	    tree ret = find_label (pc);
-	    tree ret_label = build1 (ADDR_EXPR,
-				     type_nativecode_ptr,
-				     ret);
+	    tree ret_label = build1 (ADDR_EXPR, type_nativecode_ptr, ret);
 	    tsi_link_after (&statements, push (ret_label),
 			    TSI_CONTINUE_LINKING);
-	    insn = build1 (GOTO_EXPR, void_type_node,
-			   dest);
+	    insn = build1 (GOTO_EXPR, void_type_node, dest);
 	  }
 	  break;
 
 	case op_ret:
 	  {
 	    jint index = get1u (bytes, pc);
-	    tree where = load (index,
-			       type_nativecode_ptr);
-	    insn = build1 (GOTO_EXPR, void_type_node,
-			   where);
+	    tree where = load (index, type_nativecode_ptr);
+	    insn = build1 (GOTO_EXPR, void_type_node, where);
 	  }
 	  break;
 



More information about the Java-patches mailing list