Preincrement of array element

Boehm, Hans hans_boehm@hp.com
Tue Sep 25 17:37:00 GMT 2001


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


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /