Bug 14974 - Bad generated code for '+=' and '-=' operators
Summary: Bad generated code for '+=' and '-=' operators
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-30 18:26 EDT by Luc Bourlier CLA
Modified: 2002-05-01 07:55 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 Luc Bourlier CLA 2002-04-30 18:26:56 EDT
Build 20020425++

The following code compiled with javac and run with java return '0'.
Compiled with the JDT compiler and run will java (in eclipse) return '-1'.

public class Foo2 {
  public static void main(String[] args) {
    int x = -8;
    x += 7.8f;
    System.out.println(x);
  }
}

The problem is when you generate the bytecode, you try to optimise the code by
used the iinc opcode if possible. But you do that even if the right operand is a
floating-point value, that can generate some probleme if we work on negative
value (as in the example).

I fix the probleme in my target by replacing the line 393 of
SingleNameReference.generateCompoundAssignment(BlockScope, CodeStream,
MethodBinding, Expression, int, int, boolean) with :

if (((assignConstant = expression.constant) != NotAConstant) &&
    /* new code */
    ((incrementTypeId = assignConstant.typeID()) != T_float) &&
    (incrementTypeId != T_double) &&
    /* */
   ((increment = assignConstant.intValue()) == (short) increment)) {
Comment 1 Philipe Mulet CLA 2002-05-01 07:55:16 EDT
Indeed, we should not optimize this case.
Good find.

Fixed