[cfe-dev] Alignment assumptions
Stephen Canon via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 14 07:38:27 PST 2017
Intel documents these types as follows:
"The compiler aligns the __m256, __m256d, and __m256i local and global data to 32-byte boundaries on the stack"
That’s awkwardly worded, but these types have 32B alignment; the result of casting a pointer that is not suitably aligned is undefined (i.e this is a bug in your code).
> On Dec 14, 2017, at 7:30 AM, Marcel Keller via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> The attached code segfaults with clang 3.8 and 4.0:
> $ clang++ -g -O3 -mavx main.cpp A.cpp ; ./a.out
> Segmentation fault
> The problem is in the following line:
> memset((__m256i*)dest, 0, length);
> Removing the cast to __m256i* solves the problem. It seems that clang assumes that __m256i* is always aligned correctly, which is not the case in the code. Is that a bug in clang, or is that a mistake on my side? GCC does not cause a segfault.
> Best regards,
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev