[llvm-commits] [PATCH] RFC: fix some problems in GeneralHash

Joerg Sonnenberger joerg at britannica.bec.de
Sat Feb 25 00:43:40 PST 2012


On Sat, Feb 25, 2012 at 08:06:35AM +0000, Jay Foad wrote:
> On 25 February 2012 00:36, Chris Lattner <clattner at apple.com> wrote:
> >
> > On Feb 24, 2012, at 1:36 AM, Jay Foad wrote:
> >
> >> The attached patch lets the compiler remove the part of
> >> GeneralHash::addBytes which hashes the final 1 to 3 bytes, if it is
> >> known that we're hashing an array of T where sizeof (T) is a multiple
> >> of 4.
> >
> > Looks good to me.
> 
> Thanks. There's a subtle point here that I'm unsure about. Given:
> 
>   int f(int *p) {
>     int i;
>     memcpy(&i, p, sizeof i);
>     return i;
>   }
> 
> can the compiler assume that p is 4-aligned, because of its type? Or
> is it legal to take an arbitrary char*, cast it to int*, and pass it
> into this function?

As seen in the recent discussion about ARM optimisations, the compiler
can and does assume align(4). If you don't want that, either use char *p
or an explicit align attribute of 1.

Joerg



More information about the llvm-commits mailing list