1 /* { dg-do run } */ 2 3 extern void abort (void); 4 extern void *memcpy(void *, const void *, __SIZE_TYPE__); 5 6 typedef struct { 7 void *v1; 8 void *v2; 9 void *v3; 10 union { 11 void *f1; 12 void *f2; 13 } u; 14 } S; 15 16 17 S *getS(); 18 void verify_p(void *p); 19 double *getP(void *p); 20 memcpy_bug()21void memcpy_bug() 22 { 23 S *s; 24 double *p = getP(0); 25 26 if (p) { 27 int intSptr[sizeof(S*)/sizeof(int)]; 28 unsigned i = 0; 29 for (i = 0; i < sizeof(intSptr)/sizeof(*intSptr); ++i) { 30 intSptr[i] = (int) p[i]; 31 } 32 memcpy(&s, intSptr, sizeof(intSptr)); 33 (s)->u.f1 = p; 34 verify_p((s)->u.f1); 35 } else { 36 s = getS(); 37 } 38 verify_p(s->u.f1); 39 } 40 41 double P[4]; 42 getP(void * p)43double *getP(void *p) { 44 union u { 45 void *p; 46 int i[2]; 47 } u; 48 u.p = P; 49 P[0] = u.i[0]; 50 P[1] = u.i[1]; 51 return P; 52 } 53 getS()54S *getS() 55 { 56 return 0; 57 } 58 verify_p(void * p)59void verify_p(void *p) 60 { 61 if (p != P) 62 abort (); 63 } 64 main(int argc,char * argv[])65int main(int argc, char *argv[]) 66 { 67 memcpy_bug(); 68 return 0; 69 } 70 71