This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug java/17474] New: [4.0 Regression] Compiling at -01 yields different results


Thread model: win32
gcc version 4.0.0 20040913 (experimental)

gcj --main=codes codes.java  (works)
gcj -O1 --main=codes codes.java (gives different results)

class codes {

  static int[] lengths;
  static int[] codeValues;

  public static void main(String[] args) {

    lengths = new int[] {6,0,0,7,5,5,4,5,4,4,4,3,3,3,3,4,4,7,0};

    codeValues = new int[lengths.length];
    for (int i = 0; i < codeValues.length; i++) {
      codeValues[i] = i;
    }

    // Sort the values. Primary key is code size. Secondary key is value.
    for (int i = 0; i < lengths.length - 1; i++) {
      for (int j = i + 1; j < lengths.length; j++) {
        if (lengths[j] < lengths[i]
            || (lengths[j] == lengths[i]
              && codeValues[j] < codeValues[i]))
        {
          int tmp;
          tmp = lengths[j];
          lengths[j] = lengths[i];
          lengths[i] = tmp;
          tmp = codeValues[j];
          codeValues[j] = codeValues[i];
          codeValues[i] = tmp;
        }
      }
    }

    int[] codes = new int[lengths.length];
    int lastLength = 0;
    int code = 0;
    for (int i = 0; i < lengths.length; i++) {
      while (lastLength != lengths[i]) {
        lastLength++;
        code <<= 1;
        System.out.println("SET CODE: " + code);
      }
      if (lastLength != 0) {
        codes[i] = code;
        System.out.println("(Should be equal) SET CODES[" + i + "] = " + code 
+ " = " + codes[i]);
        code++;
      }
    }

  }

}

-- 
           Summary: [4.0 Regression] Compiling at -01 yields different
                    results
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ovidr at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17474


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