This is the mail archive of the java-discuss@sources.redhat.com 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]

[PATCH] Java: verification of interface types


Tom Tromey's change of 2000-09-12 causes the verifier to accept
bytecode files that it should not.  (I discovered this while
trying to track down a Kawa code generation bug.)  This patch
handles interface types leniently without being lenient for
class types.

Some background: Neither our nor Sun's verifier are typesafe when it
comes to interface types.  Both use a kludge: The "intersection" of
two class types is their least common supertype, while the
intersection of two interface types is Object.  This meams some
type-unsafe bytecodes will slip through.  Tom's change makes the
intersection of any (incompatible) classes be Object; this means many
more invalid programs will slip by.  Sun catches type-unsafe interface
calls at run-time by type-checking at each invokeinterface call.  I
actually don't know if we catch this in Gcj after the constant-type
inteface method calls have been implemented.

The real solution would be an explicit representation (during
verification) of intersection types.  (We only need this for
interfaces, since the intersection of class types is just the least
common super-type.)  That should not be very difficult, but it will
have to wait until some other time.

2001-01-14  Per Bothner  <per@bothner.com>

	* expr.c (pop_type_0):  Only return object_ptr_type_node on mismatch
	if expeting an interface type.  Refines change of 2000-09-12.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/expr.c,v
retrieving revision 1.95
diff -u -p -r1.95 expr.c
--- expr.c	2001/01/14 21:48:10	1.95
+++ expr.c	2001/01/14 23:48:51
@@ -352,8 +352,8 @@ pop_type_0 (type, messagep)
       /* This is a kludge, but matches what Sun's verifier does.
 	 It can be tricked, but is safe as long as type errors
 	 (i.e. interface method calls) are caught at run-time. */
-      /* FIXME: this is worse than a kludge, probably.  */
-      return object_ptr_type_node;
+      else if (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (type))))
+	return object_ptr_type_node;
     }
   {
     const char *str1 = "expected type '";

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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