First of all we talk about gcc/linux(x86, amd64) and c99.
Here is the code:
#include <stdint.h>
void f(void *p)
{
uint32_t *num = p;
*num = 17;
}
int main()
{
char buf[8] __attribute__ ((aligned (8)));
f(&buf[3]);
}
The question is it UB?
From one hand Intel CPU allow unalign access, from another hand I found this: http://www.uclibc.org/docs/psABI-i386.pdf http://www.x86-64.org/documentation/abi.pdf and both of them mention 4 byte align for 4byte integer.
So even if it compiles and works fine is it still UB? Because of gcc thinks that value of "uint32_t *" pointer point to 4 byte aligned address, and use, for example "SSE" in "f" function without hesitate?
The gcc maintainers think that such code is "undefined code": https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66194
Original question was from here (Russian language): https://ru.stackoverflow.com/questions/268888/%D0%9E%D0%BF%D1%8F%D1%82%D1%8C-%D0%BE%D0%B1-%D0%BE%D0%BF%D1%82%D0%B8%D0%BC%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D0%B8-gcc-o3-intel-i5-2500-segmentation-fault