Alignment assumptions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Alignment assumptions

Alex Denisov via cfe-dev
Hi,

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,
Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

A.h (182 bytes) Download Attachment
main.cpp (62 bytes) Download Attachment
A.cpp (157 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Alignment assumptions

Alex Denisov via cfe-dev
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).

– Steve

On Dec 14, 2017, at 7:30 AM, Marcel Keller via cfe-dev <[hidden email]> wrote:

Hi,

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,
Marcel
<A.h><main.cpp><A.cpp>_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev