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 /* __VA_ARGS__ and __func__ support */
22 /* test various include syntaxes */
24 #define TCCLIB_INC <tcclib.h>
25 #define TCCLIB_INC1 <tcclib
26 #define TCCLIB_INC2 h>
27 #define TCCLIB_INC3 "tcclib"
31 #include TCCLIB_INC1.TCCLIB_INC2
33 #include TCCLIB_INC1.h>
35 /* gcc 3.2 does not accept that (bug ?) */
36 //#include TCCLIB_INC3 ".h"
58 void constant_expr_test();
60 void char_short_test();
62 void compound_literal_test(void);
64 void struct_assign_test(void);
66 void bitfield_test(void);
67 void c99_bool_test(void);
68 void float_test(void);
69 void longlong_test(void);
70 void stdarg_test(void);
71 void whitespace_test(void);
72 void relocation_test(void);
73 void old_style_function(void);
74 void sizeof_test(void);
75 void typeof_test(void);
76 void local_label_test(void);
77 void statement_expr_test(void);
79 void builtin_test(void);
83 void forward_ref(void);
89 #define M1(a, b) (a) + (b)
93 #define glue(a, b) a ## b
94 #define xglue(a, b) glue(a, b)
95 #define HIGHLOW "hello"
96 #define LOW LOW ", world"
98 #define min(a, b) ((a) < (b) ? (a) : (b))
101 #define dprintf(level,...) printf(__VA_ARGS__)
104 /* gcc vararg macros */
105 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
107 #define MACRO_NOARGS()
123 #define __INT64_C(c) c ## LL
124 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
132 void macro_test(void)
134 printf("macro:\n");\f\v
136 printf("aaa=%d\n", AAA
);
138 printf("min=%d\n", min(1, min(2, -1)));
140 printf("s1=%s\n", glue(HIGH
, LOW
));
141 printf("s2=%s\n", xglue(HIGH
, LOW
));
142 printf("s3=%s\n", str("c"));
143 printf("s4=%s\n", str(a1
));
144 printf("B3=%d\n", B3
);
147 printf("A defined\n");
150 printf("B defined\n");
153 printf("A defined\n");
155 printf("A not defined\n");
158 printf("B defined\n");
160 printf("B not defined\n");
164 printf("A defined\n");
166 printf("B1 defined\n");
168 printf("B1 not defined\n");
171 printf("A not defined\n");
173 printf("B2 defined\n");
175 printf("B2 not defined\n");
180 printf("test true1\n");
183 printf("test true2\n");
186 printf("test true3\n");
189 printf("test trueA\n");
192 printf("test trueB\n");
208 printf("__LINE__ defined\n");
211 printf("__LINE__=%d __FILE__=%s\n",
214 printf("__LINE__=%d __FILE__=%s\n",
217 printf("__LINE__=%d __FILE__=%s\n",
219 #line 220 "tcctest.c"
221 /* not strictly preprocessor, but we test it there */
223 printf("__func__ = %s\n", __func__
);
224 dprintf(1, "vaarg=%d\n", 1);
226 dprintf1(1, "vaarg1\n");
227 dprintf1(1, "vaarg1=%d\n", 2);
228 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
231 printf("func='%s'\n", __FUNCTION__
);
233 /* complicated macros in glibc */
234 printf("INT64_MIN=%Ld\n", INT64_MIN
);
244 /* macro function with argument outside the macro string */
245 #define MF_s MF_hello
246 #define MF_hello(msg) printf("%s\n",msg)
248 #define MF_t printf("tralala\n"); MF_hello
253 /* test macro substituion inside args (should not eat stream) */
254 printf("qq=%d\n", qq(qq
)(2));
256 /* test zero argument case. NOTE: gcc 2.95.x does not accept a
257 null argument without a space. gcc 3.2 fixes that. */
260 printf("qq1=%d\n", qq1( ));
262 /* comment with stray handling *\
264 /* this is a valid *\/ comment */
265 /* this is a valid comment *\*/
284 void ps(const char *s
)
296 const char foo1_string
[] = "\
305 printf("\141\1423\143\n");/* dezdez test */
306 printf("\x41\x42\x43\x3a\n");
307 printf("c=%c\n", 'r');
308 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
309 printf("foo1_string='%s'\n", foo1_string
);
311 printf("wstring=%S\n", L
"abc");
312 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
313 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
314 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
318 while ((b
= b
+ 1) < 96) {
322 printf("fib=%d\n", fib(33));
324 while (b
!= 0x80000000) {
337 for(i
= 0; i
< 10;i
++)
346 /* break/continue tests */
358 /* break/continue tests */
370 for(i
= 0;i
< 10;i
++) {
382 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
395 /* we also test computed gotos (GCC extension) */
397 goto *label_table
[i
];
425 printf("enum:\n%d %d %d %d %d %d\n",
426 E0
, E1
, E2
, E3
, E4
, E5
);
428 printf("b1=%d\n", b1
);
439 printf("typedef:\n");
440 printf("a=%d\n", *a
);
445 printf("forward:\n");
451 void forward_ref(void)
453 printf("forward ok\n");
456 typedef struct struct1
{
476 struct struct1 st1
, st2
;
478 int main(int argc
, char **argv
)
496 constant_expr_test();
500 compound_literal_test();
502 struct_assign_test();
511 old_style_function();
514 statement_expr_test();
528 printf("g1=%d\n", g
);
536 printf("g2=%d\n", g
);
540 printf("g3=%d\n", g
);
544 printf("g4=%d\n", g
);
547 printf("g5=%d\n", g
);
550 void array_test(int a
[4])
555 printf("sizeof(a) = %d\n", sizeof(a
));
556 printf("sizeof(\"a\") = %d\n", sizeof("a"));
558 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
560 printf("sizeof tab %d\n", sizeof(tab
));
561 printf("sizeof tab2 %d\n", sizeof tab2
);
565 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
568 tab2
[i
][j
] = 10 * i
+ j
;
570 printf(" %3d", ((int *)tab2
)[i
]);
579 printf("%d\n", a
+= 1);
580 printf("%d\n", a
-= 2);
581 printf("%d\n", a
*= 31232132);
582 printf("%d\n", a
/= 4);
583 printf("%d\n", a
%= 20);
584 printf("%d\n", a
&= 6);
585 printf("%d\n", a
^= 7);
586 printf("%d\n", a
|= 8);
587 printf("%d\n", a
>>= 3);
588 printf("%d\n", a
<<= 4);
592 printf("%d\n", a
+ 1);
593 printf("%d\n", a
- 2);
594 printf("%d\n", a
* 312);
595 printf("%d\n", a
/ 4);
596 printf("%d\n", b
/ 4);
597 printf("%d\n", (unsigned)b
/ 4);
598 printf("%d\n", a
% 20);
599 printf("%d\n", b
% 20);
600 printf("%d\n", (unsigned)b
% 20);
601 printf("%d\n", a
& 6);
602 printf("%d\n", a
^ 7);
603 printf("%d\n", a
| 8);
604 printf("%d\n", a
>> 3);
605 printf("%d\n", b
>> 3);
606 printf("%d\n", (unsigned)b
>> 3);
607 printf("%d\n", a
<< 4);
612 printf("%d\n", 12 + 1);
613 printf("%d\n", 12 - 2);
614 printf("%d\n", 12 * 312);
615 printf("%d\n", 12 / 4);
616 printf("%d\n", 12 % 20);
617 printf("%d\n", 12 & 6);
618 printf("%d\n", 12 ^ 7);
619 printf("%d\n", 12 | 8);
620 printf("%d\n", 12 >> 2);
621 printf("%d\n", 12 << 4);
625 printf("%d %d %d %d\n",
634 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
637 /**********************/
639 int vstack
[10], *vstack_ptr
;
641 void vpush(int vt
, int vc
)
647 void vpop(int *ft
, int *fc
)
660 vstack_ptr
[-2] &= ~0xffffff80;
662 printf("res= %d %d\n", a
, b
);
665 void constant_expr_test()
668 printf("constant_expr:\n");
670 printf("%d\n", a
* 16);
671 printf("%d\n", a
* 1);
672 printf("%d\n", a
+ 0);
681 printf("expr_ptr:\n");
684 printf("diff=%d\n", q
- p
);
686 printf("inc=%d\n", p
- tab4
);
688 printf("dec=%d\n", p
- tab4
);
690 printf("inc=%d\n", p
- tab4
);
692 printf("dec=%d\n", p
- tab4
);
693 printf("add=%d\n", p
+ 3 - tab4
);
694 printf("add=%d\n", 3 + p
- tab4
);
700 printf("constant_expr:\n");
703 printf("%d\n", a
== a
);
704 printf("%d\n", a
!= a
);
706 printf("%d\n", a
< b
);
707 printf("%d\n", a
<= b
);
708 printf("%d\n", a
<= a
);
709 printf("%d\n", b
>= a
);
710 printf("%d\n", a
>= a
);
711 printf("%d\n", b
> a
);
713 printf("%d\n", (unsigned)a
< b
);
714 printf("%d\n", (unsigned)a
<= b
);
715 printf("%d\n", (unsigned)a
<= a
);
716 printf("%d\n", (unsigned)b
>= a
);
717 printf("%d\n", (unsigned)a
>= a
);
718 printf("%d\n", (unsigned)b
> a
);
747 printf("sizes: %d %d %d %d\n",
748 sizeof(struct struct1
),
749 sizeof(struct struct2
),
750 sizeof(union union1
),
751 sizeof(union union2
));
755 printf("st1: %d %d %d\n",
756 st1
.f1
, st1
.f2
, st1
.f3
);
759 printf("union1: %d\n", st1
.u
.v1
);
762 printf("union2: %d\n", u
.w1
);
767 printf("st2: %d %d %d\n",
768 s
->f1
, s
->f2
, s
->f3
);
769 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
771 /* align / size tests */
772 printf("aligntest1 sizeof=%d alignof=%d\n",
773 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
774 printf("aligntest2 sizeof=%d alignof=%d\n",
775 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
776 printf("aligntest3 sizeof=%d alignof=%d\n",
777 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
778 printf("aligntest4 sizeof=%d alignof=%d\n",
779 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
781 /* empty structures (GCC extension) */
782 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
783 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
786 /* XXX: depend on endianness */
787 void char_short_test()
791 printf("char_short:\n");
796 *(char *)&var1
, *(char *)&var2
);
798 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
799 printf("s16=%d %d\n",
800 *(short *)&var1
, *(short *)&var2
);
801 printf("u16=%d %d\n",
802 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
803 printf("s32=%d %d\n",
804 *(int *)&var1
, *(int *)&var2
);
805 printf("u32=%d %d\n",
806 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
807 *(char *)&var1
= 0x08;
808 printf("var1=%x\n", var1
);
809 *(short *)&var1
= 0x0809;
810 printf("var1=%x\n", var1
);
811 *(int *)&var1
= 0x08090a0b;
812 printf("var1=%x\n", var1
);
825 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
826 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
828 static int toupper1(int a
)
835 int *s
, a
, b
, t
, f
, i
;
839 printf("!s=%d\n", !s
);
845 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
846 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
847 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
862 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
864 /* test register spilling */
867 a
= (a
+ b
) * ((a
< b
) ?
868 ((b
- a
) * (a
- b
)): a
+ b
);
871 /* test complex || or && expressions */
875 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
876 printf("r=%d\n", (t
|| f
) + (t
&& f
));
881 int aspect_native
= 65536;
882 double bfu_aspect
= 1.0;
884 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
885 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
886 printf("aspect=%d\n", aspect
);
890 /* test ? : GCC extension */
892 static int v1
= 34 ? : -1; /* constant case */
893 static int v2
= 0 ? : -1; /* constant case */
896 printf("%d %d\n", v1
, v2
);
897 printf("%d %d\n", a
- 30 ? : a
* 2, a
+ 1 ? : a
* 2);
900 /* again complex expression */
902 if (toupper1 (i
) != TOUPPER (i
))
903 printf("error %d\n", i
);
907 /* GCC accepts that */
908 static int tab_reinit
[];
909 static int tab_reinit
[10];
911 //int cinit1; /* a global variable can be defined several times without error ! */
915 int *cinit2
= (int []){3, 2, 1};
917 void compound_literal_test(void)
922 printf("compound_test:\n");
924 p
= (int []){1, 2, 3};
930 printf("%d", cinit2
[i
]);
934 printf("q1=%s\n", q
);
936 q
= (char *){ "tralala2" };
937 printf("q2=%s\n", q
);
940 printf("q3=%s\n", q3
);
942 q
= (char []){ "tralala3" };
943 printf("q4=%s\n", q
);
946 p
= (int []){1, 2, cinit1
+ 3};
952 p
= (int []){1, 2, 4 + i
};
975 printf("kr_test:\n");
976 printf("func1=%d\n", kr_func1(3, 4));
977 printf("func2=%d\n", kr_func2(3, 4));
984 tab
= (char*)malloc(20);
1000 /* structure assignment tests */
1006 struct structa1 ssta1
;
1008 void struct_assign_test1(struct structa1 s1
, int t
)
1010 printf("%d %d %d\n", s1
.f1
, s1
.f2
, t
);
1013 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
1020 void struct_assign_test(void)
1022 struct structa1 lsta1
, lsta2
;
1025 printf("struct_assign_test:\n");
1029 printf("%d %d\n", lsta1
.f1
, lsta1
.f2
);
1031 printf("%d %d\n", lsta2
.f1
, lsta2
.f2
);
1036 struct_assign_test1(lsta2
, 3);
1038 printf("before call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1039 lsta2
= struct_assign_test2(lsta2
, 4);
1040 printf("after call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1043 /* casts to short/char */
1045 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
1047 printf("%d %d %d %d\n", a
, b
, c
, d
);
1059 printf("cast_test:\n");
1063 printf("%d %d %d %d\n",
1066 (unsigned char)(a
+ 1),
1067 (unsigned short)(a
+ 1));
1068 printf("%d %d %d %d\n",
1071 (unsigned char)0xfffff,
1072 (unsigned short)0xfffff);
1074 a
= (bcast
= 128) + 1;
1076 a
= (scast
= 65536) + 1;
1079 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1081 /* test implicit int casting for array accesses */
1085 printf("%d %d\n", tab
[0], tab
[1]);
1087 /* test implicit casting on some operators */
1088 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1089 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1090 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1093 /* initializers tests */
1094 struct structinit1
{
1103 int sinit3
[3] = { 1, 2, {{3}}, };
1104 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1105 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1106 int sinit6
[] = { 1, 2, 3 };
1107 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1108 char sinit8
[] = "hello" "trala";
1110 struct structinit1 sinit9
= { 1, 2, 3 };
1111 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1112 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1120 char *sinit12
= "hello world";
1126 char sinit14
[10] = { "abc" };
1127 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1129 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1145 void init_test(void)
1149 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1150 int linit6
[] = { 1, 2, 3 };
1152 char linit8
[] = "hello" "trala";
1153 int linit12
[10] = { 1, 2 };
1154 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1155 char linit14
[10] = "abc";
1156 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1157 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1158 int linit17
= sizeof(linit17
);
1160 printf("init_test:\n");
1162 printf("sinit1=%d\n", sinit1
);
1163 printf("sinit2=%d\n", sinit2
);
1164 printf("sinit3=%d %d %d %d\n",
1170 printf("sinit6=%d\n", sizeof(sinit6
));
1171 printf("sinit7=%d %d %d %d\n",
1177 printf("sinit8=%s\n", sinit8
);
1178 printf("sinit9=%d %d %d\n",
1183 printf("sinit10=%d %d %d\n",
1188 printf("sinit11=%d %d %d %d %d %d\n",
1199 printf("[%d][%d] = %d %d %d\n",
1200 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1201 printf("linit1=%d\n", linit1
);
1202 printf("linit2=%d\n", linit2
);
1203 printf("linit6=%d\n", sizeof(linit6
));
1204 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1206 printf("sinit12=%s\n", sinit12
);
1207 printf("sinit13=%d %s %s %s\n",
1212 printf("sinit14=%s\n", sinit14
);
1214 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1216 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1218 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1220 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1222 printf("%d %d %d %d\n",
1227 /* test that initialisation is done after variable declare */
1228 printf("linit17=%d\n", linit17
);
1229 printf("sinit15=%d\n", sinit15
[0]);
1230 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1231 printf("sinit17=%s %d %s %d\n",
1232 sinit17
[0].s
, sinit17
[0].len
,
1233 sinit17
[1].s
, sinit17
[1].len
);
1235 printf("%x ", sinit18
[i
]);
1264 /* ISOC99 _Bool type */
1265 void c99_bool_test(void)
1271 printf("bool_test:\n");
1272 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1274 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1276 printf("b = %d\n", b
);
1278 printf("b = %d\n", b
);
1282 void bitfield_test(void)
1292 unsigned int f5
: 7;
1294 printf("bitfield_test:");
1295 printf("sizeof(st1) = %d\n", sizeof(st1
));
1304 printf("%d %d %d %d %d\n",
1305 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1309 printf("st1.f1 == -1\n");
1311 printf("st1.f1 != -1\n");
1313 printf("st1.f2 == -1\n");
1315 printf("st1.f2 != -1\n");
1318 #define FTEST(prefix, type, fmt)\
1319 void prefix ## cmp(type a, type b)\
1321 printf("%d %d %d %d %d %d\n",\
1328 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1336 printf(fmt "\n", ++a);\
1337 printf(fmt "\n", a++);\
1338 printf(fmt "\n", a);\
1340 void prefix ## fcast(type a)\
1351 printf("ftof: %f %f %Lf\n", fa, da, la);\
1353 ua = (unsigned int)a;\
1354 printf("ftoi: %d %u\n", ia, ua);\
1358 printf("itof: " fmt "\n", b);\
1360 printf("utof: " fmt "\n", b);\
1363 void prefix ## test(void)\
1365 printf("testing '%s'\n", #type);\
1366 prefix ## cmp(1, 2.5);\
1367 prefix ## cmp(2, 1.5);\
1368 prefix ## cmp(1, 1);\
1369 prefix ## fcast(234.6);\
1370 prefix ## fcast(-2334.6);\
1373 FTEST(f
, float, "%f")
1374 FTEST(d
, double, "%f")
1375 FTEST(ld
, long double, "%Lf")
1377 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1380 void float_test(void)
1387 printf("float_test:\n");
1388 printf("sizeof(float) = %d\n", sizeof(float));
1389 printf("sizeof(double) = %d\n", sizeof(double));
1390 printf("sizeof(long double) = %d\n", sizeof(long double));
1394 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1395 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1396 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1398 printf("da=%f\n", da
);
1400 printf("fa=%f\n", fa
);
1403 printf("da = %f\n", da
);
1406 printf("db = %f\n", db
);
1414 return fib(n
-1) + fib(n
-2);
1426 printf("funcptr:\n");
1433 /* more complicated pointer computation */
1436 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1437 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1438 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1439 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1442 void lloptest(long long a
, long long b
)
1444 unsigned long long ua
, ub
;
1449 printf("arith: %Ld %Ld %Ld\n",
1455 printf("arith1: %Ld %Ld\n",
1461 printf("bin: %Ld %Ld %Ld\n",
1467 printf("test: %d %d %d %d %d %d\n",
1475 printf("utest: %d %d %d %d %d %d\n",
1486 printf("arith2: %Ld %Ld\n", a
, b
);
1487 printf("arith2: %Ld %Ld\n", a
++, b
++);
1488 printf("arith2: %Ld %Ld\n", --a
, --b
);
1489 printf("arith2: %Ld %Ld\n", a
, b
);
1492 void llshift(long long a
, int b
)
1494 printf("shift: %Ld %Ld %Ld\n",
1495 (unsigned long long)a
>> b
,
1498 printf("shiftc: %Ld %Ld %Ld\n",
1499 (unsigned long long)a
>> 3,
1502 printf("shiftc: %Ld %Ld %Ld\n",
1503 (unsigned long long)a
>> 35,
1513 long long la
, lb
, lc
;
1514 unsigned long long ula
, ulb
, ulc
;
1517 la
= (la
<< 20) | 0x12345;
1519 printf("la=%Ld ula=%Lu\n", la
, ula
);
1524 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1529 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1534 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1539 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1542 long long llfunc1(int a
)
1552 long long int value(struct S
*v
)
1554 return ((long long int)v
->item
);
1557 void longlong_test(void)
1562 printf("longlong_test:\n");
1563 printf("sizeof(long long) = %d\n", sizeof(long long));
1568 printf("%Ld %Ld\n", a
, b
);
1569 printf("%Ld %Ld %Ld %Lx\n",
1573 0x1234567812345679);
1578 lloptest(0xff, 0x1234);
1579 b
= 0x72345678 << 10;
1583 b
= 0x72345678LL
<< 10;
1594 /* long long reg spill test */
1599 printf("%lld\n", value(&a
));
1601 lloptest(0x80000000, 0);
1603 /* another long long spill test */
1609 printf("%lld\n", *p
);
1613 void vprintf1(const char *fmt
, ...)
1635 i
= va_arg(ap
, int);
1639 d
= va_arg(ap
, double);
1643 ll
= va_arg(ap
, long long);
1657 void stdarg_test(void)
1659 vprintf1("%d %d %d\n", 1, 2, 3);
1660 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1661 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1664 void whitespace_test(void)
1670 ntf("whitspace:\n");\f\v
1674 #ifdef CORRECT_CR_HANDLING
1682 printf("len1=%d\n", strlen("
1684 #ifdef CORRECT_CR_HANDLING
1687 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
1689 printf("len1=%d\n", strlen("
a
1693 int reltab
[3] = { 1, 2, 3 };
1695 int *rel1
= &reltab
[1];
1696 int *rel2
= &reltab
[2];
1698 void relocation_test(void)
1700 printf("*rel1=%d\n", *rel1
);
1701 printf("*rel2=%d\n", *rel2
);
1704 void old_style_f(a
,b
,c
)
1708 printf("a=%d b=%d b=%f\n", a
, b
, c
);
1711 void decl_func1(int cmpfn())
1713 printf("cmpfn=%lx\n", (long)cmpfn
);
1716 void decl_func2(cmpfn
)
1719 printf("cmpfn=%lx\n", (long)cmpfn
);
1722 void old_style_function(void)
1724 old_style_f((void *)1, 2, 3.0);
1729 void sizeof_test(void)
1734 printf("sizeof(int) = %d\n", sizeof(int));
1735 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
1736 printf("sizeof(short) = %d\n", sizeof(short));
1737 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
1738 printf("sizeof(char) = %d\n", sizeof(char));
1739 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
1740 printf("sizeof(func) = %d\n", sizeof sizeof_test());
1742 printf("sizeof(a++) = %d\n", sizeof a
++);
1743 printf("a=%d\n", a
);
1745 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
1747 /* some alignof tests */
1748 printf("__alignof__(int) = %d\n", __alignof__(int));
1749 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
1750 printf("__alignof__(short) = %d\n", __alignof__(short));
1751 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
1752 printf("__alignof__(char) = %d\n", __alignof__(char));
1753 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
1754 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
1757 void typeof_test(void)
1766 printf("a=%f b=%f c=%f\n", a
, b
, c
);
1769 void statement_expr_test(void)
1782 printf("a=%d\n", a
);
1786 void local_label_test(void)
1792 __label__ l1
, l2
, l3
;
1806 printf("a=%d\n", a
);
1816 /* inline assembler test */
1819 /* from linux kernel */
1820 static char * strncat1(char * dest
,const char * src
,size_t count
)
1823 __asm__
__volatile__(
1832 "testb %%al,%%al\n\t"
1834 "2:\txorl %2,%2\n\t"
1836 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
1837 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
1842 static inline void * memcpy1(void * to
, const void * from
, size_t n
)
1845 __asm__
__volatile__(
1850 "1:\ttestb $1,%b4\n\t"
1854 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
1855 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
1860 static __inline__
void sigaddset1(unsigned int *set
, int _sig
)
1862 __asm__("btsl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
1865 static __inline__
void sigdelset1(unsigned int *set
, int _sig
)
1867 asm("btrl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
1870 static __inline__ __const__
unsigned int swab32(unsigned int x
)
1872 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
1873 "rorl $16,%0\n\t" /* swap words */
1874 "xchgb %b0,%h0" /* swap higher bytes */
1880 static __inline__
unsigned long long mul64(unsigned int a
, unsigned int b
)
1882 unsigned long long res
;
1883 __asm__("mull %2" : "=A" (res
) : "a" (a
), "r" (b
));
1887 static __inline__
unsigned long long inc64(unsigned long long a
)
1889 unsigned long long res
;
1890 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res
) : "A" (a
));
1901 printf("inline asm:\n");
1902 /* test the no operand case */
1903 asm volatile ("xorl %eax, %eax");
1905 memcpy1(buf
, "hello", 6);
1906 strncat1(buf
, " worldXXXXX", 3);
1907 printf("%s\n", buf
);
1909 /* 'A' constraint test */
1910 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
1911 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
1914 sigdelset1(&set
, 2);
1915 sigaddset1(&set
, 16);
1916 /* NOTE: we test here if C labels are correctly restored after the
1920 __asm__("btsl %1,%0" : "=m"(set
) : "Ir"(20) : "cc");
1921 printf("set=0x%x\n", set
);
1923 printf("swab32(0x%08x) = 0x%0x\n", val
, swab32(val
));
1937 #define COMPAT_TYPE(type1, type2) \
1939 printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
1940 __builtin_types_compatible_p (type1, type2));\
1945 void builtin_test(void)
1948 COMPAT_TYPE(int, int);
1949 COMPAT_TYPE(int, unsigned int);
1950 COMPAT_TYPE(int, char);
1951 COMPAT_TYPE(int, const int);
1952 COMPAT_TYPE(int, volatile int);
1953 COMPAT_TYPE(int *, int *);
1954 COMPAT_TYPE(int *, void *);
1955 COMPAT_TYPE(int *, const int *);
1956 COMPAT_TYPE(char *, unsigned char *);
1957 /* space is needed because tcc preprocessor introduces a space between each token */
1958 COMPAT_TYPE(char * *, void *);
1960 printf("res = %d\n", __builtin_constant_p(1));
1961 printf("res = %d\n", __builtin_constant_p(1 + 2));
1962 printf("res = %d\n", __builtin_constant_p(&constant_p_var
));
1963 printf("res = %d\n", __builtin_constant_p(constant_p_var
));
1967 void const_func(const int a
)
1971 void const_warn_test(void)