Bugzilla – Bug 298
[llvmgcc] Variable length array indexing miscompiled
Last modified: 2004-05-07 13:39:36
You need to log in before you can comment on or make changes to this bug.
It looks like we are miscompiling indexes through C99 VLA's in some cases. File this into the "wow, I didn't know you could do that" catagory. :) Testcase: --- int foo(int len, char arr[][len], int X) { return arr[X][0]; } --- The correct addressing arithmetic to generate is "arr + X*len", which we don't do in this case. -Chris
Here's another horrible testcase with the same issue: int sub1 (int i, int j) { typedef struct { int c[i+2]; }c; int x[10], y[10]; if (j == 2) { memcpy (x, y, 10 * sizeof (int)); return sizeof (c); } else return sizeof (c) * 3; } int main() { typedef struct { int c[22]; }c; if (sub1 (20, 3) != sizeof (c)*3) abort (); return 0; }
This patch: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040503/014167.html Fixes this testcase (test/Regression/CFrontend/2004-05-07-VarArrays.c): int foo(int len, char arr[][len], int X) { return arr[X][0]; } The second testcase attached to this bug is actually a bug in the non-LLVM specific portion of GCC, so it will magically be fixed when new bits are merged in. -Chris