[LLVMdev] RFC: llvm-convert.cpp Patch

Bill Wendling isanbard at gmail.com
Fri Oct 26 13:22:22 PDT 2007


On 10/26/07, Duncan Sands <baldrick at free.fr> wrote:
> > llvm.memcpy docs says, " the caller guarantees that both the source
> > and destination pointers are aligned to that boundary.". Would it
> > possible to run into a situation where selecting min. of src and dest
> > alignment will not meet this criteria ?
>
> Since alignments are always powers of 2, the minimum of two alignments
> divides both of them.  So no, this is not possible.  However you do
> indeed have to be careful - just yesterday I noticed a mistake in LLVM
> in which it takes the minimum of an alignment and an object size to
> calculate a new alignment, which might be wrong if the object size is
> not a power of 2.  Think of an 8 byte aligned pointer to an x86 long double
> (which has size 12 on some machines), and update the pointer so it points
> to the following long double.  What is the new alignment?  It is not 8,
> the minimum of 8 and 12, it is 4.  I will send in a patch if I remember :)
>
That would be an illustration of why I don't want to change the
alignment globally. :-) memcpy uses i8*, so changing the alignment --
even to 1 -- should be okay.

-bw



More information about the llvm-dev mailing list