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]

Patch: FYI: verifier fixlet


I'm checking this in.

This fixes a bug in the verifier.  If you had a branch which
branched to the immediately following instruction, you would get an
error.  This happened due to a small bug in note_branch_target.

Tom

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

	* verify.cc (_Jv_BytecodeVerifier::branch_prepass): Set start_PC
	earlier, for error handling.
	(_Jv_BytecodeVerifier::note_branch_target): Fixed branch target
	check.

Index: verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/verify.cc,v
retrieving revision 1.22
diff -u -r1.22 verify.cc
--- verify.cc 2001/12/07 03:30:47 1.22
+++ verify.cc 2001/12/07 19:51:20
@@ -1254,8 +1254,11 @@
 
   void note_branch_target (int pc, bool is_jsr_target = false)
   {
-    if (pc <= PC && ! (flags[pc] & FLAG_INSN_START))
-      verify_fail ("branch not to instruction start");
+    // Don't check `pc <= PC', because we've advanced PC after
+    // fetching the target and we haven't yet checked the next
+    // instruction.
+    if (pc < PC && ! (flags[pc] & FLAG_INSN_START))
+      verify_fail ("branch not to instruction start", start_PC);
     flags[pc] |= FLAG_BRANCH_TARGET;
     if (is_jsr_target)
       {
@@ -1395,6 +1398,9 @@
     PC = 0;
     while (PC < current_method->code_length)
       {
+	// Set `start_PC' early so that error checking can have the
+	// correct value.
+	start_PC = PC;
 	flags[PC] |= FLAG_INSN_START;
 
 	// If the previous instruction was a jsr, then the next
@@ -1404,7 +1410,6 @@
 	  note_branch_target (PC);
 	last_was_jsr = false;
 
-	start_PC = PC;
 	java_opcode opcode = (java_opcode) bytecode[PC++];
 	switch (opcode)
 	  {


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