1 /* PR45070 */
2 extern void abort(void);
3 
4 struct packed_ushort {
5     unsigned short ucs;
6 } __attribute__((packed));
7 
8 struct source {
9     int pos, length;
10 };
11 
12 static int flag;
13 
fetch(struct source * p)14 static void __attribute__((noinline)) fetch(struct source *p)
15 {
16     p->length = 128;
17 }
18 
next(struct source * p)19 static struct packed_ushort __attribute__((noinline)) next(struct source *p)
20 {
21     struct packed_ushort rv;
22 
23     if (p->pos >= p->length) {
24 	if (flag) {
25 	    flag = 0;
26 	    fetch(p);
27 	    return next(p);
28 	}
29 	flag = 1;
30 	rv.ucs = 0xffff;
31 	return rv;
32     }
33     rv.ucs = 0;
34     return rv;
35 }
36 
main(void)37 int main(void)
38 {
39     struct source s;
40     int i;
41 
42     s.pos = 0;
43     s.length = 0;
44     flag = 0;
45 
46     for (i = 0; i < 16; i++) {
47 	struct packed_ushort rv = next(&s);
48 	if ((i == 0 && rv.ucs != 0xffff)
49 	    || (i > 0 && rv.ucs != 0))
50 	    abort();
51     }
52     return 0;
53 }
54