Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / support / regression / tcc / 101_cleanup.c
blobde5dca27a35c6500c6204fca24477fad29b11abf
1 extern int printf(const char*, ...);
2 static int glob_i = 0;
4 void incr_glob_i(int *i)
6 glob_i += *i;
9 #define INCR_GI { \
10 int i __attribute__ ((__cleanup__(incr_glob_i))) = 1; \
13 #define INCR_GI0 INCR_GI INCR_GI INCR_GI INCR_GI
14 #define INCR_GI1 INCR_GI0 INCR_GI0 INCR_GI0 INCR_GI0
15 #define INCR_GI2 INCR_GI1 INCR_GI1 INCR_GI1 INCR_GI1
16 #define INCR_GI3 INCR_GI2 INCR_GI2 INCR_GI2 INCR_GI2
17 #define INCR_GI4 INCR_GI3 INCR_GI3 INCR_GI3 INCR_GI3
18 #define INCR_GI5 INCR_GI4 INCR_GI4 INCR_GI4 INCR_GI4
19 #define INCR_GI6 INCR_GI5 INCR_GI5 INCR_GI5 INCR_GI5
20 #define INCR_GI7 INCR_GI6 INCR_GI6 INCR_GI6 INCR_GI6
23 void check2(char **hum);
25 void check(int *j)
27 char * __attribute__ ((cleanup(check2))) stop_that = "wololo";
28 int chk = 0;
31 char * __attribute__ ((cleanup(check2))) stop_that = "plop";
34 non_plopage:
35 printf("---- %d\n", chk);
37 if (!chk) {
38 chk = 1;
39 goto non_plopage;
44 char * __attribute__ ((cleanup(check2))) stop_that = "tata !";
46 goto out;
47 stop_that = "titi";
49 again:
50 chk = 2;
52 char * __attribute__ ((cleanup(check2))) cascade1 = "1";
54 char * __attribute__ ((cleanup(check2))) cascade2 = "2";
56 char * __attribute__ ((cleanup(check2))) cascade3 = "3";
58 goto out;
59 cascade3 = "nope";
63 out:
64 if (chk != 2)
65 goto again;
68 char * __attribute__ ((cleanup(check2))) out = "last goto out";
69 ++chk;
70 if (chk != 3)
71 goto out;
74 return;
77 void check_oh_i(char *oh_i)
79 printf("c: %c\n", *oh_i);
82 void goto_hell(double *f)
84 printf("oo: %f\n", *f);
87 char *test()
89 char *__attribute__ ((cleanup(check2))) str = "I don't think this should be print(but gcc got it wrong too)";
91 return str;
94 void test_ret_subcall(char *that)
96 printf("should be print before\n");
99 void test_ret()
101 char *__attribute__ ((cleanup(check2))) that = "that";
102 return test_ret_subcall(that);
105 void test_ret2()
107 char *__attribute__ ((cleanup(check2))) that = "-that";
109 char *__attribute__ ((cleanup(check2))) that = "this should appear only once";
112 char *__attribute__ ((cleanup(check2))) that = "-that2";
113 return;
117 void test2(void) {
118 int chk = 0;
119 again:
120 if (!chk) {
121 char * __attribute__ ((cleanup(check2))) stop_that = "test2";
122 chk++;
123 goto again;
127 int test3(void) {
128 char * __attribute__ ((cleanup(check2))) stop_that = "three";
129 int chk = 0;
131 if (chk) {
133 outside:
135 char * __attribute__ ((cleanup(check2))) stop_that = "two";
136 printf("---- %d\n", chk);
140 if (!chk)
142 char * __attribute__ ((cleanup(check2))) stop_that = "one";
144 if (!chk) {
145 chk = 1;
146 goto outside;
149 return 0;
152 void cl(int *ip)
154 printf("%d\n", *ip);
157 void loop_cleanups(void)
159 __attribute__((cleanup(cl))) int l = 1000;
161 printf("-- loop 0 --\n");
162 for ( __attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
163 __attribute__((cleanup(cl))) int j = 100;
166 printf("-- loop 1 --\n");
167 for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
168 __attribute__((cleanup(cl))) int j = 200;
169 continue;
172 printf("-- loop 2 --\n");
173 for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
174 __attribute__((cleanup(cl))) int j = 300;
175 break;
178 printf("-- loop 3 --\n");
179 for (int i = 0; i < 2; ++i) {
180 __attribute__((cleanup(cl))) int j = 400;
181 switch (i) {
182 case 0:
183 continue;
184 default:
186 __attribute__((cleanup(cl))) int jj = 500;
187 break;
191 printf("after break\n");
194 int main()
196 int i __attribute__ ((__cleanup__(check))) = 0, not_i;
197 int chk = 0;
198 (void)not_i;
201 __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a';
204 INCR_GI7;
205 printf("glob_i: %d\n", glob_i);
206 naaaaaaaa:
207 if (!chk) {
208 __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'f';
209 double __attribute__ ((__cleanup__(goto_hell))) f = 2.6;
211 chk = 1;
212 goto naaaaaaaa;
214 i = 105;
215 printf("because what if free was call inside cleanup function %s\n", test());
216 test_ret();
217 test_ret2();
218 test2();
219 test3();
220 loop_cleanups();
221 return i;
224 void check2(char **hum)
226 printf("str: %s\n", *hum);