Bug 37501 - VerifyError with assert when optimizing out unused local variables
Summary: VerifyError with assert when optimizing out unused local variables
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-12 11:21 EDT by Philipe Mulet CLA
Modified: 2003-06-06 07:19 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2003-05-12 11:21:30 EDT
Build R2.1

The following code will not verify if compiled in mode where unused locals are 
optimized out:

public class X {	
	public static void main(String[] argv){	
		int i;	
		assert argv != null || true : i;
		System.out.println("SUCCESS");	
	}
}


START RUNNING---------------------------------------------------

java.lang.VerifyError: (class: X, method: main signature: ([Ljava/lang/String;)
V) Illegal local variable number
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:140)
	at Compile.main(Compile.java:28)

DONE RUNNING----------------------------------------------------


DISASSEMBLING--------------------------------------------------
/* 
 * Version (target 1.4) 
 * - magic: CAFEBABE
 * - minor: 0
 * - major: 48
 */
// Compiled from X.java
public class X extends java.lang.Object {
  
  final static boolean $assertionsDisabled;
    Attribute:
      Name: Synthetic Length: 0
  /*  Field descriptor #6 Z */
  
  static java.lang.Class class$0;
    Attribute:
      Name: Synthetic Length: 0
  /*  Field descriptor #9 Ljava/lang/Class; */
  
  /*  Method descriptor  #11 ()V */
  static {};
    /* Stack: 3, Locals: 0 */
    Code attribute:
       0  getstatic #14 <Field X#class$0 java.lang.Class>
       3  dup
       4  ifnonnull 32
       7  pop
       8  ldc #15 <String "X">
      10  invokestatic #21 <Method java.lang.Class#forName(java.lang.String 
arg) java.lang.Class>
      13  dup
      14  putstatic #14 <Field X#class$0 java.lang.Class>
      17  goto 32
      20  new #23 java.lang.NoClassDefFoundError
      23  dup_x1
      24  swap
      25  invokevirtual #29 <Method java.lang.Throwable#getMessage() 
java.lang.String>
      28  invokespecial #33 <Constructor java.lang.NoClassDefFoundError
(java.lang.String arg)>
      31  athrow
      32  invokevirtual #37 <Method java.lang.Class#desiredAssertionStatus() 
boolean>
      35  ifne 42
      38  iconst_1
      39  goto 43
      42  iconst_0
      43  putstatic #39 <Field X#$assertionsDisabled boolean>
      46  return

    Exception Table:
      [pc: 8, pc: 13] -> 20 when : java.lang.ClassNotFoundException
      
    Line number attribute:
      [pc: 0, line: 1]
  
  /*  Method descriptor  #11 ()V */
  public X();
    /* Stack: 1, Locals: 1 */
    Code attribute:
      0  aload_0
      1  invokespecial #44 <Constructor java.lang.Object()>
      4  return

    Line number attribute:
      [pc: 0, line: 1]
  
  /*  Method descriptor  #46 ([Ljava/lang/String;)V */
  public static void main(String[] arg);
    /* Stack: 3, Locals: 1 */
    Code attribute:
       0  getstatic #39 <Field X#$assertionsDisabled boolean>
       3  ifne 19
       6  goto 19
       9  new #48 java.lang.AssertionError
      12  dup
      13  iload 255
      15  invokespecial #51 <Constructor java.lang.AssertionError(int arg)>
      18  athrow
      19  getstatic #57 <Field java.lang.System#out java.io.PrintStream>
      22  ldc #59 <String "SUCCESS">
      24  invokevirtual #64 <Method java.io.PrintStream#println
(java.lang.String arg) void>
      27  return

    Line number attribute:
      [pc: 0, line: 4]
      [pc: 19, line: 5]
      [pc: 27, line: 6]
  
}
Comment 1 Philipe Mulet CLA 2003-05-12 11:22:38 EDT
Offending line is:

13  iload 255
Comment 2 Olivier Thomann CLA 2003-05-12 11:30:55 EDT
In fact the whole block:
       9  new #48 java.lang.AssertionError
      12  dup
      13  iload 255
      15  invokespecial #51 <Constructor java.lang.AssertionError(int arg)>
      18  athrow

is unreachable. If the condition of the assert statement is inlined to true we
don't need to generate the assertion error because it cannot happen.
Comment 3 Philipe Mulet CLA 2003-05-12 12:17:34 EDT
Indeed. Fixed by optimizing out the entire chunk when condition is inlined to 
true.

Comment 4 Philipe Mulet CLA 2003-05-12 12:17:49 EDT
Fixed. 
Comment 5 Philipe Mulet CLA 2003-05-12 12:45:33 EDT
Fixed
Comment 6 David Audel CLA 2003-06-06 07:19:11 EDT
Verified.