[LLVMdev] BasicAliasAnalysis and out-of-bound GEP indices
Daniel Berlin
dberlin at dberlin.org
Thu Nov 15 09:56:55 PST 2007
On 11/15/07, Duncan Sands <baldrick at free.fr> wrote:
> Hi,
>
> > Sadly, this will break a very common idiom. In GCC, we discovered it
> > to be common enough that it broke a *bunch* of C code.
> >
> > In particular, you will break
> >
> > struct foo {
> > int a;
> > char name[0];
> > }
> >
> > bar = malloc(sizeof (struct foo) + strlen("thisismyname") + 1);
> > strcpy(bar->name, "thisismyname");
> >
> >
> > It only started turning up when we started doing higher level loop
> > opts and used alias info in dependence testing. It would end up
> > reversing or interchanging loops around these things which while
> > legal, broke enough software that we got yelled at.
> >
> > So we special case the [0] at end of struct case.
>
> as noted in LangRef,
>
> "Note that 'variable sized arrays' can be implemented in LLVM with a zero
> length array. Normally, accesses past the end of an array are undefined in
> LLVM (e.g. it is illegal to access the 5th element of a 3 element array). As
> a special case, however, zero length arrays are recognized to be variable
> length. This allows implementation of 'pascal style arrays' with the LLVM
> type "{ i32, [0 x float]}", for example."
>
> so this example should work fine (it wouldn't work if it was char name[1]
> though).
>
Then the original reported code is fine, and the bug is in llvm or
llvm-gc (IE Owen is wrong)
Note:
struct device;
struct usb_bus {
struct device *controller;
};
struct usb_hcd {
struct usb_bus self;
unsigned long hcd_priv[0];
};
...
> Ciao,
>
> Duncan.
>
More information about the llvm-dev
mailing list