Merge from mainline.
[official-gcc.git] / gcc / testsuite / gcc.dg / sparc-getcontext-1.c
blob762804cf78cce7697470c5a8cf921e2b185f6a3b
1 /* PR middle-end/22127 */
2 /* Testcase by <akr@m17n.org> */
4 /* [ dg-do run { target sparc*-sun-solaris2.* } } */
5 /* { dg-require-effective-target ilp32 } */
6 /* { dg-options "-O" } */
8 typedef unsigned int size_t;
9 extern int printf(const char *, ...);
10 typedef unsigned char uint8_t;
11 typedef unsigned int uint32_t;
12 typedef unsigned int uint_t;
13 typedef char *caddr_t;
14 typedef int greg_t;
15 typedef greg_t gregset_t[19];
16 struct rwindow {
17 greg_t rw_local[8];
18 greg_t rw_in[8];
20 typedef struct gwindows {
21 int wbcnt;
22 greg_t *spbuf[31];
23 struct rwindow wbuf[31];
24 } gwindows_t;
25 struct fpu {
26 union {
27 uint32_t fpu_regs[32];
28 double fpu_dregs[16];
29 } fpu_fr;
30 struct fq *fpu_q;
31 uint32_t fpu_fsr;
32 uint8_t fpu_qcnt;
33 uint8_t fpu_q_entrysize;
34 uint8_t fpu_en;
36 typedef struct fpu fpregset_t;
37 typedef struct {
38 unsigned int xrs_id;
39 caddr_t xrs_ptr;
40 } xrs_t;
41 typedef struct {
42 gregset_t gregs;
43 gwindows_t *gwins;
44 fpregset_t fpregs;
45 xrs_t xrs;
46 long filler[19];
47 } mcontext_t;
48 typedef struct {
49 unsigned int __sigbits[4];
50 } sigset_t;
51 typedef struct sigaltstack {
52 void *ss_sp;
53 size_t ss_size;
54 int ss_flags;
55 } stack_t;
56 typedef struct ucontext ucontext_t;
57 struct ucontext {
58 uint_t uc_flags;
59 ucontext_t *uc_link;
60 sigset_t uc_sigmask;
61 stack_t uc_stack;
62 mcontext_t uc_mcontext;
63 long uc_filler[23];
65 extern int getcontext(ucontext_t *);
66 extern int setcontext(const ucontext_t *);
68 int flag;
69 ucontext_t cont;
70 int pad[100];
71 typedef void (*fun_t)(int);
72 fun_t p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12;
74 int global;
76 extern void abort(void);
78 void h1(int v)
80 global = v;
83 void h2(int v)
85 if (v != 1)
86 abort();
89 void f(void)
91 flag = 1;
92 setcontext(&cont);
95 int g(void)
97 int ret;
99 flag = 0;
100 getcontext(&cont);
101 ret = flag;
102 if (ret == 0) {
103 h1 (flag);
104 p0 = p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = h1;
105 f();
106 p0(ret); p1(ret); p2(ret); p3(ret); p4(ret); p5(ret); p6(ret); p7(ret); p8(ret);
108 else {
109 h2 (flag);
111 return ret;
114 int main(void)
116 g();
117 return 0;