summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/pr45070.c
blob: 95ff77aa0b0976505b59ac50b8a584575f756a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* PR45070 */
extern void abort(void);

struct packed_ushort {
    unsigned short ucs;
} __attribute__((packed));

struct source {
    int pos, length;
    int flag;
};

static void __attribute__((noinline)) fetch(struct source *p)
{
    p->length = 128;
}
    
static struct packed_ushort __attribute__((noinline)) next(struct source *p)
{
    struct packed_ushort rv;

    if (p->pos >= p->length) {
	if (p->flag) {
	    p->flag = 0;
	    fetch(p);
	    return next(p);
	}
	p->flag = 1;
	rv.ucs = 0xffff;
	return rv;
    }
    rv.ucs = 0;
    return rv;
}

int main(void)
{
    struct source s;
    int i;

    s.pos = 0;
    s.length = 0;
    s.flag = 0;

    for (i = 0; i < 16; i++) {
	struct packed_ushort rv = next(&s);
	if ((i == 0 && rv.ucs != 0xffff)
	    || (i > 0 && rv.ucs != 0))
	    abort();
    }
    return 0;
}