re-apply VLA by Thomas Preud'homme
[tinycc/miki.git] / tests / tcctest.c
blob8a6dd161fb8cbf5ba906b346fb2257702f21afcc
1 /*
2 * TCC auto test program
3 */
4 #include "../config.h"
6 #if GCC_MAJOR >= 3
8 /* Unfortunately, gcc version < 3 does not handle that! */
9 #define ALL_ISOC99
11 /* only gcc 3 handles _Bool correctly */
12 #define BOOL_ISOC99
14 /* gcc 2.95.3 does not handle correctly CR in strings or after strays */
15 #define CORRECT_CR_HANDLING
17 #endif
19 /* deprecated and no longer supported in gcc 3.3 */
20 //#define ACCEPT_CR_IN_STRINGS
22 /* __VA_ARGS__ and __func__ support */
23 #define C99_MACROS
25 /* test various include syntaxes */
27 #define TCCLIB_INC <tcclib.h>
28 #define TCCLIB_INC1 <tcclib
29 #define TCCLIB_INC2 h>
30 #define TCCLIB_INC3 "tcclib"
32 #include TCCLIB_INC
34 #include TCCLIB_INC1.TCCLIB_INC2
36 #include TCCLIB_INC1.h>
38 /* gcc 3.2 does not accept that (bug ?) */
39 //#include TCCLIB_INC3 ".h"
41 #include <tcclib.h>
43 #include "tcclib.h"
45 void string_test();
46 void expr_test();
47 void macro_test();
48 void recursive_macro_test();
49 void scope_test();
50 void forward_test();
51 void funcptr_test();
52 void loop_test();
53 void switch_test();
54 void goto_test();
55 void enum_test();
56 void typedef_test();
57 void struct_test();
58 void array_test();
59 void expr_ptr_test();
60 void bool_test();
61 void expr2_test();
62 void constant_expr_test();
63 void expr_cmp_test();
64 void char_short_test();
65 void init_test(void);
66 void compound_literal_test(void);
67 int kr_test();
68 void struct_assign_test(void);
69 void cast_test(void);
70 void bitfield_test(void);
71 void c99_bool_test(void);
72 void float_test(void);
73 void longlong_test(void);
74 void manyarg_test(void);
75 void stdarg_test(void);
76 void whitespace_test(void);
77 void relocation_test(void);
78 void old_style_function(void);
79 void alloca_test(void);
80 void c99_vla_test(int size1, int size2);
81 void sizeof_test(void);
82 void typeof_test(void);
83 void local_label_test(void);
84 void statement_expr_test(void);
85 void asm_test(void);
86 void builtin_test(void);
87 void weak_test(void);
89 int fib(int n);
90 void num(int n);
91 void forward_ref(void);
92 int isid(int c);
94 #define A 2
95 #define N 1234 + A
96 #define pf printf
97 #define M1(a, b) (a) + (b)
99 #define str\
100 (s) # s
101 #define glue(a, b) a ## b
102 #define xglue(a, b) glue(a, b)
103 #define HIGHLOW "hello"
104 #define LOW LOW ", world"
106 #define min(a, b) ((a) < (b) ? (a) : (b))
108 #ifdef C99_MACROS
109 #define dprintf(level,...) printf(__VA_ARGS__)
110 #endif
112 /* gcc vararg macros */
113 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
115 #define MACRO_NOARGS()
117 #define AAA 3
118 #undef AAA
119 #define AAA 4
121 #if 1
122 #define B3 1
123 #elif 1
124 #define B3 2
125 #elif 0
126 #define B3 3
127 #else
128 #define B3 4
129 #endif
131 #define __INT64_C(c) c ## LL
132 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
134 int qq(int x)
136 return x + 40;
138 #define qq(x) x
140 #define spin_lock(lock) do { } while (0)
141 #define wq_spin_lock spin_lock
142 #define TEST2() wq_spin_lock(a)
144 void macro_test(void)
146 printf("macro:\n");\f\v
147 pf("N=%d\n", N);
148 printf("aaa=%d\n", AAA);
150 printf("min=%d\n", min(1, min(2, -1)));
152 printf("s1=%s\n", glue(HIGH, LOW));
153 printf("s2=%s\n", xglue(HIGH, LOW));
154 printf("s3=%s\n", str("c"));
155 printf("s4=%s\n", str(a1));
156 printf("B3=%d\n", B3);
158 #ifdef A
159 printf("A defined\n");
160 #endif
161 #ifdef B
162 printf("B defined\n");
163 #endif
164 #ifdef A
165 printf("A defined\n");
166 #else
167 printf("A not defined\n");
168 #endif
169 #ifdef B
170 printf("B defined\n");
171 #else
172 printf("B not defined\n");
173 #endif
175 #ifdef A
176 printf("A defined\n");
177 #ifdef B
178 printf("B1 defined\n");
179 #else
180 printf("B1 not defined\n");
181 #endif
182 #else
183 printf("A not defined\n");
184 #ifdef B
185 printf("B2 defined\n");
186 #else
187 printf("B2 not defined\n");
188 #endif
189 #endif
191 #if 1+1
192 printf("test true1\n");
193 #endif
194 #if 0
195 printf("test true2\n");
196 #endif
197 #if 1-1
198 printf("test true3\n");
199 #endif
200 #if defined(A)
201 printf("test trueA\n");
202 #endif
203 #if defined(B)
204 printf("test trueB\n");
205 #endif
207 #if 0
208 printf("test 0\n");
209 #elif 0
210 printf("test 1\n");
211 #elif 2
212 printf("test 2\n");
213 #else
214 printf("test 3\n");
215 #endif
217 MACRO_NOARGS();
219 #ifdef __LINE__
220 printf("__LINE__ defined\n");
221 #endif
223 printf("__LINE__=%d __FILE__=%s\n",
224 __LINE__, __FILE__);
225 #line 200
226 printf("__LINE__=%d __FILE__=%s\n",
227 __LINE__, __FILE__);
228 #line 203 "test"
229 printf("__LINE__=%d __FILE__=%s\n",
230 __LINE__, __FILE__);
231 #line 227 "tcctest.c"
233 /* not strictly preprocessor, but we test it there */
234 #ifdef C99_MACROS
235 printf("__func__ = %s\n", __func__);
236 dprintf(1, "vaarg=%d\n", 1);
237 #endif
238 dprintf1(1, "vaarg1\n");
239 dprintf1(1, "vaarg1=%d\n", 2);
240 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
242 /* gcc extension */
243 printf("func='%s'\n", __FUNCTION__);
245 /* complicated macros in glibc */
246 printf("INT64_MIN=%Ld\n", INT64_MIN);
248 int a;
249 a = 1;
250 glue(a+, +);
251 printf("a=%d\n", a);
252 glue(a <, <= 2);
253 printf("a=%d\n", a);
256 /* macro function with argument outside the macro string */
257 #define MF_s MF_hello
258 #define MF_hello(msg) printf("%s\n",msg)
260 #define MF_t printf("tralala\n"); MF_hello
262 MF_s("hi");
263 MF_t("hi");
265 /* test macro substituion inside args (should not eat stream) */
266 printf("qq=%d\n", qq(qq)(2));
268 /* test zero argument case. NOTE: gcc 2.95.x does not accept a
269 null argument without a space. gcc 3.2 fixes that. */
271 #define qq1(x) 1
272 printf("qq1=%d\n", qq1( ));
274 /* comment with stray handling *\
276 /* this is a valid *\/ comment */
277 /* this is a valid comment *\*/
278 // this is a valid\
279 comment
281 /* test function macro substitution when the function name is
282 substituted */
283 TEST2();
287 static void print_num(char *fn, int line, int num) {
288 printf("fn %s, line %d, num %d\n", fn, line, num);
291 void recursive_macro_test(void)
293 #if 0 /* doesnt work yet */
294 #define ELF32_ST_TYPE(val) ((val) & 0xf)
295 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
296 #define STB_WEAK 2 /* Weak symbol */
297 #define ELFW(type) ELF##32##_##type
298 printf("%d\n", ELFW(ST_INFO)(STB_WEAK, ELFW(ST_TYPE)(123)));
299 #endif
301 #define WRAP(x) x
303 #define print_num(x) print_num(__FILE__,__LINE__,x)
304 print_num(123);
305 WRAP(print_num(123));
306 WRAP(WRAP(print_num(123)));
308 static struct recursive_macro { int rm_field; } G;
309 #define rm_field (G.rm_field)
310 printf("rm_field = %d\n", rm_field);
311 printf("rm_field = %d\n", WRAP(rm_field));
312 WRAP((printf("rm_field = %d %d\n", rm_field, WRAP(rm_field))));
315 int op(a,b)
317 return a / b;
320 int ret(a)
322 if (a == 2)
323 return 1;
324 if (a == 3)
325 return 2;
326 return 0;
329 void ps(const char *s)
331 int c;
332 while (1) {
333 c = *s;
334 if (c == 0)
335 break;
336 printf("%c", c);
337 s++;
341 const char foo1_string[] = "\
342 bar\n\
343 test\14\
346 void string_test()
348 unsigned int b;
349 printf("string:\n");
350 printf("\141\1423\143\n");/* dezdez test */
351 printf("\x41\x42\x43\x3a\n");
352 printf("c=%c\n", 'r');
353 printf("wc=%C 0x%lx %C\n", L'a', L'\x1234', L'c');
354 printf("foo1_string='%s'\n", foo1_string);
355 #if 0
356 printf("wstring=%S\n", L"abc");
357 printf("wstring=%S\n", L"abc" L"def" "ghi");
358 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
359 printf("L'\\377'=%d L'\\xff'=%d\n", L'\377', L'\xff');
360 #endif
361 ps("test\n");
362 b = 32;
363 while ((b = b + 1) < 96) {
364 printf("%c", b);
366 printf("\n");
367 printf("fib=%d\n", fib(33));
368 b = 262144;
369 while (b != 0x80000000) {
370 num(b);
371 b = b * 2;
375 void loop_test()
377 int i;
378 i = 0;
379 while (i < 10)
380 printf("%d", i++);
381 printf("\n");
382 for(i = 0; i < 10;i++)
383 printf("%d", i);
384 printf("\n");
385 i = 0;
386 do {
387 printf("%d", i++);
388 } while (i < 10);
389 printf("\n");
391 char count = 123;
392 /* c99 for loop init test */
393 for (size_t count = 1; count < 3; count++)
394 printf("count=%d\n", count);
395 printf("count = %d\n", count);
397 /* break/continue tests */
398 i = 0;
399 while (1) {
400 if (i == 6)
401 break;
402 i++;
403 if (i == 3)
404 continue;
405 printf("%d", i);
407 printf("\n");
409 /* break/continue tests */
410 i = 0;
411 do {
412 if (i == 6)
413 break;
414 i++;
415 if (i == 3)
416 continue;
417 printf("%d", i);
418 } while(1);
419 printf("\n");
421 for(i = 0;i < 10;i++) {
422 if (i == 3)
423 continue;
424 printf("%d", i);
426 printf("\n");
430 void goto_test()
432 int i;
433 static void *label_table[3] = { &&label1, &&label2, &&label3 };
435 printf("goto:\n");
436 i = 0;
437 s_loop:
438 if (i >= 10)
439 goto s_end;
440 printf("%d", i);
441 i++;
442 goto s_loop;
443 s_end:
444 printf("\n");
446 /* we also test computed gotos (GCC extension) */
447 for(i=0;i<3;i++) {
448 goto *label_table[i];
449 label1:
450 printf("label1\n");
451 goto next;
452 label2:
453 printf("label2\n");
454 goto next;
455 label3:
456 printf("label3\n");
457 next: ;
461 enum {
463 E1 = 2,
464 E2 = 4,
469 enum test {
470 E5 = 1000,
473 void enum_test()
475 enum test b1;
476 printf("enum:\n%d %d %d %d %d %d\n",
477 E0, E1, E2, E3, E4, E5);
478 b1 = 1;
479 printf("b1=%d\n", b1);
482 typedef int *my_ptr;
484 typedef int mytype1;
485 typedef int mytype2;
487 void typedef_test()
489 my_ptr a;
490 mytype1 mytype2;
491 int b;
493 a = &b;
494 *a = 1234;
495 printf("typedef:\n");
496 printf("a=%d\n", *a);
497 mytype2 = 2;
498 printf("mytype2=%d\n", mytype2);
501 void forward_test()
503 printf("forward:\n");
504 forward_ref();
505 forward_ref();
509 void forward_ref(void)
511 printf("forward ok\n");
514 typedef struct struct1 {
515 int f1;
516 int f2, f3;
517 union union1 {
518 int v1;
519 int v2;
520 } u;
521 char str[3];
522 } struct1;
524 struct struct2 {
525 int a;
526 char b;
529 union union2 {
530 int w1;
531 int w2;
534 struct struct1 st1, st2;
536 int main(int argc, char **argv)
538 string_test();
539 expr_test();
540 macro_test();
541 recursive_macro_test();
542 scope_test();
543 forward_test();
544 funcptr_test();
545 loop_test();
546 switch_test();
547 goto_test();
548 enum_test();
549 typedef_test();
550 struct_test();
551 array_test();
552 expr_ptr_test();
553 bool_test();
554 expr2_test();
555 constant_expr_test();
556 expr_cmp_test();
557 char_short_test();
558 init_test();
559 compound_literal_test();
560 kr_test();
561 struct_assign_test();
562 cast_test();
563 bitfield_test();
564 c99_bool_test();
565 float_test();
566 longlong_test();
567 manyarg_test();
568 stdarg_test();
569 whitespace_test();
570 relocation_test();
571 old_style_function();
572 alloca_test();
573 c99_vla_test(5, 2);
574 sizeof_test();
575 typeof_test();
576 statement_expr_test();
577 local_label_test();
578 asm_test();
579 builtin_test();
580 weak_test();
581 return 0;
584 int tab[3];
585 int tab2[3][2];
587 int g;
589 void f1(g)
591 printf("g1=%d\n", g);
594 void scope_test()
596 printf("scope:\n");
597 g = 2;
598 f1(1);
599 printf("g2=%d\n", g);
601 int g;
602 g = 3;
603 printf("g3=%d\n", g);
605 int g;
606 g = 4;
607 printf("g4=%d\n", g);
610 printf("g5=%d\n", g);
613 void array_test(int a[4])
615 int i, j;
617 printf("array:\n");
618 printf("sizeof(a) = %d\n", sizeof(a));
619 printf("sizeof(\"a\") = %d\n", sizeof("a"));
620 #ifdef C99_MACROS
621 printf("sizeof(__func__) = %d\n", sizeof(__func__));
622 #endif
623 printf("sizeof tab %d\n", sizeof(tab));
624 printf("sizeof tab2 %d\n", sizeof tab2);
625 tab[0] = 1;
626 tab[1] = 2;
627 tab[2] = 3;
628 printf("%d %d %d\n", tab[0], tab[1], tab[2]);
629 for(i=0;i<3;i++)
630 for(j=0;j<2;j++)
631 tab2[i][j] = 10 * i + j;
632 for(i=0;i<3*2;i++) {
633 printf(" %3d", ((int *)tab2)[i]);
635 printf("\n");
636 printf("sizeof(size_t)=%d\n", sizeof(size_t));
637 printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
640 void expr_test()
642 int a, b;
643 a = 0;
644 printf("%d\n", a += 1);
645 printf("%d\n", a -= 2);
646 printf("%d\n", a *= 31232132);
647 printf("%d\n", a /= 4);
648 printf("%d\n", a %= 20);
649 printf("%d\n", a &= 6);
650 printf("%d\n", a ^= 7);
651 printf("%d\n", a |= 8);
652 printf("%d\n", a >>= 3);
653 printf("%d\n", a <<= 4);
655 a = 22321;
656 b = -22321;
657 printf("%d\n", a + 1);
658 printf("%d\n", a - 2);
659 printf("%d\n", a * 312);
660 printf("%d\n", a / 4);
661 printf("%d\n", b / 4);
662 printf("%d\n", (unsigned)b / 4);
663 printf("%d\n", a % 20);
664 printf("%d\n", b % 20);
665 printf("%d\n", (unsigned)b % 20);
666 printf("%d\n", a & 6);
667 printf("%d\n", a ^ 7);
668 printf("%d\n", a | 8);
669 printf("%d\n", a >> 3);
670 printf("%d\n", b >> 3);
671 printf("%d\n", (unsigned)b >> 3);
672 printf("%d\n", a << 4);
673 printf("%d\n", ~a);
674 printf("%d\n", -a);
675 printf("%d\n", +a);
677 printf("%d\n", 12 + 1);
678 printf("%d\n", 12 - 2);
679 printf("%d\n", 12 * 312);
680 printf("%d\n", 12 / 4);
681 printf("%d\n", 12 % 20);
682 printf("%d\n", 12 & 6);
683 printf("%d\n", 12 ^ 7);
684 printf("%d\n", 12 | 8);
685 printf("%d\n", 12 >> 2);
686 printf("%d\n", 12 << 4);
687 printf("%d\n", ~12);
688 printf("%d\n", -12);
689 printf("%d\n", +12);
690 printf("%d %d %d %d\n",
691 isid('a'),
692 isid('g'),
693 isid('T'),
694 isid('('));
697 int isid(int c)
699 return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z') | c == '_';
702 /**********************/
704 int vstack[10], *vstack_ptr;
706 void vpush(int vt, int vc)
708 *vstack_ptr++ = vt;
709 *vstack_ptr++ = vc;
712 void vpop(int *ft, int *fc)
714 *fc = *--vstack_ptr;
715 *ft = *--vstack_ptr;
718 void expr2_test()
720 int a, b;
722 printf("expr2:\n");
723 vstack_ptr = vstack;
724 vpush(1432432, 2);
725 vstack_ptr[-2] &= ~0xffffff80;
726 vpop(&a, &b);
727 printf("res= %d %d\n", a, b);
730 void constant_expr_test()
732 int a;
733 printf("constant_expr:\n");
734 a = 3;
735 printf("%d\n", a * 16);
736 printf("%d\n", a * 1);
737 printf("%d\n", a + 0);
740 int tab4[10];
742 void expr_ptr_test()
744 int *p, *q;
745 int i = -1;
747 printf("expr_ptr:\n");
748 p = tab4;
749 q = tab4 + 10;
750 printf("diff=%d\n", q - p);
751 p++;
752 printf("inc=%d\n", p - tab4);
753 p--;
754 printf("dec=%d\n", p - tab4);
755 ++p;
756 printf("inc=%d\n", p - tab4);
757 --p;
758 printf("dec=%d\n", p - tab4);
759 printf("add=%d\n", p + 3 - tab4);
760 printf("add=%d\n", 3 + p - tab4);
762 /* check if 64bit support is ok */
763 q = p = 0;
764 q += i;
765 printf("%p %p %ld\n", q, p, p-q);
766 printf("%d %d %d %d %d %d\n",
767 p == q, p != q, p < q, p <= q, p >= q, p > q);
768 i = 0xf0000000;
769 p += i;
770 printf("%p %p %ld\n", q, p, p-q);
771 printf("%d %d %d %d %d %d\n",
772 p == q, p != q, p < q, p <= q, p >= q, p > q);
773 p = (int *)((char *)p + 0xf0000000);
774 printf("%p %p %ld\n", q, p, p-q);
775 printf("%d %d %d %d %d %d\n",
776 p == q, p != q, p < q, p <= q, p >= q, p > q);
777 p += 0xf0000000;
778 printf("%p %p %ld\n", q, p, p-q);
779 printf("%d %d %d %d %d %d\n",
780 p == q, p != q, p < q, p <= q, p >= q, p > q);
782 struct size12 {
783 int i, j, k;
785 struct size12 s[2], *sp = s;
786 int i, j;
787 sp->i = 42;
788 sp++;
789 j = -1;
790 printf("%d\n", sp[j].i);
794 void expr_cmp_test()
796 int a, b;
797 printf("constant_expr:\n");
798 a = -1;
799 b = 1;
800 printf("%d\n", a == a);
801 printf("%d\n", a != a);
803 printf("%d\n", a < b);
804 printf("%d\n", a <= b);
805 printf("%d\n", a <= a);
806 printf("%d\n", b >= a);
807 printf("%d\n", a >= a);
808 printf("%d\n", b > a);
810 printf("%d\n", (unsigned)a < b);
811 printf("%d\n", (unsigned)a <= b);
812 printf("%d\n", (unsigned)a <= a);
813 printf("%d\n", (unsigned)b >= a);
814 printf("%d\n", (unsigned)a >= a);
815 printf("%d\n", (unsigned)b > a);
818 struct empty {
821 struct aligntest1 {
822 char a[10];
825 struct aligntest2 {
826 int a;
827 char b[10];
830 struct aligntest3 {
831 double a, b;
834 struct aligntest4 {
835 double a[0];
838 void struct_test()
840 struct1 *s;
841 union union2 u;
843 printf("struct:\n");
844 printf("sizes: %d %d %d %d\n",
845 sizeof(struct struct1),
846 sizeof(struct struct2),
847 sizeof(union union1),
848 sizeof(union union2));
849 st1.f1 = 1;
850 st1.f2 = 2;
851 st1.f3 = 3;
852 printf("st1: %d %d %d\n",
853 st1.f1, st1.f2, st1.f3);
854 st1.u.v1 = 1;
855 st1.u.v2 = 2;
856 printf("union1: %d\n", st1.u.v1);
857 u.w1 = 1;
858 u.w2 = 2;
859 printf("union2: %d\n", u.w1);
860 s = &st2;
861 s->f1 = 3;
862 s->f2 = 2;
863 s->f3 = 1;
864 printf("st2: %d %d %d\n",
865 s->f1, s->f2, s->f3);
866 printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);
868 /* align / size tests */
869 printf("aligntest1 sizeof=%d alignof=%d\n",
870 sizeof(struct aligntest1), __alignof__(struct aligntest1));
871 printf("aligntest2 sizeof=%d alignof=%d\n",
872 sizeof(struct aligntest2), __alignof__(struct aligntest2));
873 printf("aligntest3 sizeof=%d alignof=%d\n",
874 sizeof(struct aligntest3), __alignof__(struct aligntest3));
875 printf("aligntest4 sizeof=%d alignof=%d\n",
876 sizeof(struct aligntest4), __alignof__(struct aligntest4));
878 /* empty structures (GCC extension) */
879 printf("sizeof(struct empty) = %d\n", sizeof(struct empty));
880 printf("alignof(struct empty) = %d\n", __alignof__(struct empty));
883 /* XXX: depend on endianness */
884 void char_short_test()
886 int var1, var2;
888 printf("char_short:\n");
890 var1 = 0x01020304;
891 var2 = 0xfffefdfc;
892 printf("s8=%d %d\n",
893 *(char *)&var1, *(char *)&var2);
894 printf("u8=%d %d\n",
895 *(unsigned char *)&var1, *(unsigned char *)&var2);
896 printf("s16=%d %d\n",
897 *(short *)&var1, *(short *)&var2);
898 printf("u16=%d %d\n",
899 *(unsigned short *)&var1, *(unsigned short *)&var2);
900 printf("s32=%d %d\n",
901 *(int *)&var1, *(int *)&var2);
902 printf("u32=%d %d\n",
903 *(unsigned int *)&var1, *(unsigned int *)&var2);
904 *(char *)&var1 = 0x08;
905 printf("var1=%x\n", var1);
906 *(short *)&var1 = 0x0809;
907 printf("var1=%x\n", var1);
908 *(int *)&var1 = 0x08090a0b;
909 printf("var1=%x\n", var1);
912 /******************/
914 typedef struct Sym {
915 int v;
916 int t;
917 int c;
918 struct Sym *next;
919 struct Sym *prev;
920 } Sym;
922 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
923 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
925 static int toupper1(int a)
927 return TOUPPER(a);
930 void bool_test()
932 int *s, a, b, t, f, i;
934 a = 0;
935 s = (void*)0;
936 printf("!s=%d\n", !s);
938 if (!s || !s[0])
939 a = 1;
940 printf("a=%d\n", a);
942 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
943 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
944 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
945 #if 1 && 1
946 printf("a1\n");
947 #endif
948 #if 1 || 0
949 printf("a2\n");
950 #endif
951 #if 1 ? 0 : 1
952 printf("a3\n");
953 #endif
954 #if 0 ? 0 : 1
955 printf("a4\n");
956 #endif
958 a = 4;
959 printf("b=%d\n", a + (0 ? 1 : a / 2));
961 /* test register spilling */
962 a = 10;
963 b = 10;
964 a = (a + b) * ((a < b) ?
965 ((b - a) * (a - b)): a + b);
966 printf("a=%d\n", a);
968 /* test complex || or && expressions */
969 t = 1;
970 f = 0;
971 a = 32;
972 printf("exp=%d\n", f == (32 <= a && a <= 3));
973 printf("r=%d\n", (t || f) + (t && f));
975 /* test ? : cast */
977 int aspect_on;
978 int aspect_native = 65536;
979 double bfu_aspect = 1.0;
980 int aspect;
981 for(aspect_on = 0; aspect_on < 2; aspect_on++) {
982 aspect=aspect_on?(aspect_native*bfu_aspect+0.5):65535UL;
983 printf("aspect=%d\n", aspect);
987 /* test ? : GCC extension */
989 static int v1 = 34 ? : -1; /* constant case */
990 static int v2 = 0 ? : -1; /* constant case */
991 int a = 30;
993 printf("%d %d\n", v1, v2);
994 printf("%d %d\n", a - 30 ? : a * 2, a + 1 ? : a * 2);
997 /* again complex expression */
998 for(i=0;i<256;i++) {
999 if (toupper1 (i) != TOUPPER (i))
1000 printf("error %d\n", i);
1004 /* GCC accepts that */
1005 static int tab_reinit[];
1006 static int tab_reinit[10];
1008 //int cinit1; /* a global variable can be defined several times without error ! */
1009 int cinit1;
1010 int cinit1;
1011 int cinit1 = 0;
1012 int *cinit2 = (int []){3, 2, 1};
1014 void compound_literal_test(void)
1016 int *p, i;
1017 char *q, *q3;
1019 printf("compound_test:\n");
1021 p = (int []){1, 2, 3};
1022 for(i=0;i<3;i++)
1023 printf(" %d", p[i]);
1024 printf("\n");
1026 for(i=0;i<3;i++)
1027 printf("%d", cinit2[i]);
1028 printf("\n");
1030 q = "tralala1";
1031 printf("q1=%s\n", q);
1033 q = (char *){ "tralala2" };
1034 printf("q2=%s\n", q);
1036 q3 = (char *){ q };
1037 printf("q3=%s\n", q3);
1039 q = (char []){ "tralala3" };
1040 printf("q4=%s\n", q);
1042 #ifdef ALL_ISOC99
1043 p = (int []){1, 2, cinit1 + 3};
1044 for(i=0;i<3;i++)
1045 printf(" %d", p[i]);
1046 printf("\n");
1048 for(i=0;i<3;i++) {
1049 p = (int []){1, 2, 4 + i};
1050 printf("%d %d %d\n",
1051 p[0],
1052 p[1],
1053 p[2]);
1055 #endif
1058 /* K & R protos */
1060 kr_func1(a, b)
1062 return a + b;
1065 int kr_func2(a, b)
1067 return a + b;
1070 kr_test()
1072 printf("kr_test:\n");
1073 printf("func1=%d\n", kr_func1(3, 4));
1074 printf("func2=%d\n", kr_func2(3, 4));
1075 return 0;
1078 void num(int n)
1080 char *tab, *p;
1081 tab = (char*)malloc(20);
1082 p = tab;
1083 while (1) {
1084 *p = 48 + (n % 10);
1085 p++;
1086 n = n / 10;
1087 if (n == 0)
1088 break;
1090 while (p != tab) {
1091 p--;
1092 printf("%c", *p);
1094 printf("\n");
1095 free(tab);
1098 /* structure assignment tests */
1099 struct structa1 {
1100 int f1;
1101 char f2;
1104 struct structa1 ssta1;
1106 void struct_assign_test1(struct structa1 s1, int t, float f)
1108 printf("%d %d %d %f\n", s1.f1, s1.f2, t, f);
1111 struct structa1 struct_assign_test2(struct structa1 s1, int t)
1113 s1.f1 += t;
1114 s1.f2 -= t;
1115 return s1;
1118 void struct_assign_test(void)
1120 struct structa1 lsta1, lsta2;
1122 #if 0
1123 printf("struct_assign_test:\n");
1125 lsta1.f1 = 1;
1126 lsta1.f2 = 2;
1127 printf("%d %d\n", lsta1.f1, lsta1.f2);
1128 lsta2 = lsta1;
1129 printf("%d %d\n", lsta2.f1, lsta2.f2);
1130 #else
1131 lsta2.f1 = 1;
1132 lsta2.f2 = 2;
1133 #endif
1134 struct_assign_test1(lsta2, 3, 4.5);
1136 printf("before call: %d %d\n", lsta2.f1, lsta2.f2);
1137 lsta2 = struct_assign_test2(lsta2, 4);
1138 printf("after call: %d %d\n", lsta2.f1, lsta2.f2);
1140 static struct {
1141 void (*elem)();
1142 } t[] = {
1143 /* XXX: we should allow this even without braces */
1144 { struct_assign_test }
1146 printf("%d\n", struct_assign_test == t[0].elem);
1149 /* casts to short/char */
1151 void cast1(char a, short b, unsigned char c, unsigned short d)
1153 printf("%d %d %d %d\n", a, b, c, d);
1156 char bcast;
1157 short scast;
1159 void cast_test()
1161 int a;
1162 char c;
1163 char tab[10];
1164 unsigned b,d;
1165 short s;
1166 char *p = NULL;
1167 p -= 0x700000000042;
1169 printf("cast_test:\n");
1170 a = 0xfffff;
1171 cast1(a, a, a, a);
1172 a = 0xffffe;
1173 printf("%d %d %d %d\n",
1174 (char)(a + 1),
1175 (short)(a + 1),
1176 (unsigned char)(a + 1),
1177 (unsigned short)(a + 1));
1178 printf("%d %d %d %d\n",
1179 (char)0xfffff,
1180 (short)0xfffff,
1181 (unsigned char)0xfffff,
1182 (unsigned short)0xfffff);
1184 a = (bcast = 128) + 1;
1185 printf("%d\n", a);
1186 a = (scast = 65536) + 1;
1187 printf("%d\n", a);
1189 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c), sizeof((int)c));
1191 /* test cast from unsigned to signed short to int */
1192 b = 0xf000;
1193 d = (short)b;
1194 printf("((unsigned)(short)0x%08x) = 0x%08x\n", b, d);
1195 b = 0xf0f0;
1196 d = (char)b;
1197 printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d);
1199 /* test implicit int casting for array accesses */
1200 c = 0;
1201 tab[1] = 2;
1202 tab[c] = 1;
1203 printf("%d %d\n", tab[0], tab[1]);
1205 /* test implicit casting on some operators */
1206 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1207 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1208 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1210 /* from pointer to integer types */
1211 printf("%d %d %ld %ld %lld %lld\n",
1212 (int)p, (unsigned int)p,
1213 (long)p, (unsigned long)p,
1214 (long long)p, (unsigned long long)p);
1216 /* from integers to pointers */
1217 printf("%p %p %p %p\n",
1218 (void *)a, (void *)b, (void *)c, (void *)d);
1221 /* initializers tests */
1222 struct structinit1 {
1223 int f1;
1224 char f2;
1225 short f3;
1226 int farray[3];
1229 int sinit1 = 2;
1230 int sinit2 = { 3 };
1231 int sinit3[3] = { 1, 2, {{3}}, };
1232 int sinit4[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1233 int sinit5[3][2] = { 1, 2, 3, 4, 5, 6 };
1234 int sinit6[] = { 1, 2, 3 };
1235 int sinit7[] = { [2] = 3, [0] = 1, 2 };
1236 char sinit8[] = "hello" "trala";
1238 struct structinit1 sinit9 = { 1, 2, 3 };
1239 struct structinit1 sinit10 = { .f2 = 2, 3, .f1 = 1 };
1240 struct structinit1 sinit11 = { .f2 = 2, 3, .f1 = 1,
1241 #ifdef ALL_ISOC99
1242 .farray[0] = 10,
1243 .farray[1] = 11,
1244 .farray[2] = 12,
1245 #endif
1248 char *sinit12 = "hello world";
1249 char *sinit13[] = {
1250 "test1",
1251 "test2",
1252 "test3",
1254 char sinit14[10] = { "abc" };
1255 int sinit15[3] = { sizeof(sinit15), 1, 2 };
1257 struct { int a[3], b; } sinit16[] = { { 1 }, 2 };
1259 struct bar {
1260 char *s;
1261 int len;
1262 } sinit17[] = {
1263 "a1", 4,
1264 "a2", 1
1267 int sinit18[10] = {
1268 [2 ... 5] = 20,
1270 [8] = 10,
1273 struct complexinit0 {
1274 int a;
1275 int b;
1278 struct complexinit {
1279 int a;
1280 const struct complexinit0 *b;
1283 const static struct complexinit cix[] = {
1284 [0] = {
1285 .a = 2000,
1286 .b = (const struct complexinit0[]) {
1287 { 2001, 2002 },
1288 { 2003, 2003 },
1294 struct complexinit2 {
1295 int a;
1296 int b[];
1299 struct complexinit2 cix21 = {
1300 .a = 3000,
1301 .b = { 3001, 3002, 3003 }
1304 struct complexinit2 cix22 = {
1305 .a = 4000,
1306 .b = { 4001, 4002, 4003, 4004, 4005, 4006 }
1309 void init_test(void)
1311 int linit1 = 2;
1312 int linit2 = { 3 };
1313 int linit4[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1314 int linit6[] = { 1, 2, 3 };
1315 int i, j;
1316 char linit8[] = "hello" "trala";
1317 int linit12[10] = { 1, 2 };
1318 int linit13[10] = { 1, 2, [7] = 3, [3] = 4, };
1319 char linit14[10] = "abc";
1320 int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, };
1321 struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 };
1322 int linit17 = sizeof(linit17);
1324 printf("init_test:\n");
1326 printf("sinit1=%d\n", sinit1);
1327 printf("sinit2=%d\n", sinit2);
1328 printf("sinit3=%d %d %d %d\n",
1329 sizeof(sinit3),
1330 sinit3[0],
1331 sinit3[1],
1332 sinit3[2]
1334 printf("sinit6=%d\n", sizeof(sinit6));
1335 printf("sinit7=%d %d %d %d\n",
1336 sizeof(sinit7),
1337 sinit7[0],
1338 sinit7[1],
1339 sinit7[2]
1341 printf("sinit8=%s\n", sinit8);
1342 printf("sinit9=%d %d %d\n",
1343 sinit9.f1,
1344 sinit9.f2,
1345 sinit9.f3
1347 printf("sinit10=%d %d %d\n",
1348 sinit10.f1,
1349 sinit10.f2,
1350 sinit10.f3
1352 printf("sinit11=%d %d %d %d %d %d\n",
1353 sinit11.f1,
1354 sinit11.f2,
1355 sinit11.f3,
1356 sinit11.farray[0],
1357 sinit11.farray[1],
1358 sinit11.farray[2]
1361 for(i=0;i<3;i++)
1362 for(j=0;j<2;j++)
1363 printf("[%d][%d] = %d %d %d\n",
1364 i, j, sinit4[i][j], sinit5[i][j], linit4[i][j]);
1365 printf("linit1=%d\n", linit1);
1366 printf("linit2=%d\n", linit2);
1367 printf("linit6=%d\n", sizeof(linit6));
1368 printf("linit8=%d %s\n", sizeof(linit8), linit8);
1370 printf("sinit12=%s\n", sinit12);
1371 printf("sinit13=%d %s %s %s\n",
1372 sizeof(sinit13),
1373 sinit13[0],
1374 sinit13[1],
1375 sinit13[2]);
1376 printf("sinit14=%s\n", sinit14);
1378 for(i=0;i<10;i++) printf(" %d", linit12[i]);
1379 printf("\n");
1380 for(i=0;i<10;i++) printf(" %d", linit13[i]);
1381 printf("\n");
1382 for(i=0;i<10;i++) printf(" %d", linit14[i]);
1383 printf("\n");
1384 for(i=0;i<10;i++) printf(" %d", linit15[i]);
1385 printf("\n");
1386 printf("%d %d %d %d\n",
1387 linit16.a1,
1388 linit16.a2,
1389 linit16.a3,
1390 linit16.a4);
1391 /* test that initialisation is done after variable declare */
1392 printf("linit17=%d\n", linit17);
1393 printf("sinit15=%d\n", sinit15[0]);
1394 printf("sinit16=%d %d\n", sinit16[0].a[0], sinit16[1].a[0]);
1395 printf("sinit17=%s %d %s %d\n",
1396 sinit17[0].s, sinit17[0].len,
1397 sinit17[1].s, sinit17[1].len);
1398 for(i=0;i<10;i++)
1399 printf("%x ", sinit18[i]);
1400 printf("\n");
1401 /* complex init check */
1402 printf("cix: %d %d %d %d %d %d %d\n",
1403 cix[0].a,
1404 cix[0].b[0].a, cix[0].b[0].b,
1405 cix[0].b[1].a, cix[0].b[1].b,
1406 cix[0].b[2].a, cix[0].b[2].b);
1407 printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]);
1408 printf("sizeof cix21 %d, sizeof cix22 %d\n", sizeof cix21, sizeof cix22);
1412 void switch_test()
1414 int i;
1416 for(i=0;i<15;i++) {
1417 switch(i) {
1418 case 0:
1419 case 1:
1420 printf("a");
1421 break;
1422 default:
1423 printf("%d", i);
1424 break;
1425 case 8 ... 12:
1426 printf("c");
1427 break;
1428 case 3:
1429 printf("b");
1430 break;
1433 printf("\n");
1436 /* ISOC99 _Bool type */
1437 void c99_bool_test(void)
1439 #ifdef BOOL_ISOC99
1440 int a;
1441 _Bool b;
1443 printf("bool_test:\n");
1444 printf("sizeof(_Bool) = %d\n", sizeof(_Bool));
1445 a = 3;
1446 printf("cast: %d %d %d\n", (_Bool)10, (_Bool)0, (_Bool)a);
1447 b = 3;
1448 printf("b = %d\n", b);
1449 b++;
1450 printf("b = %d\n", b);
1451 #endif
1454 void bitfield_test(void)
1456 int a;
1457 struct sbf1 {
1458 int f1 : 3;
1459 int : 2;
1460 int f2 : 1;
1461 int : 0;
1462 int f3 : 5;
1463 int f4 : 7;
1464 unsigned int f5 : 7;
1465 } st1;
1466 printf("bitfield_test:");
1467 printf("sizeof(st1) = %d\n", sizeof(st1));
1469 st1.f1 = 3;
1470 st1.f2 = 1;
1471 st1.f3 = 15;
1472 a = 120;
1473 st1.f4 = a;
1474 st1.f5 = a;
1475 st1.f5++;
1476 printf("%d %d %d %d %d\n",
1477 st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);
1479 st1.f1 = 7;
1480 if (st1.f1 == -1)
1481 printf("st1.f1 == -1\n");
1482 else
1483 printf("st1.f1 != -1\n");
1484 if (st1.f2 == -1)
1485 printf("st1.f2 == -1\n");
1486 else
1487 printf("st1.f2 != -1\n");
1489 /* bit sizes below must be bigger than 32 since GCC doesn't allow
1490 long-long bitfields whose size is not bigger than int */
1491 struct sbf2 {
1492 long long f1 : 45;
1493 long long : 2;
1494 long long f2 : 35;
1495 unsigned long long f3 : 38;
1496 } st2;
1497 st2.f1 = 0x123456789ULL;
1498 a = 120;
1499 st2.f2 = (long long)a << 25;
1500 st2.f3 = a;
1501 st2.f2++;
1502 printf("%lld %lld %lld\n", st2.f1, st2.f2, st2.f3);
1505 #ifdef __x86_64__
1506 #define FLOAT_FMT "%f\n"
1507 #else
1508 /* x86's float isn't compatible with GCC */
1509 #define FLOAT_FMT "%.5f\n"
1510 #endif
1512 /* declare strto* functions as they are C99 */
1513 double strtod(const char *nptr, char **endptr);
1514 float strtof(const char *nptr, char **endptr);
1515 long double strtold(const char *nptr, char **endptr);
1517 #define FTEST(prefix, type, fmt)\
1518 void prefix ## cmp(type a, type b)\
1520 printf("%d %d %d %d %d %d\n",\
1521 a == b,\
1522 a != b,\
1523 a < b,\
1524 a > b,\
1525 a >= b,\
1526 a <= b);\
1527 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1530 a + b,\
1531 a - b,\
1532 a * b,\
1533 a / b,\
1534 -a);\
1535 printf(fmt "\n", ++a);\
1536 printf(fmt "\n", a++);\
1537 printf(fmt "\n", a);\
1538 b = 0;\
1539 printf("%d %d\n", !a, !b);\
1541 void prefix ## fcast(type a)\
1543 float fa;\
1544 double da;\
1545 long double la;\
1546 int ia;\
1547 unsigned int ua;\
1548 type b;\
1549 fa = a;\
1550 da = a;\
1551 la = a;\
1552 printf("ftof: %f %f %Lf\n", fa, da, la);\
1553 ia = (int)a;\
1554 ua = (unsigned int)a;\
1555 printf("ftoi: %d %u\n", ia, ua);\
1556 ia = -1234;\
1557 ua = 0x81234500;\
1558 b = ia;\
1559 printf("itof: " fmt "\n", b);\
1560 b = ua;\
1561 printf("utof: " fmt "\n", b);\
1564 float prefix ## retf(type a) { return a; }\
1565 double prefix ## retd(type a) { return a; }\
1566 long double prefix ## retld(type a) { return a; }\
1568 void prefix ## call(void)\
1570 printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
1571 printf("double: %f\n", prefix ## retd(42.123456789));\
1572 printf("long double: %Lf\n", prefix ## retld(42.123456789));\
1573 printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\
1576 void prefix ## test(void)\
1578 printf("testing '%s'\n", #type);\
1579 prefix ## cmp(1, 2.5);\
1580 prefix ## cmp(2, 1.5);\
1581 prefix ## cmp(1, 1);\
1582 prefix ## fcast(234.6);\
1583 prefix ## fcast(-2334.6);\
1584 prefix ## call();\
1587 FTEST(f, float, "%f")
1588 FTEST(d, double, "%f")
1589 FTEST(ld, long double, "%Lf")
1591 double ftab1[3] = { 1.2, 3.4, -5.6 };
1594 void float_test(void)
1596 float fa, fb;
1597 double da, db;
1598 int a;
1599 unsigned int b;
1601 printf("float_test:\n");
1602 printf("sizeof(float) = %d\n", sizeof(float));
1603 printf("sizeof(double) = %d\n", sizeof(double));
1604 printf("sizeof(long double) = %d\n", sizeof(long double));
1605 ftest();
1606 dtest();
1607 ldtest();
1608 printf("%f %f %f\n", ftab1[0], ftab1[1], ftab1[2]);
1609 printf("%f %f %f\n", 2.12, .5, 2.3e10);
1610 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1611 da = 123;
1612 printf("da=%f\n", da);
1613 fa = 123;
1614 printf("fa=%f\n", fa);
1615 a = 4000000000;
1616 da = a;
1617 printf("da = %f\n", da);
1618 b = 4000000000;
1619 db = b;
1620 printf("db = %f\n", db);
1623 int fib(int n)
1625 if (n <= 2)
1626 return 1;
1627 else
1628 return fib(n-1) + fib(n-2);
1631 void funcptr_test()
1633 void (*func)(int);
1634 int a;
1635 struct {
1636 int dummy;
1637 void (*func)(int);
1638 } st1;
1640 printf("funcptr:\n");
1641 func = &num;
1642 (*func)(12345);
1643 func = num;
1644 a = 1;
1645 a = 1;
1646 func(12345);
1647 /* more complicated pointer computation */
1648 st1.func = num;
1649 st1.func(12346);
1650 printf("sizeof1 = %d\n", sizeof(funcptr_test));
1651 printf("sizeof2 = %d\n", sizeof funcptr_test);
1652 printf("sizeof3 = %d\n", sizeof(&funcptr_test));
1653 printf("sizeof4 = %d\n", sizeof &funcptr_test);
1656 void lloptest(long long a, long long b)
1658 unsigned long long ua, ub;
1660 ua = a;
1661 ub = b;
1662 /* arith */
1663 printf("arith: %Ld %Ld %Ld\n",
1664 a + b,
1665 a - b,
1666 a * b);
1668 if (b != 0) {
1669 printf("arith1: %Ld %Ld\n",
1670 a / b,
1671 a % b);
1674 /* binary */
1675 printf("bin: %Ld %Ld %Ld\n",
1676 a & b,
1677 a | b,
1678 a ^ b);
1680 /* tests */
1681 printf("test: %d %d %d %d %d %d\n",
1682 a == b,
1683 a != b,
1684 a < b,
1685 a > b,
1686 a >= b,
1687 a <= b);
1689 printf("utest: %d %d %d %d %d %d\n",
1690 ua == ub,
1691 ua != ub,
1692 ua < ub,
1693 ua > ub,
1694 ua >= ub,
1695 ua <= ub);
1697 /* arith2 */
1698 a++;
1699 b++;
1700 printf("arith2: %Ld %Ld\n", a, b);
1701 printf("arith2: %Ld %Ld\n", a++, b++);
1702 printf("arith2: %Ld %Ld\n", --a, --b);
1703 printf("arith2: %Ld %Ld\n", a, b);
1704 b = ub = 0;
1705 printf("not: %d %d %d %d\n", !a, !ua, !b, !ub);
1708 void llshift(long long a, int b)
1710 printf("shift: %Ld %Ld %Ld\n",
1711 (unsigned long long)a >> b,
1712 a >> b,
1713 a << b);
1714 printf("shiftc: %Ld %Ld %Ld\n",
1715 (unsigned long long)a >> 3,
1716 a >> 3,
1717 a << 3);
1718 printf("shiftc: %Ld %Ld %Ld\n",
1719 (unsigned long long)a >> 35,
1720 a >> 35,
1721 a << 35);
1724 void llfloat(void)
1726 float fa;
1727 double da;
1728 long double lda;
1729 long long la, lb, lc;
1730 unsigned long long ula, ulb, ulc;
1731 la = 0x12345678;
1732 ula = 0x72345678;
1733 la = (la << 20) | 0x12345;
1734 ula = ula << 33;
1735 printf("la=%Ld ula=%Lu\n", la, ula);
1737 fa = la;
1738 da = la;
1739 lda = la;
1740 printf("lltof: %f %f %Lf\n", fa, da, lda);
1742 la = fa;
1743 lb = da;
1744 lc = lda;
1745 printf("ftoll: %Ld %Ld %Ld\n", la, lb, lc);
1747 fa = ula;
1748 da = ula;
1749 lda = ula;
1750 printf("ulltof: %f %f %Lf\n", fa, da, lda);
1752 ula = fa;
1753 ulb = da;
1754 ulc = lda;
1755 printf("ftoull: %Lu %Lu %Lu\n", ula, ulb, ulc);
1758 long long llfunc1(int a)
1760 return a * 2;
1763 struct S {
1764 int id;
1765 char item;
1768 long long int value(struct S *v)
1770 return ((long long int)v->item);
1773 void longlong_test(void)
1775 long long a, b, c;
1776 int ia;
1777 unsigned int ua;
1778 printf("longlong_test:\n");
1779 printf("sizeof(long long) = %d\n", sizeof(long long));
1780 ia = -1;
1781 ua = -2;
1782 a = ia;
1783 b = ua;
1784 printf("%Ld %Ld\n", a, b);
1785 printf("%Ld %Ld %Ld %Lx\n",
1786 (long long)1,
1787 (long long)-2,
1788 1LL,
1789 0x1234567812345679);
1790 a = llfunc1(-3);
1791 printf("%Ld\n", a);
1793 lloptest(1000, 23);
1794 lloptest(0xff, 0x1234);
1795 b = 0x72345678 << 10;
1796 lloptest(-3, b);
1797 llshift(0x123, 5);
1798 llshift(-23, 5);
1799 b = 0x72345678LL << 10;
1800 llshift(b, 47);
1802 llfloat();
1803 #if 1
1804 b = 0x12345678;
1805 a = -1;
1806 c = a + b;
1807 printf("%Lx\n", c);
1808 #endif
1810 /* long long reg spill test */
1812 struct S a;
1814 a.item = 3;
1815 printf("%lld\n", value(&a));
1817 lloptest(0x80000000, 0);
1819 /* another long long spill test */
1821 long long *p, v;
1822 v = 1;
1823 p = &v;
1824 p[0]++;
1825 printf("%lld\n", *p);
1828 a = 68719476720LL;
1829 b = 4294967295LL;
1830 printf("%d %d %d %d\n", a > b, a < b, a >= b, a <= b);
1832 printf("%Ld\n", 0x123456789LLU);
1835 void manyarg_test(void)
1837 long double ld = 1234567891234LL;
1838 printf("manyarg_test:\n");
1839 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1840 1, 2, 3, 4, 5, 6, 7, 8,
1841 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1842 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1843 "%Ld %Ld %f %f\n",
1844 1, 2, 3, 4, 5, 6, 7, 8,
1845 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1846 1234567891234LL, 987654321986LL,
1847 42.0, 43.0);
1848 printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1849 "%Ld %Ld %f %f\n",
1850 ld, 1, 2, 3, 4, 5, 6, 7, 8,
1851 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1852 1234567891234LL, 987654321986LL,
1853 42.0, 43.0);
1854 /* XXX: known bug of x86-64 */
1855 #ifndef __x86_64__
1856 printf("%d %d %d %d %d %d %d %d %Lf\n",
1857 1, 2, 3, 4, 5, 6, 7, 8, ld);
1858 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1859 "%Ld %Ld %f %f %Lf\n",
1860 1, 2, 3, 4, 5, 6, 7, 8,
1861 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1862 1234567891234LL, 987654321986LL,
1863 42.0, 43.0, ld);
1864 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1865 "%Lf %Ld %Ld %f %f %Lf\n",
1866 1, 2, 3, 4, 5, 6, 7, 8,
1867 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1868 ld, 1234567891234LL, 987654321986LL,
1869 42.0, 43.0, ld);
1870 #endif
1873 void vprintf1(const char *fmt, ...)
1875 va_list ap, aq;
1876 const char *p;
1877 int c, i;
1878 double d;
1879 long long ll;
1880 long double ld;
1882 va_start(aq, fmt);
1883 va_copy(ap, aq);
1885 p = fmt;
1886 for(;;) {
1887 c = *p;
1888 if (c == '\0')
1889 break;
1890 p++;
1891 if (c == '%') {
1892 c = *p;
1893 switch(c) {
1894 case '\0':
1895 goto the_end;
1896 case 'd':
1897 i = va_arg(ap, int);
1898 printf("%d", i);
1899 break;
1900 case 'f':
1901 d = va_arg(ap, double);
1902 printf("%f", d);
1903 break;
1904 case 'l':
1905 ll = va_arg(ap, long long);
1906 printf("%Ld", ll);
1907 break;
1908 case 'F':
1909 ld = va_arg(ap, long double);
1910 printf("%Lf", ld);
1911 break;
1913 p++;
1914 } else {
1915 putchar(c);
1918 the_end:
1919 va_end(aq);
1920 va_end(ap);
1923 struct myspace {
1924 short int profile;
1927 void stdarg_for_struct(struct myspace bob, ...)
1929 struct myspace george, bill;
1930 va_list ap;
1931 short int validate;
1933 va_start(ap, bob);
1934 bill = va_arg(ap, struct myspace);
1935 george = va_arg(ap, struct myspace);
1936 validate = va_arg(ap, int);
1937 printf("stdarg_for_struct: %d %d %d %d\n",
1938 bob.profile, bill.profile, george.profile, validate);
1939 va_end(ap);
1942 void stdarg_test(void)
1944 long double ld = 1234567891234LL;
1945 struct myspace bob;
1947 vprintf1("%d %d %d\n", 1, 2, 3);
1948 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1949 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1950 vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
1951 #ifdef __x86_64__
1952 /* a bug of x86's TCC */
1953 vprintf1("%d %f %l %F %d %f %l %F\n",
1954 1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
1955 #endif
1956 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1957 1, 2, 3, 4, 5, 6, 7, 8,
1958 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
1959 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1960 1, 2, 3, 4, 5, 6, 7, 8,
1961 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1962 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1963 "%l %l %f %f\n",
1964 1, 2, 3, 4, 5, 6, 7, 8,
1965 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1966 1234567891234LL, 987654321986LL,
1967 42.0, 43.0);
1968 vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1969 "%l %l %f %f\n",
1970 ld, 1, 2, 3, 4, 5, 6, 7, 8,
1971 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1972 1234567891234LL, 987654321986LL,
1973 42.0, 43.0);
1974 vprintf1("%d %d %d %d %d %d %d %d %F\n",
1975 1, 2, 3, 4, 5, 6, 7, 8, ld);
1976 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1977 "%l %l %f %f %F\n",
1978 1, 2, 3, 4, 5, 6, 7, 8,
1979 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1980 1234567891234LL, 987654321986LL,
1981 42.0, 43.0, ld);
1982 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1983 "%F %l %l %f %f %F\n",
1984 1, 2, 3, 4, 5, 6, 7, 8,
1985 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1986 ld, 1234567891234LL, 987654321986LL,
1987 42.0, 43.0, ld);
1989 bob.profile = 42;
1990 stdarg_for_struct(bob, bob, bob, bob.profile);
1993 void whitespace_test(void)
1995 char *str;
1997 \f\v #if 1
1998 pri\
1999 ntf("whitspace:\n");\f\v
2000 #endif
2001 pf("N=%d\n", 2);
2003 #ifdef CORRECT_CR_HANDLING
2004 pri\
2005 ntf("aaa=%d\n", 3);
2006 #endif
2008 pri\
2010 ntf("min=%d\n", 4);
2012 #ifdef ACCEPT_CR_IN_STRINGS
2013 printf("len1=%d\n", strlen("
2014 "));
2015 #ifdef CORRECT_CR_HANDLING
2016 str = "
2018 printf("len1=%d str[0]=%d\n", strlen(str), str[0]);
2019 #endif
2020 printf("len1=%d\n", strlen(" a
2021 "));
2022 #endif /* ACCEPT_CR_IN_STRINGS */
2025 int reltab[3] = { 1, 2, 3 };
2027 int *rel1 = &reltab[1];
2028 int *rel2 = &reltab[2];
2030 void relocation_test(void)
2032 printf("*rel1=%d\n", *rel1);
2033 printf("*rel2=%d\n", *rel2);
2036 void old_style_f(a,b,c)
2037 int a, b;
2038 double c;
2040 printf("a=%d b=%d b=%f\n", a, b, c);
2043 void decl_func1(int cmpfn())
2045 printf("cmpfn=%lx\n", (long)cmpfn);
2048 void decl_func2(cmpfn)
2049 int cmpfn();
2051 printf("cmpfn=%lx\n", (long)cmpfn);
2054 void old_style_function(void)
2056 old_style_f((void *)1, 2, 3.0);
2057 decl_func1(NULL);
2058 decl_func2(NULL);
2061 void alloca_test()
2063 #if defined __i386__ || defined __x86_64__
2064 char *p = alloca(16);
2065 strcpy(p,"123456789012345");
2066 printf("alloca: p is %s\n", p);
2067 char *demo = "This is only a test.\n";
2068 /* Test alloca embedded in a larger expression */
2069 printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) );
2070 #endif
2073 void c99_vla_test(int size1, int size2)
2075 #if defined __i386__ || defined __x86_64__
2076 int tab1[size1 * size2][2], tab2[10][2];
2077 void *tab1_ptr, *tab2_ptr;
2079 printf("Test C99 VLA 1 (sizeof): ");
2080 printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED");
2081 tab1_ptr = tab1;
2082 tab2_ptr = tab2;
2083 printf("Test C99 VLA 2 (ptrs substract): ");
2084 printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED");
2085 printf("Test C99 VLA 3 (ptr add): ");
2086 printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED");
2087 printf("Test C99 VLA 4 (ptr access): ");
2088 tab1[size1][1] = 42;
2089 printf("%s\n", (*((int *) (tab1_ptr + (size1 * 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED");
2090 #endif
2093 void sizeof_test(void)
2095 int a;
2096 int **ptr;
2098 printf("sizeof(int) = %d\n", sizeof(int));
2099 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
2100 printf("sizeof(long) = %d\n", sizeof(long));
2101 printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
2102 printf("sizeof(short) = %d\n", sizeof(short));
2103 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
2104 printf("sizeof(char) = %d\n", sizeof(char));
2105 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
2106 printf("sizeof(func) = %d\n", sizeof sizeof_test());
2107 a = 1;
2108 printf("sizeof(a++) = %d\n", sizeof a++);
2109 printf("a=%d\n", a);
2110 ptr = NULL;
2111 printf("sizeof(**ptr) = %d\n", sizeof (**ptr));
2113 /* some alignof tests */
2114 printf("__alignof__(int) = %d\n", __alignof__(int));
2115 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
2116 printf("__alignof__(short) = %d\n", __alignof__(short));
2117 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
2118 printf("__alignof__(char) = %d\n", __alignof__(char));
2119 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
2120 printf("__alignof__(func) = %d\n", __alignof__ sizeof_test());
2123 void typeof_test(void)
2125 double a;
2126 typeof(a) b;
2127 typeof(float) c;
2129 a = 1.5;
2130 b = 2.5;
2131 c = 3.5;
2132 printf("a=%f b=%f c=%f\n", a, b, c);
2135 void statement_expr_test(void)
2137 int a, i;
2139 a = 0;
2140 for(i=0;i<10;i++) {
2141 a += 1 +
2142 ( { int b, j;
2143 b = 0;
2144 for(j=0;j<5;j++)
2145 b += j; b;
2146 } );
2148 printf("a=%d\n", a);
2152 void local_label_test(void)
2154 int a;
2155 goto l1;
2157 a = 1 + ({
2158 __label__ l1, l2, l3, l4;
2159 goto l1;
2161 printf("aa1\n");
2162 goto l3;
2164 printf("aa3\n");
2165 goto l4;
2167 printf("aa2\n");
2168 goto l2;
2169 l3:;
2172 printf("a=%d\n", a);
2173 return;
2175 printf("bb1\n");
2176 goto l2;
2178 printf("bb2\n");
2179 goto l4;
2182 /* inline assembler test */
2183 #ifdef __i386__
2185 /* from linux kernel */
2186 static char * strncat1(char * dest,const char * src,size_t count)
2188 int d0, d1, d2, d3;
2189 __asm__ __volatile__(
2190 "repne\n\t"
2191 "scasb\n\t"
2192 "decl %1\n\t"
2193 "movl %8,%3\n"
2194 "1:\tdecl %3\n\t"
2195 "js 2f\n\t"
2196 "lodsb\n\t"
2197 "stosb\n\t"
2198 "testb %%al,%%al\n\t"
2199 "jne 1b\n"
2200 "2:\txorl %2,%2\n\t"
2201 "stosb"
2202 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
2203 : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
2204 : "memory");
2205 return dest;
2208 static char * strncat2(char * dest,const char * src,size_t count)
2210 int d0, d1, d2, d3;
2211 __asm__ __volatile__(
2212 "repne scasb\n\t" /* one-line repne prefix + string op */
2213 "decl %1\n\t"
2214 "movl %8,%3\n"
2215 "1:\tdecl %3\n\t"
2216 "js 2f\n\t"
2217 "lodsb\n\t"
2218 "stosb\n\t"
2219 "testb %%al,%%al\n\t"
2220 "jne 1b\n"
2221 "2:\txorl %2,%2\n\t"
2222 "stosb"
2223 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
2224 : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
2225 : "memory");
2226 return dest;
2229 static inline void * memcpy1(void * to, const void * from, size_t n)
2231 int d0, d1, d2;
2232 __asm__ __volatile__(
2233 "rep ; movsl\n\t"
2234 "testb $2,%b4\n\t"
2235 "je 1f\n\t"
2236 "movsw\n"
2237 "1:\ttestb $1,%b4\n\t"
2238 "je 2f\n\t"
2239 "movsb\n"
2240 "2:"
2241 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
2242 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
2243 : "memory");
2244 return (to);
2247 static inline void * memcpy2(void * to, const void * from, size_t n)
2249 int d0, d1, d2;
2250 __asm__ __volatile__(
2251 "rep movsl\n\t" /* one-line rep prefix + string op */
2252 "testb $2,%b4\n\t"
2253 "je 1f\n\t"
2254 "movsw\n"
2255 "1:\ttestb $1,%b4\n\t"
2256 "je 2f\n\t"
2257 "movsb\n"
2258 "2:"
2259 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
2260 :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
2261 : "memory");
2262 return (to);
2265 static __inline__ void sigaddset1(unsigned int *set, int _sig)
2267 __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
2270 static __inline__ void sigdelset1(unsigned int *set, int _sig)
2272 asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
2275 static __inline__ __const__ unsigned int swab32(unsigned int x)
2277 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
2278 "rorl $16,%0\n\t" /* swap words */
2279 "xchgb %b0,%h0" /* swap higher bytes */
2280 :"=q" (x)
2281 : "0" (x));
2282 return x;
2285 static __inline__ unsigned long long mul64(unsigned int a, unsigned int b)
2287 unsigned long long res;
2288 __asm__("mull %2" : "=A" (res) : "a" (a), "r" (b));
2289 return res;
2292 static __inline__ unsigned long long inc64(unsigned long long a)
2294 unsigned long long res;
2295 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res) : "A" (a));
2296 return res;
2299 unsigned int set;
2301 void asm_test(void)
2303 char buf[128];
2304 unsigned int val;
2306 printf("inline asm:\n");
2307 /* test the no operand case */
2308 asm volatile ("xorl %eax, %eax");
2310 memcpy1(buf, "hello", 6);
2311 strncat1(buf, " worldXXXXX", 3);
2312 printf("%s\n", buf);
2314 memcpy2(buf, "hello", 6);
2315 strncat2(buf, " worldXXXXX", 3);
2316 printf("%s\n", buf);
2318 /* 'A' constraint test */
2319 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
2320 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
2322 set = 0xff;
2323 sigdelset1(&set, 2);
2324 sigaddset1(&set, 16);
2325 /* NOTE: we test here if C labels are correctly restored after the
2326 asm statement */
2327 goto label1;
2328 label2:
2329 __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc");
2330 #ifdef __GNUC__ // works strange with GCC 4.3
2331 set=0x1080fd;
2332 #endif
2333 printf("set=0x%x\n", set);
2334 val = 0x01020304;
2335 printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val));
2336 return;
2337 label1:
2338 goto label2;
2341 #else
2343 void asm_test(void)
2347 #endif
2349 #define COMPAT_TYPE(type1, type2) \
2351 printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
2352 __builtin_types_compatible_p (type1, type2));\
2355 int constant_p_var;
2357 void builtin_test(void)
2359 #if GCC_MAJOR >= 3
2360 COMPAT_TYPE(int, int);
2361 COMPAT_TYPE(int, unsigned int);
2362 COMPAT_TYPE(int, char);
2363 COMPAT_TYPE(int, const int);
2364 COMPAT_TYPE(int, volatile int);
2365 COMPAT_TYPE(int *, int *);
2366 COMPAT_TYPE(int *, void *);
2367 COMPAT_TYPE(int *, const int *);
2368 COMPAT_TYPE(char *, unsigned char *);
2369 /* space is needed because tcc preprocessor introduces a space between each token */
2370 COMPAT_TYPE(char * *, void *);
2371 #endif
2372 printf("res = %d\n", __builtin_constant_p(1));
2373 printf("res = %d\n", __builtin_constant_p(1 + 2));
2374 printf("res = %d\n", __builtin_constant_p(&constant_p_var));
2375 printf("res = %d\n", __builtin_constant_p(constant_p_var));
2379 extern int __attribute__((weak)) weak_f1(void);
2380 extern int __attribute__((weak)) weak_f2(void);
2381 extern int weak_f3(void);
2382 extern int __attribute__((weak)) weak_v1;
2383 extern int __attribute__((weak)) weak_v2;
2384 extern int weak_v3;
2386 extern int (*weak_fpa)() __attribute__((weak));
2387 extern int __attribute__((weak)) (*weak_fpb)();
2388 extern __attribute__((weak)) int (*weak_fpc)();
2390 extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak));
2391 extern int __attribute((weak)) weak_asm_f2(void) asm("weak_asm_f2x") ;
2392 extern int __attribute((weak)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak));
2393 extern int weak_asm_v1 asm("weak_asm_v1x") __attribute((weak));
2394 extern int __attribute((weak)) weak_asm_v2 asm("weak_asm_v2x") ;
2395 extern int __attribute((weak)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak));
2397 static const size_t dummy = 0;
2398 extern __typeof(dummy) weak_dummy1 __attribute__((weak, alias("dummy")));
2399 extern __typeof(dummy) __attribute__((weak, alias("dummy"))) weak_dummy2;
2400 extern __attribute__((weak, alias("dummy"))) __typeof(dummy) weak_dummy3;
2402 int some_lib_func(void);
2403 int dummy_impl_of_slf(void) { return 444; }
2404 int some_lib_func(void) __attribute__((weak, alias("dummy_impl_of_slf")));
2406 int weak_toolate() { return 0; }
2407 int weak_toolate() __attribute__((weak));
2409 void __attribute__((weak)) weak_test(void)
2411 printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123);
2412 printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123);
2413 printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123);
2414 printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123);
2415 printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123);
2416 printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123);
2418 printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123);
2419 printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123);
2420 printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123);
2422 printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL);
2423 printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL);
2424 printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL);
2425 printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL);
2426 printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL);
2427 printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL);
2430 int __attribute__((weak)) weak_f2() { return 222; }
2431 int __attribute__((weak)) weak_f3() { return 333; }
2432 int __attribute__((weak)) weak_v2 = 222;
2433 int __attribute__((weak)) weak_v3 = 333;
2435 void const_func(const int a)
2439 void const_warn_test(void)
2441 const_func(1);