2 * TCC auto test program
5 /* Unfortunately, gcc version < 3 does not handle that! */
8 /* only gcc 3 handles _Bool correctly */
13 /* gcc 2.95.3 does not handle correctly CR in strings or after strays */
14 //#define CORRECT_CR_HANDLING
16 /* test various include syntaxes */
18 #define TCCLIB_INC <tcclib.h>
19 #define TCCLIB_INC1 <tcclib
20 #define TCCLIB_INC2 h>
21 #define TCCLIB_INC3 "tcclib"
25 #include TCCLIB_INC1.TCCLIB_INC2
27 #include TCCLIB_INC1.h>
29 /* gcc 3.2 does not accept that (bug ?) */
30 //#include TCCLIB_INC3 ".h"
52 void constant_expr_test();
54 void char_short_test();
56 void compound_literal_test(void);
58 void struct_assign_test(void);
60 void bitfield_test(void);
61 void c99_bool_test(void);
62 void float_test(void);
63 void longlong_test(void);
64 void stdarg_test(void);
65 void whitespace_test(void);
66 void relocation_test(void);
67 void old_style_function(void);
68 void sizeof_test(void);
69 void typeof_test(void);
70 void local_label_test(void);
71 void statement_expr_test(void);
76 void forward_ref(void);
82 #define M1(a, b) (a) + (b)
86 #define glue(a, b) a ## b
87 #define xglue(a, b) glue(a, b)
88 #define HIGHLOW "hello"
89 #define LOW LOW ", world"
91 #define min(a, b) ((a) < (b) ? (a) : (b))
94 #define dprintf(level,...) printf(__VA_ARGS__)
97 /* gcc vararg macros */
98 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
100 #define MACRO_NOARGS()
116 #define __INT64_C(c) c ## LL
117 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
119 void macro_test(void)
121 printf("macro:\n");\f\v
123 printf("aaa=%d\n", AAA
);
125 printf("min=%d\n", min(1, min(2, -1)));
127 printf("s1=%s\n", glue(HIGH
, LOW
));
128 printf("s2=%s\n", xglue(HIGH
, LOW
));
129 printf("s3=%s\n", str("c"));
130 printf("s4=%s\n", str(a1
));
131 printf("B3=%d\n", B3
);
134 printf("A defined\n");
137 printf("B defined\n");
140 printf("A defined\n");
142 printf("A not defined\n");
145 printf("B defined\n");
147 printf("B not defined\n");
151 printf("A defined\n");
153 printf("B1 defined\n");
155 printf("B1 not defined\n");
158 printf("A not defined\n");
160 printf("B2 defined\n");
162 printf("B2 not defined\n");
167 printf("test true1\n");
170 printf("test true2\n");
173 printf("test true3\n");
176 printf("test trueA\n");
179 printf("test trueB\n");
195 printf("__LINE__ defined\n");
198 printf("__LINE__=%d __FILE__=%s\n",
201 printf("__LINE__=%d __FILE__=%s\n",
204 printf("__LINE__=%d __FILE__=%s\n",
206 #line 206 "tcctest.c"
208 /* not strictly preprocessor, but we test it there */
210 printf("__func__ = %s\n", __func__
);
211 dprintf(1, "vaarg=%d\n", 1);
213 dprintf1(1, "vaarg1\n");
214 dprintf1(1, "vaarg1=%d\n", 2);
215 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
218 printf("func='%s'\n", __FUNCTION__
);
220 /* complicated macros in glibc */
221 printf("INT64_MIN=%Ld\n", INT64_MIN
);
231 /* comment with stray handling *\
265 printf("\141\1423\143\n");/* dezdez test */
266 printf("\x41\x42\x43\x3a\n");
267 printf("c=%c\n", 'r');
268 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
270 printf("wstring=%S\n", L
"abc");
271 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
272 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
273 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
277 while ((b
= b
+ 1) < 96) {
281 printf("fib=%d\n", fib(33));
283 while (b
!= 0x80000000) {
296 for(i
= 0; i
< 10;i
++)
305 /* break/continue tests */
317 /* break/continue tests */
329 for(i
= 0;i
< 10;i
++) {
341 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
354 /* we also test computed gotos (GCC extension) */
356 goto *label_table
[i
];
384 printf("enum:\n%d %d %d %d %d %d\n",
385 E0
, E1
, E2
, E3
, E4
, E5
);
387 printf("b1=%d\n", b1
);
398 printf("typedef:\n");
399 printf("a=%d\n", *a
);
404 printf("forward:\n");
410 void forward_ref(void)
412 printf("forward ok\n");
415 typedef struct struct1
{
435 struct struct1 st1
, st2
;
437 int main(int argc
, char **argv
)
455 constant_expr_test();
459 compound_literal_test();
461 struct_assign_test();
470 old_style_function();
473 statement_expr_test();
486 printf("g1=%d\n", g
);
494 printf("g2=%d\n", g
);
498 printf("g3=%d\n", g
);
502 printf("g4=%d\n", g
);
505 printf("g5=%d\n", g
);
508 void array_test(int a
[4])
513 printf("sizeof(a) = %d\n", sizeof(a
));
514 printf("sizeof(\"a\") = %d\n", sizeof("a"));
516 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
518 printf("sizeof tab %d\n", sizeof(tab
));
519 printf("sizeof tab2 %d\n", sizeof tab2
);
523 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
526 tab2
[i
][j
] = 10 * i
+ j
;
528 printf(" %3d", ((int *)tab2
)[i
]);
537 printf("%d\n", a
+= 1);
538 printf("%d\n", a
-= 2);
539 printf("%d\n", a
*= 31232132);
540 printf("%d\n", a
/= 4);
541 printf("%d\n", a
%= 20);
542 printf("%d\n", a
&= 6);
543 printf("%d\n", a
^= 7);
544 printf("%d\n", a
|= 8);
545 printf("%d\n", a
>>= 3);
546 printf("%d\n", a
<<= 4);
550 printf("%d\n", a
+ 1);
551 printf("%d\n", a
- 2);
552 printf("%d\n", a
* 312);
553 printf("%d\n", a
/ 4);
554 printf("%d\n", b
/ 4);
555 printf("%d\n", (unsigned)b
/ 4);
556 printf("%d\n", a
% 20);
557 printf("%d\n", b
% 20);
558 printf("%d\n", (unsigned)b
% 20);
559 printf("%d\n", a
& 6);
560 printf("%d\n", a
^ 7);
561 printf("%d\n", a
| 8);
562 printf("%d\n", a
>> 3);
563 printf("%d\n", b
>> 3);
564 printf("%d\n", (unsigned)b
>> 3);
565 printf("%d\n", a
<< 4);
570 printf("%d\n", 12 + 1);
571 printf("%d\n", 12 - 2);
572 printf("%d\n", 12 * 312);
573 printf("%d\n", 12 / 4);
574 printf("%d\n", 12 % 20);
575 printf("%d\n", 12 & 6);
576 printf("%d\n", 12 ^ 7);
577 printf("%d\n", 12 | 8);
578 printf("%d\n", 12 >> 2);
579 printf("%d\n", 12 << 4);
583 printf("%d %d %d %d\n",
592 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
595 /**********************/
597 int vstack
[10], *vstack_ptr
;
599 void vpush(int vt
, int vc
)
605 void vpop(int *ft
, int *fc
)
618 vstack_ptr
[-2] &= ~0xffffff80;
620 printf("res= %d %d\n", a
, b
);
623 void constant_expr_test()
626 printf("constant_expr:\n");
628 printf("%d\n", a
* 16);
629 printf("%d\n", a
* 1);
630 printf("%d\n", a
+ 0);
639 printf("expr_ptr:\n");
642 printf("diff=%d\n", q
- p
);
644 printf("inc=%d\n", p
- tab4
);
646 printf("dec=%d\n", p
- tab4
);
648 printf("inc=%d\n", p
- tab4
);
650 printf("dec=%d\n", p
- tab4
);
651 printf("add=%d\n", p
+ 3 - tab4
);
652 printf("add=%d\n", 3 + p
- tab4
);
658 printf("constant_expr:\n");
661 printf("%d\n", a
== a
);
662 printf("%d\n", a
!= a
);
664 printf("%d\n", a
< b
);
665 printf("%d\n", a
<= b
);
666 printf("%d\n", a
<= a
);
667 printf("%d\n", b
>= a
);
668 printf("%d\n", a
>= a
);
669 printf("%d\n", b
> a
);
671 printf("%d\n", (unsigned)a
< b
);
672 printf("%d\n", (unsigned)a
<= b
);
673 printf("%d\n", (unsigned)a
<= a
);
674 printf("%d\n", (unsigned)b
>= a
);
675 printf("%d\n", (unsigned)a
>= a
);
676 printf("%d\n", (unsigned)b
> a
);
705 printf("sizes: %d %d %d %d\n",
706 sizeof(struct struct1
),
707 sizeof(struct struct2
),
708 sizeof(union union1
),
709 sizeof(union union2
));
713 printf("st1: %d %d %d\n",
714 st1
.f1
, st1
.f2
, st1
.f3
);
717 printf("union1: %d\n", st1
.u
.v1
);
720 printf("union2: %d\n", u
.w1
);
725 printf("st2: %d %d %d\n",
726 s
->f1
, s
->f2
, s
->f3
);
727 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
729 /* align / size tests */
730 printf("aligntest1 sizeof=%d alignof=%d\n",
731 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
732 printf("aligntest2 sizeof=%d alignof=%d\n",
733 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
734 printf("aligntest3 sizeof=%d alignof=%d\n",
735 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
736 printf("aligntest4 sizeof=%d alignof=%d\n",
737 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
739 /* empty structures (GCC extension) */
740 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
741 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
744 /* XXX: depend on endianness */
745 void char_short_test()
749 printf("char_short:\n");
754 *(char *)&var1
, *(char *)&var2
);
756 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
757 printf("s16=%d %d\n",
758 *(short *)&var1
, *(short *)&var2
);
759 printf("u16=%d %d\n",
760 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
761 printf("s32=%d %d\n",
762 *(int *)&var1
, *(int *)&var2
);
763 printf("u32=%d %d\n",
764 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
765 *(char *)&var1
= 0x08;
766 printf("var1=%x\n", var1
);
767 *(short *)&var1
= 0x0809;
768 printf("var1=%x\n", var1
);
769 *(int *)&var1
= 0x08090a0b;
770 printf("var1=%x\n", var1
);
783 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
784 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
786 static int toupper1(int a
)
793 int *s
, a
, b
, t
, f
, i
;
797 printf("!s=%d\n", !s
);
803 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
804 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
805 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
820 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
822 /* test register spilling */
825 a
= (a
+ b
) * ((a
< b
) ?
826 ((b
- a
) * (a
- b
)): a
+ b
);
829 /* test complex || or && expressions */
833 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
834 printf("r=%d\n", (t
|| f
) + (t
&& f
));
839 int aspect_native
= 65536;
840 double bfu_aspect
= 1.0;
842 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
843 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
844 printf("aspect=%d\n", aspect
);
848 /* test ? : GCC extension */
850 static int v1
= 34 ? : -1; /* constant case */
851 static int v2
= 0 ? : -1; /* constant case */
854 printf("%d %d\n", v1
, v2
);
855 printf("%d %d\n", a
- 30 ? : a
* 2, a
+ 1 ? : a
* 2);
858 /* again complex expression */
860 if (toupper1 (i
) != TOUPPER (i
))
861 printf("error %d\n", i
);
865 /* GCC accepts that */
866 static int tab_reinit
[];
867 static int tab_reinit
[10];
869 //int cinit1; /* a global variable can be defined several times without error ! */
873 int *cinit2
= (int []){3, 2, 1};
875 void compound_literal_test(void)
880 printf("compound_test:\n");
882 p
= (int []){1, 2, 3};
888 printf("%d", cinit2
[i
]);
892 printf("q1=%s\n", q
);
894 q
= (char *){ "tralala2" };
895 printf("q2=%s\n", q
);
898 printf("q3=%s\n", q3
);
900 q
= (char []){ "tralala3" };
901 printf("q4=%s\n", q
);
904 p
= (int []){1, 2, cinit1
+ 3};
910 p
= (int []){1, 2, 4 + i
};
933 printf("kr_test:\n");
934 printf("func1=%d\n", kr_func1(3, 4));
935 printf("func2=%d\n", kr_func2(3, 4));
942 tab
= (char*)malloc(20);
958 /* structure assignment tests */
964 struct structa1 ssta1
;
966 void struct_assign_test1(struct structa1 s1
, int t
)
968 printf("%d %d %d\n", s1
.f1
, s1
.f2
, t
);
971 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
978 void struct_assign_test(void)
980 struct structa1 lsta1
, lsta2
;
983 printf("struct_assign_test:\n");
987 printf("%d %d\n", lsta1
.f1
, lsta1
.f2
);
989 printf("%d %d\n", lsta2
.f1
, lsta2
.f2
);
994 struct_assign_test1(lsta2
, 3);
996 printf("before call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
997 lsta2
= struct_assign_test2(lsta2
, 4);
998 printf("after call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1001 /* casts to short/char */
1003 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
1005 printf("%d %d %d %d\n", a
, b
, c
, d
);
1017 printf("cast_test:\n");
1021 printf("%d %d %d %d\n",
1024 (unsigned char)(a
+ 1),
1025 (unsigned short)(a
+ 1));
1026 printf("%d %d %d %d\n",
1029 (unsigned char)0xfffff,
1030 (unsigned short)0xfffff);
1032 a
= (bcast
= 128) + 1;
1034 a
= (scast
= 65536) + 1;
1037 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1039 /* test implicit int casting for array accesses */
1043 printf("%d %d\n", tab
[0], tab
[1]);
1045 /* test implicit casting on some operators */
1046 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1047 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1048 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1051 /* initializers tests */
1052 struct structinit1
{
1061 int sinit3
[3] = { 1, 2, {{3}}, };
1062 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1063 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1064 int sinit6
[] = { 1, 2, 3 };
1065 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1066 char sinit8
[] = "hello" "trala";
1068 struct structinit1 sinit9
= { 1, 2, 3 };
1069 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1070 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1078 char *sinit12
= "hello world";
1084 char sinit14
[10] = { "abc" };
1085 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1087 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1103 void init_test(void)
1107 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1108 int linit6
[] = { 1, 2, 3 };
1110 char linit8
[] = "hello" "trala";
1111 int linit12
[10] = { 1, 2 };
1112 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1113 char linit14
[10] = "abc";
1114 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1115 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1116 int linit17
= sizeof(linit17
);
1118 printf("init_test:\n");
1120 printf("sinit1=%d\n", sinit1
);
1121 printf("sinit2=%d\n", sinit2
);
1122 printf("sinit3=%d %d %d %d\n",
1128 printf("sinit6=%d\n", sizeof(sinit6
));
1129 printf("sinit7=%d %d %d %d\n",
1135 printf("sinit8=%s\n", sinit8
);
1136 printf("sinit9=%d %d %d\n",
1141 printf("sinit10=%d %d %d\n",
1146 printf("sinit11=%d %d %d %d %d %d\n",
1157 printf("[%d][%d] = %d %d %d\n",
1158 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1159 printf("linit1=%d\n", linit1
);
1160 printf("linit2=%d\n", linit2
);
1161 printf("linit6=%d\n", sizeof(linit6
));
1162 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1164 printf("sinit12=%s\n", sinit12
);
1165 printf("sinit13=%d %s %s %s\n",
1170 printf("sinit14=%s\n", sinit14
);
1172 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1174 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1176 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1178 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1180 printf("%d %d %d %d\n",
1185 /* test that initialisation is done after variable declare */
1186 printf("linit17=%d\n", linit17
);
1187 printf("sinit15=%d\n", sinit15
[0]);
1188 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1189 printf("sinit17=%s %d %s %d\n",
1190 sinit17
[0].s
, sinit17
[0].len
,
1191 sinit17
[1].s
, sinit17
[1].len
);
1193 printf("%x ", sinit18
[i
]);
1222 /* ISOC99 _Bool type */
1223 void c99_bool_test(void)
1229 printf("bool_test:\n");
1230 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1232 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1234 printf("b = %d\n", b
);
1236 printf("b = %d\n", b
);
1240 void bitfield_test(void)
1250 unsigned int f5
: 7;
1252 printf("bitfield_test:");
1253 printf("sizeof(st1) = %d\n", sizeof(st1
));
1262 printf("%d %d %d %d %d\n",
1263 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1266 #define FTEST(prefix, type, fmt)\
1267 void prefix ## cmp(type a, type b)\
1269 printf("%d %d %d %d %d %d\n",\
1276 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1284 printf(fmt "\n", ++a);\
1285 printf(fmt "\n", a++);\
1286 printf(fmt "\n", a);\
1288 void prefix ## fcast(type a)\
1299 printf("ftof: %f %f %Lf\n", fa, da, la);\
1301 ua = (unsigned int)a;\
1302 printf("ftoi: %d %u\n", ia, ua);\
1306 printf("itof: " fmt "\n", b);\
1308 printf("utof: " fmt "\n", b);\
1311 void prefix ## test(void)\
1313 printf("testing '%s'\n", #type);\
1314 prefix ## cmp(1, 2.5);\
1315 prefix ## cmp(2, 1.5);\
1316 prefix ## cmp(1, 1);\
1317 prefix ## fcast(234.6);\
1318 prefix ## fcast(-2334.6);\
1321 FTEST(f
, float, "%f")
1322 FTEST(d
, double, "%f")
1323 FTEST(ld
, long double, "%Lf")
1325 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1328 void float_test(void)
1335 printf("float_test:\n");
1336 printf("sizeof(float) = %d\n", sizeof(float));
1337 printf("sizeof(double) = %d\n", sizeof(double));
1338 printf("sizeof(long double) = %d\n", sizeof(long double));
1342 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1343 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1344 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1346 printf("da=%f\n", da
);
1348 printf("fa=%f\n", fa
);
1351 printf("da = %f\n", da
);
1354 printf("db = %f\n", db
);
1362 return fib(n
-1) + fib(n
-2);
1374 printf("funcptr:\n");
1381 /* more complicated pointer computation */
1384 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1385 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1386 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1387 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1390 void lloptest(long long a
, long long b
)
1392 unsigned long long ua
, ub
;
1397 printf("arith: %Ld %Ld %Ld\n",
1403 printf("arith1: %Ld %Ld\n",
1409 printf("bin: %Ld %Ld %Ld\n",
1415 printf("test: %d %d %d %d %d %d\n",
1423 printf("utest: %d %d %d %d %d %d\n",
1434 printf("arith2: %Ld %Ld\n", a
, b
);
1435 printf("arith2: %Ld %Ld\n", a
++, b
++);
1436 printf("arith2: %Ld %Ld\n", --a
, --b
);
1437 printf("arith2: %Ld %Ld\n", a
, b
);
1440 void llshift(long long a
, int b
)
1442 printf("shift: %Ld %Ld %Ld\n",
1443 (unsigned long long)a
>> b
,
1446 printf("shiftc: %Ld %Ld %Ld\n",
1447 (unsigned long long)a
>> 3,
1450 printf("shiftc: %Ld %Ld %Ld\n",
1451 (unsigned long long)a
>> 35,
1461 long long la
, lb
, lc
;
1462 unsigned long long ula
, ulb
, ulc
;
1465 la
= (la
<< 20) | 0x12345;
1467 printf("la=%Ld ula=%Lu\n", la
, ula
);
1472 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1477 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1482 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1487 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1490 long long llfunc1(int a
)
1500 long long int value(struct S
*v
)
1502 return ((long long int)v
->item
);
1505 void longlong_test(void)
1510 printf("longlong_test:\n");
1511 printf("sizeof(long long) = %d\n", sizeof(long long));
1516 printf("%Ld %Ld\n", a
, b
);
1517 printf("%Ld %Ld %Ld %Lx\n",
1521 0x1234567812345679);
1526 lloptest(0xff, 0x1234);
1527 b
= 0x72345678 << 10;
1531 b
= 0x72345678LL
<< 10;
1542 /* long long reg spill test */
1547 printf("%lld\n", value(&a
));
1549 lloptest(0x80000000, 0);
1552 void vprintf1(const char *fmt
, ...)
1574 i
= va_arg(ap
, int);
1578 d
= va_arg(ap
, double);
1582 ll
= va_arg(ap
, long long);
1596 void stdarg_test(void)
1598 vprintf1("%d %d %d\n", 1, 2, 3);
1599 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1600 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1603 void whitespace_test(void)
1609 ntf("whitspace:\n");\f\v
1613 #ifdef CORRECT_CR_HANDLING
1621 printf("len1=%d\n", strlen("
1623 #ifdef CORRECT_CR_HANDLING
1626 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
1628 printf("len1=%d\n", strlen("
a
1632 int reltab
[3] = { 1, 2, 3 };
1634 int *rel1
= &reltab
[1];
1635 int *rel2
= &reltab
[2];
1637 void relocation_test(void)
1639 printf("*rel1=%d\n", *rel1
);
1640 printf("*rel2=%d\n", *rel2
);
1643 void old_style_f(a
,b
,c
)
1647 printf("a=%d b=%d b=%f\n", a
, b
, c
);
1650 void old_style_function(void)
1652 old_style_f((void *)1, 2, 3.0);
1655 void sizeof_test(void)
1660 printf("sizeof(int) = %d\n", sizeof(int));
1661 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
1662 printf("sizeof(short) = %d\n", sizeof(short));
1663 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
1664 printf("sizeof(char) = %d\n", sizeof(char));
1665 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
1666 printf("sizeof(func) = %d\n", sizeof sizeof_test());
1668 printf("sizeof(a++) = %d\n", sizeof a
++);
1669 printf("a=%d\n", a
);
1671 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
1673 /* some alignof tests */
1674 printf("__alignof__(int) = %d\n", __alignof__(int));
1675 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
1676 printf("__alignof__(short) = %d\n", __alignof__(short));
1677 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
1678 printf("__alignof__(char) = %d\n", __alignof__(char));
1679 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
1680 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
1683 void typeof_test(void)
1692 printf("a=%f b=%f c=%f\n", a
, b
, c
);
1695 void statement_expr_test(void)
1708 printf("a=%d\n", a
);
1712 void local_label_test(void)
1718 __label__ l1
, l2
, l3
;
1732 printf("a=%d\n", a
);
1742 /* inline assembler test */
1745 /* from linux kernel */
1746 static char * strncat1(char * dest
,const char * src
,size_t count
)
1749 __asm__
__volatile__(
1758 "testb %%al,%%al\n\t"
1760 "2:\txorl %2,%2\n\t"
1762 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
1763 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
1768 static inline void * memcpy1(void * to
, const void * from
, size_t n
)
1771 __asm__
__volatile__(
1776 "1:\ttestb $1,%b4\n\t"
1780 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
1781 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
1786 static __inline__
void sigaddset1(unsigned int *set
, int _sig
)
1788 __asm__("btsl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
1791 static __inline__
void sigdelset1(unsigned int *set
, int _sig
)
1793 asm("btrl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
1796 static __inline__ __const__
unsigned int swab32(unsigned int x
)
1798 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
1799 "rorl $16,%0\n\t" /* swap words */
1800 "xchgb %b0,%h0" /* swap higher bytes */
1813 printf("inline asm:\n");
1814 memcpy1(buf
, "hello", 6);
1815 strncat1(buf
, " worldXXXXX", 3);
1816 printf("%s\n", buf
);
1819 sigdelset1(&set
, 2);
1820 sigaddset1(&set
, 16);
1821 /* NOTE: we test here if C labels are correctly restored after the
1825 __asm__("btsl %1,%0" : "=m"(set
) : "Ir"(20) : "cc");
1826 printf("set=0x%x\n", set
);
1828 printf("swab32(0x%08x) = 0x%0x\n", val
, swab32(val
));