Bug 117451

Summary: [compiler] Codegen could better optimize field access when value not required
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Philipe Mulet CLA 2005-11-22 04:13:43 EST
Build 3.2M3

Code generated for:
public class X {
  public float f0;
  
  public static void main(String[] args)
  {
    long l11 = -26;
    X x = new X();
    System.out.println(
        (((l11 < x.f0) || true) != false));
  }
}

requires the 'f0' field to be accessed (and popped) to ensure proper null check on x.f0.

But following code does not need the field access to be generated in bytecode:
public class X {
  public float f0;
  
  public void main(String[] args)
  {
    long l11 = -26;
    System.out.println(
        (((l11 < f0) || true) != false));
  }
}

or
public class X {
  public static float f0;
  
  public static void main(String[] args)
  {
    long l11 = -26;
    System.out.println(
        (((l11 < f0) || true) != false));
  }
}
Comment 1 Philipe Mulet CLA 2005-11-24 10:57:04 EST
Added BooleanTest#test031. Boolean tests test020,021,022,025,026,027 & 028 are also reflecting the fix.
Comment 2 Philipe Mulet CLA 2005-11-24 11:20:25 EST
Other scenario involving qualified name.
public class X {
	static float f0;
	public static void main(String[] args) {
		System.out.println((X.f0 > 0 || true) == false);
	} 
}
Comment 3 Philipe Mulet CLA 2005-11-25 12:52:40 EST
Tuned SingleNameReference, FieldReference and QualifiedNameReference.
Fixed
Comment 4 Frederic Fusier CLA 2005-12-13 09:58:11 EST
Verified for 3.2 M4 using build I20051213-0010