Issue 53147
Summary clang++ generate aligned avx code cause coredump.
Labels
Assignees
Reporter xsc351072127
    ```C
#include<stdio.h>
struct __attribute__ ((aligned (64)))
S
{
  S()
  {
    A[0]=0;
    A[1]=0;
    A[2]=0;
    A[3]=0;
    A[4]=0;
    A[5]=0;
    A[6]=0;
    A[7]=0;
  };
  long long A[8];
};

int main()
{
  S* s1 = new S();
  S* s2 = new S();
  S* s3 = new S();
  printf("s1=%p,s2=%p,s3=%p",s1,s2,s3);
  return 0;
}
```
When use the command:
`clang++ -O1 -mavx512vl -mavx512bw align_test.cpp -o at`
or
`clang++ -O1 -mavx2 -mfma align_test.cpp -o at`
And  run the at will get a coredump.

Because will got a simd instruction like  the after to clean the memory.
```
vxorps %xmm0,%xmm0,%xmm0
vmovaps %zmm0,(%rdi)
```
But the memory address alloc from new, may not be 64 byte aligned.
I use the g++ to complie these code, g++ will not optimization the memory clean or use the vmovups.
The laster version gcc will use the c++17  standard new() operator with alignment parament.
`void* operator new[]( std::size_t count, std::align_val_t al );`

Use the https://godbolt.org/ can see more detail difference with gcc and clang.

I can reappearance the case in clang 7 and clang 11 in my mechine and some other version in https://godbolt.org/.










_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to