| 1 |
/* PR c++/34459 */ |
| 2 |
|
| 3 |
extern void abort (void); |
| 4 |
extern void *memset (void *s, int c, __SIZE_TYPE__ n); |
| 5 |
|
| 6 |
struct S |
| 7 |
{ |
| 8 |
char s[25]; |
| 9 |
}; |
| 10 |
|
| 11 |
struct S *p; |
| 12 |
|
| 13 |
void __attribute__((noinline,noclone)) |
| 14 |
foo (struct S *x, int set) |
| 15 |
{ |
| 16 |
int i; |
| 17 |
for (i = 0; i < sizeof (x->s); ++i) |
| 18 |
if (x->s[i] != 0) |
| 19 |
abort (); |
| 20 |
else if (set) |
| 21 |
x->s[i] = set; |
| 22 |
p = x; |
| 23 |
} |
| 24 |
|
| 25 |
void __attribute__((noinline,noclone)) |
| 26 |
test1 (void) |
| 27 |
{ |
| 28 |
struct S a; |
| 29 |
memset (&a.s, '\0', sizeof (a.s)); |
| 30 |
foo (&a, 0); |
| 31 |
struct S b = a; |
| 32 |
foo (&b, 1); |
| 33 |
b = a; |
| 34 |
b = b; |
| 35 |
foo (&b, 0); |
| 36 |
} |
| 37 |
|
| 38 |
void __attribute__((noinline,noclone)) |
| 39 |
test2 (void) |
| 40 |
{ |
| 41 |
struct S a; |
| 42 |
memset (&a.s, '\0', sizeof (a.s)); |
| 43 |
foo (&a, 0); |
| 44 |
struct S b = a; |
| 45 |
foo (&b, 1); |
| 46 |
b = a; |
| 47 |
b = *p; |
| 48 |
foo (&b, 0); |
| 49 |
} |
| 50 |
|
| 51 |
void __attribute__((noinline,noclone)) |
| 52 |
test3 (void) |
| 53 |
{ |
| 54 |
struct S a; |
| 55 |
memset (&a.s, '\0', sizeof (a.s)); |
| 56 |
foo (&a, 0); |
| 57 |
struct S b = a; |
| 58 |
foo (&b, 1); |
| 59 |
*p = a; |
| 60 |
*p = b; |
| 61 |
foo (&b, 0); |
| 62 |
} |
| 63 |
|
| 64 |
int |
| 65 |
main (void) |
| 66 |
{ |
| 67 |
test1 (); |
| 68 |
test2 (); |
| 69 |
test3 (); |
| 70 |
return 0; |
| 71 |
} |