Apparent bug in "inlined" memcpy
Greetings,
Consider this test case:
#include <stdlib.h>
#include <string.h>
struct S { struct S *next; };
int main(int argc, char *argv[])
{
struct S s;
unsigned long expected;
s.next = (struct S*)malloc(sizeof(s));
memset(s.next,0xAE, sizeof(s));
memset(&expected, 0xAE, sizeof(expected));
if (argc < 2)
s = *(s.next); /* implicit memcpy */
else
memcpy(&s, s.next, sizeof(s));
return s.next == (void*)expected ? 0 : 1;
}
Expected result of this code is successful exit, which it does for gcc and CC.
With cc however, the code crashes:
$ cc -g junk.c
$ ./a.out 1 && echo ok
ok
$ ./a.out && echo ok
Segmentation Fault (core dumped)
This was observed with cc versions:
cc: Sun C 5.6 2004/07/15
cc: Sun C 5.7 2005/01/07
cc: Sun C 5.8 2005/10/13
It would appear that 'cc' inlines memcpy incorrectly.

