| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target fpic } */ |
| 3 |
/* { dg-options "-O2 -fPIC" } */ |
| 4 |
|
| 5 |
void (*pfn)(void); |
| 6 |
|
| 7 |
struct s |
| 8 |
{ |
| 9 |
void** q; |
| 10 |
int h; |
| 11 |
int t; |
| 12 |
int s; |
| 13 |
}; |
| 14 |
|
| 15 |
|
| 16 |
void* f (struct s *, struct s *) __attribute__ ((noinline, regparm(1))); |
| 17 |
|
| 18 |
void* |
| 19 |
__attribute__ ((regparm(1))) |
| 20 |
f (struct s *p, struct s *p2) |
| 21 |
{ |
| 22 |
void *gp, *gp1; |
| 23 |
int t, h, s, t2, h2, c, i; |
| 24 |
|
| 25 |
if (p2->h == p2->t) |
| 26 |
return 0; |
| 27 |
|
| 28 |
(*pfn) (); |
| 29 |
|
| 30 |
h = p->h; |
| 31 |
t = p->t; |
| 32 |
s = p->s; |
| 33 |
|
| 34 |
h2 = p2->h; |
| 35 |
t2 = p2->t; |
| 36 |
|
| 37 |
gp = p2->q[h2++]; |
| 38 |
|
| 39 |
c = (t2 - h2) / 2; |
| 40 |
for (i = 0; i != c; i++) |
| 41 |
{ |
| 42 |
if (t == h || (h == 0 && t == s - 1)) |
| 43 |
break; |
| 44 |
gp1 = p2->q[h2++]; |
| 45 |
p->q[t++] = gp1; |
| 46 |
if (t == s) |
| 47 |
t = 0; |
| 48 |
} |
| 49 |
|
| 50 |
p2->h = h2; |
| 51 |
return gp; |
| 52 |
} |
| 53 |
|
| 54 |
static void gn () { } |
| 55 |
|
| 56 |
int |
| 57 |
main() |
| 58 |
{ |
| 59 |
struct s s1, s2; |
| 60 |
void *q[10]; |
| 61 |
|
| 62 |
pfn = gn; |
| 63 |
|
| 64 |
s1.q = q; |
| 65 |
s1.h = 0; |
| 66 |
s1.t = 2; |
| 67 |
s1.s = 4; |
| 68 |
|
| 69 |
s2.q = q; |
| 70 |
s2.h = 0; |
| 71 |
s2.t = 4; |
| 72 |
s2.s = 2; |
| 73 |
|
| 74 |
f (&s1, &s2); |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |