In my recent C++ code;
I found Clang generated asm code use instruction movaps
to memset the object to 0.
because of this movaps
instruction need memory alignment of 16;
and when i use a self allocated buffer to initialize this object, the program was core.
because of the buffer allocated not aligned with 16 bytes.
- how clang decide the object's alignment will be 16 bytes ?
- how can i hint clang to don't use 16 bytes as the alignment, instead, use 8 bytes ?
example case is :
// a.h
class A {
A();
X x;
Y y;
Z z;
};
// a.cpp
A::A(): X(), Y(),Z(){}
// main.cpp
int main() {
char *buf = my_allocator(sizeof(A)); // buf was not aligned by 16bytes. but 8.
A *a=new(buf)A(); // cored.
return 1;
}