verify.cc (_Jv_BytecodeVerifier::branch_prepass): Set start_PC earlier, for error...
authorTom Tromey <tromey@redhat.com>
Fri, 7 Dec 2001 19:53:34 +0000 (19:53 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 7 Dec 2001 19:53:34 +0000 (19:53 +0000)
* verify.cc (_Jv_BytecodeVerifier::branch_prepass): Set start_PC
earlier, for error handling.
(_Jv_BytecodeVerifier::note_branch_target): Fixed branch target
check.

From-SVN: r47769

libjava/ChangeLog
libjava/verify.cc

index ed3bafc49e1a651c9b0be95cfab0668d0dd560fb..067b30178fa2d9f99b9b03ae5f8c3ef94a29abf3 100644 (file)
@@ -1,3 +1,10 @@
+2001-12-07  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.
+
 2001-12-06  Tom Tromey  <tromey@redhat.com>
 
        * verify.cc (_Jv_BytecodeVerifier::FLAG_JSR_TARGET): Removed.
index 37935c4eca20026b55a74bad8b8c4e6bb4863d6c..b0206d15f983c202da89b5d0e1a6c9a4a6f69b30 100644 (file)
@@ -1254,8 +1254,11 @@ private:
 
   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 @@ private:
     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 @@ private:
          note_branch_target (PC);
        last_was_jsr = false;
 
-       start_PC = PC;
        java_opcode opcode = (java_opcode) bytecode[PC++];
        switch (opcode)
          {