ei_declare_aligned_stack_constructed_variable alignment wrong with clang
Submitted by Eric Martin
Assigned to Nobody
Link to original bugzilla bug (#837)
Version: 3.2
Operating system: Linux
Description
This bug is both in Eigen 3.2.1 and today's unstable release (998455a5).
ei_declare_aligned_stack_constructed_variable (defined in Core/util/Memory.h) must return a 16 byte aligned pointer for loadLhs in Core/products/GeneralBlockPanelKernel.h to work (otherwise there is a segfault).
In clang, I have code where ei_declare_aligned_stack_constructed_variable returns a pointer that is not 16 byte aligned (only 8 byte aligned). I couldn't reduce this to a simple test case, but I did discover that my code is calling EIGEN_ALIGNED_ALLOCA and that EIGEN_ALIGN_BYTES=16. This means my call to ei_declare_aligned_stack is just a simple call to EIGEN_ALLOCA (no allocating extra space or anything).
Memory.h has a comment that LLVM aligns buffer on 16 bytes, but this contradicts that. I couldn't find any evidence that LLVM aligns on 16 bytes, and found this bug indicating the alignment for clang is actually 8 bytes: https://code.google.com/p/nativeclient/issues/detail?id=3795
Suggested fix:
change the EIGEN_ALIGN_BYTES > 16 check to EIGEN_ALIGN_BYTES > 8, or better yet (if you don't want to rely on undocumented features of clang), just always take that branch.
Also, the indentation is misleading in this header file and should be fixed.
Cheers,
Eric