Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / support / regression / tcc / 115_bound_setjmp.c
blob793db583f516110116fb785e7b857e76af02c2e4
1 #include <stdio.h>
2 #include <string.h>
3 #include <setjmp.h>
5 #define TST int i, a[2], b[2]; \
6 for (i = 0; i < 2; i++) a[i] = 0; \
7 for (i = 0; i < 2; i++) b[i] = 0
9 static jmp_buf jmp;
11 static void tst1 (void)
13 TST;
14 longjmp(jmp, 1);
17 static void tst2(void)
19 jmp_buf jmp;
21 setjmp (jmp);
22 TST;
23 tst1();
26 static void tst3 (jmp_buf loc)
28 TST;
29 longjmp(loc, 1);
32 static void tst4(jmp_buf loc)
34 jmp_buf jmp;
36 setjmp (jmp);
37 TST;
38 tst3(loc);
41 static void tst (void)
43 jmp_buf loc;
44 static int cnt;
46 cnt = 0;
47 if (setjmp (jmp) == 0) {
48 TST;
49 tst2();
51 else {
52 cnt++;
54 if (setjmp (loc) == 0) {
55 TST;
56 tst4(loc);
58 else {
59 cnt++;
61 if (cnt != 2)
62 printf ("incorrect cnt %d\n", cnt);
65 static jmp_buf buf1;
66 static jmp_buf buf2;
67 static int *p;
68 static int n_x = 6;
69 static int g_counter;
71 static void stack (void)
73 static int counter;
74 static int way_point1;
75 static int way_point2;
77 counter = 0;
78 way_point1 = 3;
79 way_point2 = 2;
80 g_counter = 0;
81 if (setjmp (buf1) != 101) {
82 int a[n_x];
83 g_counter++;
84 p = &a[0];
85 if (g_counter < 5)
86 longjmp (buf1, 2);
87 else if (g_counter == 5)
88 longjmp (buf1, 101);
89 else {
90 setjmp (buf2);
91 longjmp (buf1, 101);
95 way_point1--;
97 if (counter == 0) {
98 counter++;
100 int a[n_x];
101 g_counter++;
102 p = &a[0];
103 if (g_counter < 5)
104 longjmp (buf1, 2);
105 else if (g_counter == 5)
106 longjmp (buf1, 101);
107 else {
108 setjmp (buf2);
109 longjmp (buf1, 101);
114 way_point2--;
116 if (counter == 1) {
117 counter++;
118 longjmp (buf2, 2);
121 if (!(way_point1 == 0 && way_point2 == 0 &&
122 g_counter == 6 && counter == 2))
123 printf ("Failed %d %d %d %d\n",
124 way_point1, way_point2, g_counter, counter);
127 static jmp_buf env;
128 static int last_value;
130 static void jump (int val)
132 longjmp (env, val);
135 static void check (void)
137 int value;
139 last_value = -1;
140 value = setjmp (env);
141 if (value != last_value + 1) {
142 printf ("incorrect value %d %d\n",
143 value, last_value + 1);
144 return;
146 last_value = value;
147 switch (value) {
148 #if !(defined(__FreeBSD__) || defined(__NetBSD__))
149 /* longjmp(jmp_buf, 0) not supported */
150 case 0:
151 jump (0);
152 #endif
153 default:
154 if (value < 10)
155 jump (value + 1);
160 main (void)
162 int i;
164 for (i = 0; i < 10; i++) {
165 tst();
166 stack();
167 check();
169 return 0;