This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Preincrement of array element
- To: "'java at gcc dot gnu dot org'" <java at gcc dot gnu dot org>
- Subject: Preincrement of array element
- From: "Boehm, Hans" <hans_boehm at hp dot com>
- Date: Tue, 25 Sep 2001 17:37:41 -0700
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