Notice that the alignment of the llvm.memcpy.i64 is 8 but the
alignment of Qux isn't -- it's 1 (n.b. the object is placed into the
redzone). The problem stems from from llvm-convert.cpp getting the
memcpy statement's alignment from the source pointer. The change below
will set its alignment to the minimum of the dest and src pointers'
alignments. (I do a copy because I didn't want to change it for all
cases. If it's okay to change it for all cases, I can take the copy
out.)
Notice that the alignment of the llvm.memcpy.i64 is 8 but the
alignment of Qux isn't -- it's 1 (n.b. the object is placed into the
redzone). The problem stems from from llvm-convert.cpp getting the
memcpy statement's alignment from the source pointer.
The change below
will set its alignment to the minimum of the dest and src pointers'
alignments.
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 ?
(I do a copy because I didn't want to change it for all
cases. If it's okay to change it for all cases, I can take the copy
out.)
In this case, I *think* (not guarantee it is ok to change alignment of "{0}" expression node in place, because, I don't think this expr node will be shared with any another "{0}" expression. However, your conservative approach is also fine.
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.