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]

Small improvement to bytecode verifier error messages


Present CVS gets tons of bytecode verifier errors running the test
suite.  All the ones I looked at are of the form

BlankFinal.java: In class `BlankFinal':
BlankFinal.java: In method `BlankFinal.<clinit>()':
BlankFinal.java:10: expected type 'int' but stack contains 'int'
BlankFinal.java:10: verification error at PC=9
BlankFinal.java:10: expected type 'null' but stack contains 'null'

One might be inclined to suspect the compiler of losing its mind upon
seeing these error messages.  It turns out that the stack really is
messed up, but the error message generator is buggy.  It calls concat
with a bunch of strings including two calls to java's lang_printable_name, 
which uses a static buffer.  The second call clobbers the string
generated by the first call.

With this patch, it gives the much more reasonable

BlankFinal.java: In class `BlankFinal':
BlankFinal.java: In method `BlankFinal.<clinit>()':
BlankFinal.java:10: expected type 'int' but stack contains 'java.lang.Exception'
BlankFinal.java:10: verification error at PC=9
BlankFinal.java:10: expected type 'null' but stack contains 'int'

[due to the i386 calling conventions, the second call generates the
string on the left.]

I have compiled this patch and run it against a problem .class file,
but I have not run a full bootstrap or the test suite.  I don't know
what's wrong with the byte compiler.

The code on the branch is different and does not suffer from the bug.

zw

	* expr.c (pop_type_0): Save the result of the first
	lang_printable_name call in a scratch buffer, so it 
	won't be clobbered by the second call.

===================================================================
Index: java/expr.c
--- java/expr.c	2001/03/28 19:31:43	1.108
+++ java/expr.c	2001/04/03 00:24:58
@@ -356,9 +356,15 @@ pop_type_0 (type, messagep)
 	return object_ptr_type_node;
     }
 
-  *messagep = concat ("expected type '", lang_printable_name (type, 0),
-		      "' but stack contains '", lang_printable_name (t, 0),
-		      "'", NULL);
+  /* lang_printable_name uses a static buffer, so we must save the result
+     from calling it the first time.  */
+  {
+    char *temp = xstrdup (lang_printable_name (type, 0));
+    *messagep = concat ("expected type '", temp,
+			"' but stack contains '", lang_printable_name (t, 0),
+			"'", NULL);
+    free (temp);
+  }
   return type;
 }
 


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