2 * TCC auto test program
8 /* Unfortunately, gcc version < 3 does not handle that! */
11 /* only gcc 3 handles _Bool correctly */
14 /* gcc 2.95.3 does not handle correctly CR in strings or after strays */
15 #define CORRECT_CR_HANDLING
19 /* deprecated and no longer supported in gcc 3.3 */
20 //#define ACCEPT_CR_IN_STRINGS
22 /* __VA_ARGS__ and __func__ support */
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"
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"
48 void recursive_macro_test();
62 void constant_expr_test();
64 void char_short_test();
66 void compound_literal_test(void);
68 void struct_assign_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);
86 void builtin_test(void);
91 void forward_ref(void);
97 #define M1(a, b) (a) + (b)
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))
109 #define dprintf(level,...) printf(__VA_ARGS__)
112 /* gcc vararg macros */
113 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
115 #define MACRO_NOARGS()
131 #define __INT64_C(c) c ## LL
132 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
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
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
);
159 printf("A defined\n");
162 printf("B defined\n");
165 printf("A defined\n");
167 printf("A not defined\n");
170 printf("B defined\n");
172 printf("B not defined\n");
176 printf("A defined\n");
178 printf("B1 defined\n");
180 printf("B1 not defined\n");
183 printf("A not defined\n");
185 printf("B2 defined\n");
187 printf("B2 not defined\n");
192 printf("test true1\n");
195 printf("test true2\n");
198 printf("test true3\n");
201 printf("test trueA\n");
204 printf("test trueB\n");
220 printf("__LINE__ defined\n");
223 printf("__LINE__=%d __FILE__=%s\n",
226 printf("__LINE__=%d __FILE__=%s\n",
229 printf("__LINE__=%d __FILE__=%s\n",
231 #line 227 "tcctest.c"
233 /* not strictly preprocessor, but we test it there */
235 printf("__func__ = %s\n", __func__
);
236 dprintf(1, "vaarg=%d\n", 1);
238 dprintf1(1, "vaarg1\n");
239 dprintf1(1, "vaarg1=%d\n", 2);
240 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
243 printf("func='%s'\n", __FUNCTION__
);
245 /* complicated macros in glibc */
246 printf("INT64_MIN=%Ld\n", INT64_MIN
);
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
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. */
272 printf("qq1=%d\n", qq1( ));
274 /* comment with stray handling *\
276 /* this is a valid *\/ comment */
277 /* this is a valid comment *\*/
281 /* test function macro substitution when the function name is
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)
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)));
302 #define print_num(x) print_num(__FILE__,__LINE__,x)
304 WRAP(print_num(123));
305 WRAP(WRAP(print_num(123)));
307 static struct recursive_macro
{ int rm_field
; } G
;
308 #define rm_field (G.rm_field)
309 printf("rm_field = %d\n", rm_field
);
310 printf("rm_field = %d\n", WRAP(rm_field
));
311 WRAP((printf("rm_field = %d %d\n", rm_field
, WRAP(rm_field
))));
328 void ps(const char *s
)
340 const char foo1_string
[] = "\
349 printf("\141\1423\143\n");/* dezdez test */
350 printf("\x41\x42\x43\x3a\n");
351 printf("c=%c\n", 'r');
352 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
353 printf("foo1_string='%s'\n", foo1_string
);
355 printf("wstring=%S\n", L
"abc");
356 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
357 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
358 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
362 while ((b
= b
+ 1) < 96) {
366 printf("fib=%d\n", fib(33));
368 while (b
!= 0x80000000) {
381 for(i
= 0; i
< 10;i
++)
391 /* c99 for loop init test */
392 for (size_t count
= 1; count
< 3; count
++)
393 printf("count=%d\n", count
);
394 printf("count = %d\n", count
);
396 /* break/continue tests */
408 /* break/continue tests */
420 for(i
= 0;i
< 10;i
++) {
432 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
445 /* we also test computed gotos (GCC extension) */
447 goto *label_table
[i
];
475 printf("enum:\n%d %d %d %d %d %d\n",
476 E0
, E1
, E2
, E3
, E4
, E5
);
478 printf("b1=%d\n", b1
);
494 printf("typedef:\n");
495 printf("a=%d\n", *a
);
497 printf("mytype2=%d\n", mytype2
);
502 printf("forward:\n");
508 void forward_ref(void)
510 printf("forward ok\n");
513 typedef struct struct1
{
533 struct struct1 st1
, st2
;
535 int main(int argc
, char **argv
)
540 recursive_macro_test();
554 constant_expr_test();
558 compound_literal_test();
560 struct_assign_test();
570 old_style_function();
575 statement_expr_test();
590 printf("g1=%d\n", g
);
598 printf("g2=%d\n", g
);
602 printf("g3=%d\n", g
);
606 printf("g4=%d\n", g
);
609 printf("g5=%d\n", g
);
612 void array_test(int a
[4])
617 printf("sizeof(a) = %d\n", sizeof(a
));
618 printf("sizeof(\"a\") = %d\n", sizeof("a"));
620 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
622 printf("sizeof tab %d\n", sizeof(tab
));
623 printf("sizeof tab2 %d\n", sizeof tab2
);
627 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
630 tab2
[i
][j
] = 10 * i
+ j
;
632 printf(" %3d", ((int *)tab2
)[i
]);
635 printf("sizeof(size_t)=%d\n", sizeof(size_t));
636 printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
643 printf("%d\n", a
+= 1);
644 printf("%d\n", a
-= 2);
645 printf("%d\n", a
*= 31232132);
646 printf("%d\n", a
/= 4);
647 printf("%d\n", a
%= 20);
648 printf("%d\n", a
&= 6);
649 printf("%d\n", a
^= 7);
650 printf("%d\n", a
|= 8);
651 printf("%d\n", a
>>= 3);
652 printf("%d\n", a
<<= 4);
656 printf("%d\n", a
+ 1);
657 printf("%d\n", a
- 2);
658 printf("%d\n", a
* 312);
659 printf("%d\n", a
/ 4);
660 printf("%d\n", b
/ 4);
661 printf("%d\n", (unsigned)b
/ 4);
662 printf("%d\n", a
% 20);
663 printf("%d\n", b
% 20);
664 printf("%d\n", (unsigned)b
% 20);
665 printf("%d\n", a
& 6);
666 printf("%d\n", a
^ 7);
667 printf("%d\n", a
| 8);
668 printf("%d\n", a
>> 3);
669 printf("%d\n", b
>> 3);
670 printf("%d\n", (unsigned)b
>> 3);
671 printf("%d\n", a
<< 4);
676 printf("%d\n", 12 + 1);
677 printf("%d\n", 12 - 2);
678 printf("%d\n", 12 * 312);
679 printf("%d\n", 12 / 4);
680 printf("%d\n", 12 % 20);
681 printf("%d\n", 12 & 6);
682 printf("%d\n", 12 ^ 7);
683 printf("%d\n", 12 | 8);
684 printf("%d\n", 12 >> 2);
685 printf("%d\n", 12 << 4);
689 printf("%d %d %d %d\n",
698 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
701 /**********************/
703 int vstack
[10], *vstack_ptr
;
705 void vpush(int vt
, int vc
)
711 void vpop(int *ft
, int *fc
)
724 vstack_ptr
[-2] &= ~0xffffff80;
726 printf("res= %d %d\n", a
, b
);
729 void constant_expr_test()
732 printf("constant_expr:\n");
734 printf("%d\n", a
* 16);
735 printf("%d\n", a
* 1);
736 printf("%d\n", a
+ 0);
746 printf("expr_ptr:\n");
749 printf("diff=%d\n", q
- p
);
751 printf("inc=%d\n", p
- tab4
);
753 printf("dec=%d\n", p
- tab4
);
755 printf("inc=%d\n", p
- tab4
);
757 printf("dec=%d\n", p
- tab4
);
758 printf("add=%d\n", p
+ 3 - tab4
);
759 printf("add=%d\n", 3 + p
- tab4
);
761 /* check if 64bit support is ok */
764 printf("%p %p %ld\n", q
, p
, p
-q
);
765 printf("%d %d %d %d %d %d\n",
766 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
769 printf("%p %p %ld\n", q
, p
, p
-q
);
770 printf("%d %d %d %d %d %d\n",
771 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
772 p
= (int *)((char *)p
+ 0xf0000000);
773 printf("%p %p %ld\n", q
, p
, p
-q
);
774 printf("%d %d %d %d %d %d\n",
775 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
777 printf("%p %p %ld\n", q
, p
, p
-q
);
778 printf("%d %d %d %d %d %d\n",
779 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
784 struct size12 s
[2], *sp
= s
;
789 printf("%d\n", sp
[j
].i
);
796 printf("constant_expr:\n");
799 printf("%d\n", a
== a
);
800 printf("%d\n", a
!= a
);
802 printf("%d\n", a
< b
);
803 printf("%d\n", a
<= b
);
804 printf("%d\n", a
<= a
);
805 printf("%d\n", b
>= a
);
806 printf("%d\n", a
>= a
);
807 printf("%d\n", b
> a
);
809 printf("%d\n", (unsigned)a
< b
);
810 printf("%d\n", (unsigned)a
<= b
);
811 printf("%d\n", (unsigned)a
<= a
);
812 printf("%d\n", (unsigned)b
>= a
);
813 printf("%d\n", (unsigned)a
>= a
);
814 printf("%d\n", (unsigned)b
> a
);
843 printf("sizes: %d %d %d %d\n",
844 sizeof(struct struct1
),
845 sizeof(struct struct2
),
846 sizeof(union union1
),
847 sizeof(union union2
));
851 printf("st1: %d %d %d\n",
852 st1
.f1
, st1
.f2
, st1
.f3
);
855 printf("union1: %d\n", st1
.u
.v1
);
858 printf("union2: %d\n", u
.w1
);
863 printf("st2: %d %d %d\n",
864 s
->f1
, s
->f2
, s
->f3
);
865 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
867 /* align / size tests */
868 printf("aligntest1 sizeof=%d alignof=%d\n",
869 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
870 printf("aligntest2 sizeof=%d alignof=%d\n",
871 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
872 printf("aligntest3 sizeof=%d alignof=%d\n",
873 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
874 printf("aligntest4 sizeof=%d alignof=%d\n",
875 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
877 /* empty structures (GCC extension) */
878 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
879 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
882 /* XXX: depend on endianness */
883 void char_short_test()
887 printf("char_short:\n");
892 *(char *)&var1
, *(char *)&var2
);
894 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
895 printf("s16=%d %d\n",
896 *(short *)&var1
, *(short *)&var2
);
897 printf("u16=%d %d\n",
898 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
899 printf("s32=%d %d\n",
900 *(int *)&var1
, *(int *)&var2
);
901 printf("u32=%d %d\n",
902 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
903 *(char *)&var1
= 0x08;
904 printf("var1=%x\n", var1
);
905 *(short *)&var1
= 0x0809;
906 printf("var1=%x\n", var1
);
907 *(int *)&var1
= 0x08090a0b;
908 printf("var1=%x\n", var1
);
921 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
922 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
924 static int toupper1(int a
)
931 int *s
, a
, b
, t
, f
, i
;
935 printf("!s=%d\n", !s
);
941 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
942 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
943 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
958 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
960 /* test register spilling */
963 a
= (a
+ b
) * ((a
< b
) ?
964 ((b
- a
) * (a
- b
)): a
+ b
);
967 /* test complex || or && expressions */
971 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
972 printf("r=%d\n", (t
|| f
) + (t
&& f
));
977 int aspect_native
= 65536;
978 double bfu_aspect
= 1.0;
980 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
981 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
982 printf("aspect=%d\n", aspect
);
986 /* test ? : GCC extension */
988 static int v1
= 34 ? : -1; /* constant case */
989 static int v2
= 0 ? : -1; /* constant case */
992 printf("%d %d\n", v1
, v2
);
993 printf("%d %d\n", a
- 30 ? : a
* 2, a
+ 1 ? : a
* 2);
996 /* again complex expression */
998 if (toupper1 (i
) != TOUPPER (i
))
999 printf("error %d\n", i
);
1003 /* GCC accepts that */
1004 static int tab_reinit
[];
1005 static int tab_reinit
[10];
1007 //int cinit1; /* a global variable can be defined several times without error ! */
1011 int *cinit2
= (int []){3, 2, 1};
1013 void compound_literal_test(void)
1018 printf("compound_test:\n");
1020 p
= (int []){1, 2, 3};
1022 printf(" %d", p
[i
]);
1026 printf("%d", cinit2
[i
]);
1030 printf("q1=%s\n", q
);
1032 q
= (char *){ "tralala2" };
1033 printf("q2=%s\n", q
);
1036 printf("q3=%s\n", q3
);
1038 q
= (char []){ "tralala3" };
1039 printf("q4=%s\n", q
);
1042 p
= (int []){1, 2, cinit1
+ 3};
1044 printf(" %d", p
[i
]);
1048 p
= (int []){1, 2, 4 + i
};
1049 printf("%d %d %d\n",
1071 printf("kr_test:\n");
1072 printf("func1=%d\n", kr_func1(3, 4));
1073 printf("func2=%d\n", kr_func2(3, 4));
1080 tab
= (char*)malloc(20);
1097 /* structure assignment tests */
1103 struct structa1 ssta1
;
1105 void struct_assign_test1(struct structa1 s1
, int t
, float f
)
1107 printf("%d %d %d %f\n", s1
.f1
, s1
.f2
, t
, f
);
1110 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
1117 void struct_assign_test(void)
1119 struct structa1 lsta1
, lsta2
;
1122 printf("struct_assign_test:\n");
1126 printf("%d %d\n", lsta1
.f1
, lsta1
.f2
);
1128 printf("%d %d\n", lsta2
.f1
, lsta2
.f2
);
1133 struct_assign_test1(lsta2
, 3, 4.5);
1135 printf("before call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1136 lsta2
= struct_assign_test2(lsta2
, 4);
1137 printf("after call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1142 /* XXX: we should allow this even without braces */
1143 { struct_assign_test
}
1145 printf("%d\n", struct_assign_test
== t
[0].elem
);
1148 /* casts to short/char */
1150 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
1152 printf("%d %d %d %d\n", a
, b
, c
, d
);
1166 p
-= 0x700000000042;
1168 printf("cast_test:\n");
1172 printf("%d %d %d %d\n",
1175 (unsigned char)(a
+ 1),
1176 (unsigned short)(a
+ 1));
1177 printf("%d %d %d %d\n",
1180 (unsigned char)0xfffff,
1181 (unsigned short)0xfffff);
1183 a
= (bcast
= 128) + 1;
1185 a
= (scast
= 65536) + 1;
1188 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1190 /* test cast from unsigned to signed short to int */
1193 printf("((unsigned)(short)0x%08x) = 0x%08x\n", b
, d
);
1196 printf("((unsigned)(char)0x%08x) = 0x%08x\n", b
, d
);
1198 /* test implicit int casting for array accesses */
1202 printf("%d %d\n", tab
[0], tab
[1]);
1204 /* test implicit casting on some operators */
1205 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1206 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1207 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1209 /* from pointer to integer types */
1210 printf("%d %d %ld %ld %lld %lld\n",
1211 (int)p
, (unsigned int)p
,
1212 (long)p
, (unsigned long)p
,
1213 (long long)p
, (unsigned long long)p
);
1215 /* from integers to pointers */
1216 printf("%p %p %p %p\n",
1217 (void *)a
, (void *)b
, (void *)c
, (void *)d
);
1220 /* initializers tests */
1221 struct structinit1
{
1230 int sinit3
[3] = { 1, 2, {{3}}, };
1231 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1232 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1233 int sinit6
[] = { 1, 2, 3 };
1234 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1235 char sinit8
[] = "hello" "trala";
1237 struct structinit1 sinit9
= { 1, 2, 3 };
1238 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1239 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1247 char *sinit12
= "hello world";
1253 char sinit14
[10] = { "abc" };
1254 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1256 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1272 struct complexinit0
{
1277 struct complexinit
{
1279 const struct complexinit0
*b
;
1282 const static struct complexinit cix
[] = {
1285 .b
= (const struct complexinit0
[]) {
1293 struct complexinit2
{
1298 struct complexinit2 cix21
= {
1300 .b
= { 3001, 3002, 3003 }
1303 struct complexinit2 cix22
= {
1305 .b
= { 4001, 4002, 4003, 4004, 4005, 4006 }
1308 void init_test(void)
1312 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1313 int linit6
[] = { 1, 2, 3 };
1315 char linit8
[] = "hello" "trala";
1316 int linit12
[10] = { 1, 2 };
1317 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1318 char linit14
[10] = "abc";
1319 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1320 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1321 int linit17
= sizeof(linit17
);
1323 printf("init_test:\n");
1325 printf("sinit1=%d\n", sinit1
);
1326 printf("sinit2=%d\n", sinit2
);
1327 printf("sinit3=%d %d %d %d\n",
1333 printf("sinit6=%d\n", sizeof(sinit6
));
1334 printf("sinit7=%d %d %d %d\n",
1340 printf("sinit8=%s\n", sinit8
);
1341 printf("sinit9=%d %d %d\n",
1346 printf("sinit10=%d %d %d\n",
1351 printf("sinit11=%d %d %d %d %d %d\n",
1362 printf("[%d][%d] = %d %d %d\n",
1363 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1364 printf("linit1=%d\n", linit1
);
1365 printf("linit2=%d\n", linit2
);
1366 printf("linit6=%d\n", sizeof(linit6
));
1367 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1369 printf("sinit12=%s\n", sinit12
);
1370 printf("sinit13=%d %s %s %s\n",
1375 printf("sinit14=%s\n", sinit14
);
1377 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1379 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1381 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1383 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1385 printf("%d %d %d %d\n",
1390 /* test that initialisation is done after variable declare */
1391 printf("linit17=%d\n", linit17
);
1392 printf("sinit15=%d\n", sinit15
[0]);
1393 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1394 printf("sinit17=%s %d %s %d\n",
1395 sinit17
[0].s
, sinit17
[0].len
,
1396 sinit17
[1].s
, sinit17
[1].len
);
1398 printf("%x ", sinit18
[i
]);
1400 /* complex init check */
1401 printf("cix: %d %d %d %d %d %d %d\n",
1403 cix
[0].b
[0].a
, cix
[0].b
[0].b
,
1404 cix
[0].b
[1].a
, cix
[0].b
[1].b
,
1405 cix
[0].b
[2].a
, cix
[0].b
[2].b
);
1406 printf("cix2: %d %d\n", cix21
.b
[2], cix22
.b
[5]);
1407 printf("sizeof cix21 %d, sizeof cix22 %d\n", sizeof cix21
, sizeof cix22
);
1435 /* ISOC99 _Bool type */
1436 void c99_bool_test(void)
1442 printf("bool_test:\n");
1443 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1445 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1447 printf("b = %d\n", b
);
1449 printf("b = %d\n", b
);
1453 void bitfield_test(void)
1463 unsigned int f5
: 7;
1465 printf("bitfield_test:");
1466 printf("sizeof(st1) = %d\n", sizeof(st1
));
1475 printf("%d %d %d %d %d\n",
1476 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1480 printf("st1.f1 == -1\n");
1482 printf("st1.f1 != -1\n");
1484 printf("st1.f2 == -1\n");
1486 printf("st1.f2 != -1\n");
1488 /* bit sizes below must be bigger than 32 since GCC doesn't allow
1489 long-long bitfields whose size is not bigger than int */
1494 unsigned long long f3
: 38;
1496 st2
.f1
= 0x123456789ULL
;
1498 st2
.f2
= (long long)a
<< 25;
1501 printf("%lld %lld %lld\n", st2
.f1
, st2
.f2
, st2
.f3
);
1505 #define FLOAT_FMT "%f\n"
1507 /* x86's float isn't compatible with GCC */
1508 #define FLOAT_FMT "%.5f\n"
1511 /* declare strto* functions as they are C99 */
1512 double strtod(const char *nptr
, char **endptr
);
1513 float strtof(const char *nptr
, char **endptr
);
1514 long double strtold(const char *nptr
, char **endptr
);
1516 #define FTEST(prefix, type, fmt)\
1517 void prefix ## cmp(type a, type b)\
1519 printf("%d %d %d %d %d %d\n",\
1526 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1534 printf(fmt "\n", ++a);\
1535 printf(fmt "\n", a++);\
1536 printf(fmt "\n", a);\
1538 printf("%d %d\n", !a, !b);\
1540 void prefix ## fcast(type a)\
1551 printf("ftof: %f %f %Lf\n", fa, da, la);\
1553 ua = (unsigned int)a;\
1554 printf("ftoi: %d %u\n", ia, ua);\
1558 printf("itof: " fmt "\n", b);\
1560 printf("utof: " fmt "\n", b);\
1563 float prefix ## retf(type a) { return a; }\
1564 double prefix ## retd(type a) { return a; }\
1565 long double prefix ## retld(type a) { return a; }\
1567 void prefix ## call(void)\
1569 printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
1570 printf("double: %f\n", prefix ## retd(42.123456789));\
1571 printf("long double: %Lf\n", prefix ## retld(42.123456789));\
1572 printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\
1575 void prefix ## test(void)\
1577 printf("testing '%s'\n", #type);\
1578 prefix ## cmp(1, 2.5);\
1579 prefix ## cmp(2, 1.5);\
1580 prefix ## cmp(1, 1);\
1581 prefix ## fcast(234.6);\
1582 prefix ## fcast(-2334.6);\
1586 FTEST(f
, float, "%f")
1587 FTEST(d
, double, "%f")
1588 FTEST(ld
, long double, "%Lf")
1590 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1593 void float_test(void)
1600 printf("float_test:\n");
1601 printf("sizeof(float) = %d\n", sizeof(float));
1602 printf("sizeof(double) = %d\n", sizeof(double));
1603 printf("sizeof(long double) = %d\n", sizeof(long double));
1607 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1608 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1609 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1611 printf("da=%f\n", da
);
1613 printf("fa=%f\n", fa
);
1616 printf("da = %f\n", da
);
1619 printf("db = %f\n", db
);
1627 return fib(n
-1) + fib(n
-2);
1639 printf("funcptr:\n");
1646 /* more complicated pointer computation */
1649 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1650 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1651 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1652 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1655 void lloptest(long long a
, long long b
)
1657 unsigned long long ua
, ub
;
1662 printf("arith: %Ld %Ld %Ld\n",
1668 printf("arith1: %Ld %Ld\n",
1674 printf("bin: %Ld %Ld %Ld\n",
1680 printf("test: %d %d %d %d %d %d\n",
1688 printf("utest: %d %d %d %d %d %d\n",
1699 printf("arith2: %Ld %Ld\n", a
, 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
);
1704 printf("not: %d %d %d %d\n", !a
, !ua
, !b
, !ub
);
1707 void llshift(long long a
, int b
)
1709 printf("shift: %Ld %Ld %Ld\n",
1710 (unsigned long long)a
>> b
,
1713 printf("shiftc: %Ld %Ld %Ld\n",
1714 (unsigned long long)a
>> 3,
1717 printf("shiftc: %Ld %Ld %Ld\n",
1718 (unsigned long long)a
>> 35,
1728 long long la
, lb
, lc
;
1729 unsigned long long ula
, ulb
, ulc
;
1732 la
= (la
<< 20) | 0x12345;
1734 printf("la=%Ld ula=%Lu\n", la
, ula
);
1739 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1744 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1749 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1754 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1757 long long llfunc1(int a
)
1767 long long int value(struct S
*v
)
1769 return ((long long int)v
->item
);
1772 void longlong_test(void)
1777 printf("longlong_test:\n");
1778 printf("sizeof(long long) = %d\n", sizeof(long long));
1783 printf("%Ld %Ld\n", a
, b
);
1784 printf("%Ld %Ld %Ld %Lx\n",
1788 0x1234567812345679);
1793 lloptest(0xff, 0x1234);
1794 b
= 0x72345678 << 10;
1798 b
= 0x72345678LL
<< 10;
1809 /* long long reg spill test */
1814 printf("%lld\n", value(&a
));
1816 lloptest(0x80000000, 0);
1818 /* another long long spill test */
1824 printf("%lld\n", *p
);
1829 printf("%d %d %d %d\n", a
> b
, a
< b
, a
>= b
, a
<= b
);
1831 printf("%Ld\n", 0x123456789LLU
);
1834 void manyarg_test(void)
1836 long double ld
= 1234567891234LL;
1837 printf("manyarg_test:\n");
1838 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1839 1, 2, 3, 4, 5, 6, 7, 8,
1840 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1841 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1843 1, 2, 3, 4, 5, 6, 7, 8,
1844 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1845 1234567891234LL, 987654321986LL,
1847 printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1849 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1850 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1851 1234567891234LL, 987654321986LL,
1853 /* XXX: known bug of x86-64 */
1855 printf("%d %d %d %d %d %d %d %d %Lf\n",
1856 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1857 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1858 "%Ld %Ld %f %f %Lf\n",
1859 1, 2, 3, 4, 5, 6, 7, 8,
1860 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1861 1234567891234LL, 987654321986LL,
1863 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1864 "%Lf %Ld %Ld %f %f %Lf\n",
1865 1, 2, 3, 4, 5, 6, 7, 8,
1866 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1867 ld
, 1234567891234LL, 987654321986LL,
1872 void vprintf1(const char *fmt
, ...)
1896 i
= va_arg(ap
, int);
1900 d
= va_arg(ap
, double);
1904 ll
= va_arg(ap
, long long);
1908 ld
= va_arg(ap
, long double);
1926 void stdarg_for_struct(struct myspace bob
, ...)
1928 struct myspace george
, bill
;
1933 bill
= va_arg(ap
, struct myspace
);
1934 george
= va_arg(ap
, struct myspace
);
1935 validate
= va_arg(ap
, int);
1936 printf("stdarg_for_struct: %d %d %d %d\n",
1937 bob
.profile
, bill
.profile
, george
.profile
, validate
);
1941 void stdarg_test(void)
1943 long double ld
= 1234567891234LL;
1946 vprintf1("%d %d %d\n", 1, 2, 3);
1947 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1948 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1949 vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
1951 /* a bug of x86's TCC */
1952 vprintf1("%d %f %l %F %d %f %l %F\n",
1953 1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
1955 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1956 1, 2, 3, 4, 5, 6, 7, 8,
1957 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
1958 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1959 1, 2, 3, 4, 5, 6, 7, 8,
1960 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1961 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1963 1, 2, 3, 4, 5, 6, 7, 8,
1964 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1965 1234567891234LL, 987654321986LL,
1967 vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1969 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1970 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1971 1234567891234LL, 987654321986LL,
1973 vprintf1("%d %d %d %d %d %d %d %d %F\n",
1974 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1975 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1977 1, 2, 3, 4, 5, 6, 7, 8,
1978 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1979 1234567891234LL, 987654321986LL,
1981 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1982 "%F %l %l %f %f %F\n",
1983 1, 2, 3, 4, 5, 6, 7, 8,
1984 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1985 ld
, 1234567891234LL, 987654321986LL,
1989 stdarg_for_struct(bob
, bob
, bob
, bob
.profile
);
1992 void whitespace_test(void)
1998 ntf("whitspace:\n");\f\v
2002 #ifdef CORRECT_CR_HANDLING
2011 #ifdef ACCEPT_CR_IN_STRINGS
2012 printf("len1=%d\n", strlen("
2014 #ifdef CORRECT_CR_HANDLING
2017 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
2019 printf("len1=%d\n", strlen("
a
2021 #endif /* ACCEPT_CR_IN_STRINGS */
2024 int reltab
[3] = { 1, 2, 3 };
2026 int *rel1
= &reltab
[1];
2027 int *rel2
= &reltab
[2];
2029 void relocation_test(void)
2031 printf("*rel1=%d\n", *rel1
);
2032 printf("*rel2=%d\n", *rel2
);
2035 void old_style_f(a
,b
,c
)
2039 printf("a=%d b=%d b=%f\n", a
, b
, c
);
2042 void decl_func1(int cmpfn())
2044 printf("cmpfn=%lx\n", (long)cmpfn
);
2047 void decl_func2(cmpfn
)
2050 printf("cmpfn=%lx\n", (long)cmpfn
);
2053 void old_style_function(void)
2055 old_style_f((void *)1, 2, 3.0);
2062 #if defined __i386__ || defined __x86_64__
2063 char *p
= alloca(16);
2064 strcpy(p
,"123456789012345");
2065 printf("alloca: p is %s\n", p
);
2066 char *demo
= "This is only a test.\n";
2067 /* Test alloca embedded in a larger expression */
2068 printf("alloca: %s\n", strcpy(alloca(strlen(demo
)+1),demo
) );
2072 void *bounds_checking_is_enabled()
2074 char ca
[10], *cp
= ca
-1;
2075 return (ca
!= cp
+ 1) ? cp
: NULL
;
2078 void c99_vla_test(int size1
, int size2
)
2080 #if defined __i386__ || defined __x86_64__
2081 int size
= size1
* size2
;
2082 int tab1
[size
][2], tab2
[10][2];
2083 void *tab1_ptr
, *tab2_ptr
, *bad_ptr
;
2085 /* "size" should have been 'captured' at tab1 declaration,
2086 so modifying it should have no effect on VLA behaviour. */
2089 printf("Test C99 VLA 1 (sizeof): ");
2090 printf("%s\n", (sizeof tab1
== size1
* size2
* 2 * sizeof(int)) ? "PASSED" : "FAILED");
2093 printf("Test C99 VLA 2 (ptrs substract): ");
2094 printf("%s\n", (tab2
- tab1
== (tab2_ptr
- tab1_ptr
) / (sizeof(int) * 2)) ? "PASSED" : "FAILED");
2095 printf("Test C99 VLA 3 (ptr add): ");
2096 printf("%s\n", &tab1
[5][1] == (tab1_ptr
+ (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED");
2097 printf("Test C99 VLA 4 (ptr access): ");
2098 tab1
[size1
][1] = 42;
2099 printf("%s\n", (*((int *) (tab1_ptr
+ (size1
* 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED");
2101 printf("Test C99 VLA 5 (bounds checking (might be disabled)): ");
2102 if (bad_ptr
= bounds_checking_is_enabled()) {
2103 int *t1
= &tab1
[size1
* size2
- 1][3];
2104 int *t2
= &tab2
[9][3];
2105 printf("%s ", bad_ptr
== t1
? "PASSED" : "FAILED");
2106 printf("%s ", bad_ptr
== t2
? "PASSED" : "FAILED");
2108 char*c1
= 1 + sizeof(tab1
) + (char*)tab1
;
2109 char*c2
= 1 + sizeof(tab2
) + (char*)tab2
;
2110 printf("%s ", bad_ptr
== c1
? "PASSED" : "FAILED");
2111 printf("%s ", bad_ptr
== c2
? "PASSED" : "FAILED");
2115 printf("%s ", bad_ptr
== i1
? "PASSED" : "FAILED");
2116 printf("%s ", bad_ptr
== i2
? "PASSED" : "FAILED");
2118 int *x1
= tab1
[size1
* size2
+ 1];
2119 int *x2
= tab2
[10 + 1];
2120 printf("%s ", bad_ptr
== x1
? "PASSED" : "FAILED");
2121 printf("%s ", bad_ptr
== x2
? "PASSED" : "FAILED");
2123 printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED ");
2129 void sizeof_test(void)
2134 printf("sizeof(int) = %d\n", sizeof(int));
2135 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
2136 printf("sizeof(long) = %d\n", sizeof(long));
2137 printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
2138 printf("sizeof(short) = %d\n", sizeof(short));
2139 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
2140 printf("sizeof(char) = %d\n", sizeof(char));
2141 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
2142 printf("sizeof(func) = %d\n", sizeof sizeof_test());
2144 printf("sizeof(a++) = %d\n", sizeof a
++);
2145 printf("a=%d\n", a
);
2147 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
2149 /* some alignof tests */
2150 printf("__alignof__(int) = %d\n", __alignof__(int));
2151 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
2152 printf("__alignof__(short) = %d\n", __alignof__(short));
2153 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
2154 printf("__alignof__(char) = %d\n", __alignof__(char));
2155 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
2156 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
2159 void typeof_test(void)
2168 printf("a=%f b=%f c=%f\n", a
, b
, c
);
2171 void statement_expr_test(void)
2184 printf("a=%d\n", a
);
2188 void local_label_test(void)
2194 __label__ l1
, l2
, l3
, l4
;
2208 printf("a=%d\n", a
);
2218 /* inline assembler test */
2221 /* from linux kernel */
2222 static char * strncat1(char * dest
,const char * src
,size_t count
)
2225 __asm__
__volatile__(
2234 "testb %%al,%%al\n\t"
2236 "2:\txorl %2,%2\n\t"
2238 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2239 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2244 static char * strncat2(char * dest
,const char * src
,size_t count
)
2247 __asm__
__volatile__(
2248 "repne scasb\n\t" /* one-line repne prefix + string op */
2255 "testb %%al,%%al\n\t"
2257 "2:\txorl %2,%2\n\t"
2259 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2260 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2265 static inline void * memcpy1(void * to
, const void * from
, size_t n
)
2268 __asm__
__volatile__(
2273 "1:\ttestb $1,%b4\n\t"
2277 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2278 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2283 static inline void * memcpy2(void * to
, const void * from
, size_t n
)
2286 __asm__
__volatile__(
2287 "rep movsl\n\t" /* one-line rep prefix + string op */
2291 "1:\ttestb $1,%b4\n\t"
2295 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2296 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2301 static __inline__
void sigaddset1(unsigned int *set
, int _sig
)
2303 __asm__("btsl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2306 static __inline__
void sigdelset1(unsigned int *set
, int _sig
)
2308 asm("btrl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2311 static __inline__ __const__
unsigned int swab32(unsigned int x
)
2313 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
2314 "rorl $16,%0\n\t" /* swap words */
2315 "xchgb %b0,%h0" /* swap higher bytes */
2321 static __inline__
unsigned long long mul64(unsigned int a
, unsigned int b
)
2323 unsigned long long res
;
2324 __asm__("mull %2" : "=A" (res
) : "a" (a
), "r" (b
));
2328 static __inline__
unsigned long long inc64(unsigned long long a
)
2330 unsigned long long res
;
2331 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res
) : "A" (a
));
2342 printf("inline asm:\n");
2343 /* test the no operand case */
2344 asm volatile ("xorl %eax, %eax");
2346 memcpy1(buf
, "hello", 6);
2347 strncat1(buf
, " worldXXXXX", 3);
2348 printf("%s\n", buf
);
2350 memcpy2(buf
, "hello", 6);
2351 strncat2(buf
, " worldXXXXX", 3);
2352 printf("%s\n", buf
);
2354 /* 'A' constraint test */
2355 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
2356 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
2359 sigdelset1(&set
, 2);
2360 sigaddset1(&set
, 16);
2361 /* NOTE: we test here if C labels are correctly restored after the
2365 __asm__("btsl %1,%0" : "=m"(set
) : "Ir"(20) : "cc");
2366 #ifdef __GNUC__ // works strange with GCC 4.3
2369 printf("set=0x%x\n", set
);
2371 printf("swab32(0x%08x) = 0x%0x\n", val
, swab32(val
));
2385 #define COMPAT_TYPE(type1, type2) \
2387 printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
2388 __builtin_types_compatible_p (type1, type2));\
2393 void builtin_test(void)
2396 COMPAT_TYPE(int, int);
2397 COMPAT_TYPE(int, unsigned int);
2398 COMPAT_TYPE(int, char);
2399 COMPAT_TYPE(int, const int);
2400 COMPAT_TYPE(int, volatile int);
2401 COMPAT_TYPE(int *, int *);
2402 COMPAT_TYPE(int *, void *);
2403 COMPAT_TYPE(int *, const int *);
2404 COMPAT_TYPE(char *, unsigned char *);
2405 /* space is needed because tcc preprocessor introduces a space between each token */
2406 COMPAT_TYPE(char * *, void *);
2408 printf("res = %d\n", __builtin_constant_p(1));
2409 printf("res = %d\n", __builtin_constant_p(1 + 2));
2410 printf("res = %d\n", __builtin_constant_p(&constant_p_var
));
2411 printf("res = %d\n", __builtin_constant_p(constant_p_var
));
2415 extern int __attribute__((weak
)) weak_f1(void);
2416 extern int __attribute__((weak
)) weak_f2(void);
2417 extern int weak_f3(void);
2418 extern int __attribute__((weak
)) weak_v1
;
2419 extern int __attribute__((weak
)) weak_v2
;
2422 extern int (*weak_fpa
)() __attribute__((weak
));
2423 extern int __attribute__((weak
)) (*weak_fpb
)();
2424 extern __attribute__((weak
)) int (*weak_fpc
)();
2426 extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak
));
2427 extern int __attribute((weak
)) weak_asm_f2(void) asm("weak_asm_f2x") ;
2428 extern int __attribute((weak
)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak
));
2429 extern int weak_asm_v1
asm("weak_asm_v1x") __attribute((weak
));
2430 extern int __attribute((weak
)) weak_asm_v2
asm("weak_asm_v2x") ;
2431 extern int __attribute((weak
)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak
));
2433 static const size_t dummy
= 0;
2434 extern __typeof(dummy
) weak_dummy1
__attribute__((weak
, alias("dummy")));
2435 extern __typeof(dummy
) __attribute__((weak
, alias("dummy"))) weak_dummy2
;
2436 extern __attribute__((weak
, alias("dummy"))) __typeof(dummy
) weak_dummy3
;
2438 int some_lib_func(void);
2439 int dummy_impl_of_slf(void) { return 444; }
2440 int some_lib_func(void) __attribute__((weak
, alias("dummy_impl_of_slf")));
2442 int weak_toolate() { return 0; }
2443 int weak_toolate() __attribute__((weak
));
2445 void __attribute__((weak
)) weak_test(void)
2447 printf("weak_f1=%d\n", weak_f1
? weak_f1() : 123);
2448 printf("weak_f2=%d\n", weak_f2
? weak_f2() : 123);
2449 printf("weak_f3=%d\n", weak_f3
? weak_f3() : 123);
2450 printf("weak_v1=%d\n",&weak_v1
? weak_v1
: 123);
2451 printf("weak_v2=%d\n",&weak_v2
? weak_v2
: 123);
2452 printf("weak_v3=%d\n",&weak_v3
? weak_v3
: 123);
2454 printf("weak_fpa=%d\n",&weak_fpa
? weak_fpa() : 123);
2455 printf("weak_fpb=%d\n",&weak_fpb
? weak_fpb() : 123);
2456 printf("weak_fpc=%d\n",&weak_fpc
? weak_fpc() : 123);
2458 printf("weak_asm_f1=%d\n", weak_asm_f1
!= NULL
);
2459 printf("weak_asm_f2=%d\n", weak_asm_f2
!= NULL
);
2460 printf("weak_asm_f3=%d\n", weak_asm_f3
!= NULL
);
2461 printf("weak_asm_v1=%d\n",&weak_asm_v1
!= NULL
);
2462 printf("weak_asm_v2=%d\n",&weak_asm_v2
!= NULL
);
2463 printf("weak_asm_v3=%d\n",&weak_asm_v3
!= NULL
);
2466 int __attribute__((weak
)) weak_f2() { return 222; }
2467 int __attribute__((weak
)) weak_f3() { return 333; }
2468 int __attribute__((weak
)) weak_v2
= 222;
2469 int __attribute__((weak
)) weak_v3
= 333;
2471 void const_func(const int a
)
2475 void const_warn_test(void)