https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68462
Bug ID: 68462 Summary: -fno-strict-aliasing not respected Product: gcc Version: 4.8.4 Status: UNCONFIRMED Severity: major Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: manjeetdahiya at gmail dot com Target Milestone: --- For the following code -fno-strict-aliasing is not respected in function add_link_to_domain. The variable N_domains is cached before executing: domain_array[N_domains].lol = lol; domain_array[N_domains].size++; However, it should have been read again from the memory for the second statement. * I checked on clang-3.6 and it works as desired. * Another thing I noticed is that when I make the variable N_domains non-static -fno-strict-aliasing is respected. code listing: ------------- struct List_o_links{ struct List_o_links * next; }; struct Domain{ int size; struct List_o_links * lol; }; static int N_domains; int Size; static struct Domain domain_array[500]; void* mymalloc(int size); void add_link_to_domain(int link) { struct List_o_links *lol; lol = (struct List_o_links *) mymalloc(sizeof(struct List_o_links)); lol->next = domain_array[N_domains].lol; domain_array[N_domains].lol = lol; domain_array[N_domains].size++; } void build_dom() { int i; for(i = 0; i < Size; ++i) N_domains++; } Relevent assembly: ------------------ N_global static: call mymalloc movl N_domains, %edx movl domain_array+4(,%edx,8), %ecx addl $1, domain_array(,%edx,8) movl %eax, domain_array+4(,%edx,8) N_global non-static: call mymalloc movl N_domains, %edx movl domain_array+4(,%edx,8), %edx movl %edx, (%eax) movl N_domains, %edx movl %eax, domain_array+4(,%edx,8)