First Last Prev Next    No search results available
Details
: [llvmgcc] Variable length array indexing miscompiled
Bug#: 298
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.3

:
: miscompilation
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Unassigned LLVM Bugs <unassignedbugs@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2004-03-17 15:21
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
------- Comment #1 From Chris Lattner 2004-04-22 21:52:50 -------
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;
}
------- Comment #2 From Chris Lattner 2004-05-07 13:39:36 -------
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

First Last Prev Next    No search results available