This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


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

Preincrement of array element


Aneesh Aggarwal reported a while ago that preincrements of array elements
don't work.  Did anyone ever come up with a patch for that?  It seems like a
fairly fundamental problem.  Or does this work for other people?

Here's a simple example that's well suited for debugging:

public class inc_test {
     static void inc(int[] a, int i) {
	++a[i];
     }
     public static void main(String [] args) {
        int a[];
        a = new int[2];
        for(int i = 0; i < 2; i++) {
                inc(a,i);
                System.out.println(" Value " + a[i]);
        }
     }
   }

The gcj compiled version prints two zeros.  gcj -C followed by gij prints
two ones, which is clearly the right answer.  This happens on both X86 and
Itanium, with all gcj versions I can find.

The inc function is clearly miscompiled.  As a nonexpert, and based on the
fact that gcj -C works, the tree looks OK to me.  The RTL code is wrong, in
that the store back into a[i] has been dropped.  So far I had a bit of
trouble following the translation process in more detail.

Hans


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