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 static int onetwothree
= 123;
107 #define onetwothree4 onetwothree
108 #define onetwothree xglue(onetwothree,4)
110 #define min(a, b) ((a) < (b) ? (a) : (b))
113 #define dprintf(level,...) printf(__VA_ARGS__)
116 /* gcc vararg macros */
117 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
119 #define MACRO_NOARGS()
135 #define __INT64_C(c) c ## LL
136 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
144 #define spin_lock(lock) do { } while (0)
145 #define wq_spin_lock spin_lock
146 #define TEST2() wq_spin_lock(a)
148 void macro_test(void)
150 printf("macro:\n");\f\v
152 printf("aaa=%d\n", AAA
);
154 printf("min=%d\n", min(1, min(2, -1)));
156 printf("s1=%s\n", glue(HIGH
, LOW
));
157 printf("s2=%s\n", xglue(HIGH
, LOW
));
158 printf("s3=%s\n", str("c"));
159 printf("s4=%s\n", str(a1
));
160 printf("B3=%d\n", B3
);
162 printf("onetwothree=%d\n", onetwothree
);
165 printf("A defined\n");
168 printf("B defined\n");
171 printf("A defined\n");
173 printf("A not defined\n");
176 printf("B defined\n");
178 printf("B not defined\n");
182 printf("A defined\n");
184 printf("B1 defined\n");
186 printf("B1 not defined\n");
189 printf("A not defined\n");
191 printf("B2 defined\n");
193 printf("B2 not defined\n");
198 printf("test true1\n");
201 printf("test true2\n");
204 printf("test true3\n");
207 printf("test trueA\n");
210 printf("test trueB\n");
226 printf("__LINE__ defined\n");
229 printf("__LINE__=%d __FILE__=%s\n",
232 printf("__LINE__=%d __FILE__=%s\n",
235 printf("__LINE__=%d __FILE__=%s\n",
237 #line 227 "tcctest.c"
239 /* not strictly preprocessor, but we test it there */
241 printf("__func__ = %s\n", __func__
);
242 dprintf(1, "vaarg=%d\n", 1);
244 dprintf1(1, "vaarg1\n");
245 dprintf1(1, "vaarg1=%d\n", 2);
246 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
249 printf("func='%s'\n", __FUNCTION__
);
251 /* complicated macros in glibc */
252 printf("INT64_MIN=%Ld\n", INT64_MIN
);
262 /* macro function with argument outside the macro string */
263 #define MF_s MF_hello
264 #define MF_hello(msg) printf("%s\n",msg)
266 #define MF_t printf("tralala\n"); MF_hello
271 /* test macro substituion inside args (should not eat stream) */
272 printf("qq=%d\n", qq(qq
)(2));
274 /* test zero argument case. NOTE: gcc 2.95.x does not accept a
275 null argument without a space. gcc 3.2 fixes that. */
278 printf("qq1=%d\n", qq1( ));
280 /* comment with stray handling *\
282 /* this is a valid *\/ comment */
283 /* this is a valid comment *\*/
287 /* test function macro substitution when the function name is
293 static void print_num(char *fn
, int line
, int num
) {
294 printf("fn %s, line %d, num %d\n", fn
, line
, num
);
297 void recursive_macro_test(void)
300 #define ELF32_ST_TYPE(val) ((val) & 0xf)
301 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
302 #define STB_WEAK 2 /* Weak symbol */
303 #define ELFW(type) ELF##32##_##type
304 printf("%d\n", ELFW(ST_INFO
)(STB_WEAK
, ELFW(ST_TYPE
)(123)));
308 #define print_num(x) print_num(__FILE__,__LINE__,x)
310 WRAP(print_num(123));
311 WRAP(WRAP(print_num(123)));
313 static struct recursive_macro
{ int rm_field
; } G
;
314 #define rm_field (G.rm_field)
315 printf("rm_field = %d\n", rm_field
);
316 printf("rm_field = %d\n", WRAP(rm_field
));
317 WRAP((printf("rm_field = %d %d\n", rm_field
, WRAP(rm_field
))));
334 void ps(const char *s
)
346 const char foo1_string
[] = "\
355 printf("\141\1423\143\n");/* dezdez test */
356 printf("\x41\x42\x43\x3a\n");
357 printf("c=%c\n", 'r');
358 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
359 printf("foo1_string='%s'\n", foo1_string
);
361 printf("wstring=%S\n", L
"abc");
362 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
363 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
364 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
368 while ((b
= b
+ 1) < 96) {
372 printf("fib=%d\n", fib(33));
374 while (b
!= 0x80000000) {
387 for(i
= 0; i
< 10;i
++)
397 /* c99 for loop init test */
398 for (size_t count
= 1; count
< 3; count
++)
399 printf("count=%d\n", count
);
400 printf("count = %d\n", count
);
402 /* break/continue tests */
414 /* break/continue tests */
426 for(i
= 0;i
< 10;i
++) {
438 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
451 /* we also test computed gotos (GCC extension) */
453 goto *label_table
[i
];
481 printf("enum:\n%d %d %d %d %d %d\n",
482 E0
, E1
, E2
, E3
, E4
, E5
);
484 printf("b1=%d\n", b1
);
500 printf("typedef:\n");
501 printf("a=%d\n", *a
);
503 printf("mytype2=%d\n", mytype2
);
508 printf("forward:\n");
514 void forward_ref(void)
516 printf("forward ok\n");
519 typedef struct struct1
{
539 struct struct1 st1
, st2
;
541 int main(int argc
, char **argv
)
546 recursive_macro_test();
560 constant_expr_test();
564 compound_literal_test();
566 struct_assign_test();
576 old_style_function();
581 statement_expr_test();
596 printf("g1=%d\n", g
);
604 printf("g2=%d\n", g
);
608 printf("g3=%d\n", g
);
612 printf("g4=%d\n", g
);
615 printf("g5=%d\n", g
);
623 printf("sizeof(a) = %d\n", sizeof(a
));
624 printf("sizeof(\"a\") = %d\n", sizeof("a"));
626 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
628 printf("sizeof tab %d\n", sizeof(tab
));
629 printf("sizeof tab2 %d\n", sizeof tab2
);
633 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
636 tab2
[i
][j
] = 10 * i
+ j
;
638 printf(" %3d", ((int *)tab2
)[i
]);
641 printf("sizeof(size_t)=%d\n", sizeof(size_t));
642 printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
649 printf("%d\n", a
+= 1);
650 printf("%d\n", a
-= 2);
651 printf("%d\n", a
*= 31232132);
652 printf("%d\n", a
/= 4);
653 printf("%d\n", a
%= 20);
654 printf("%d\n", a
&= 6);
655 printf("%d\n", a
^= 7);
656 printf("%d\n", a
|= 8);
657 printf("%d\n", a
>>= 3);
658 printf("%d\n", a
<<= 4);
662 printf("%d\n", a
+ 1);
663 printf("%d\n", a
- 2);
664 printf("%d\n", a
* 312);
665 printf("%d\n", a
/ 4);
666 printf("%d\n", b
/ 4);
667 printf("%d\n", (unsigned)b
/ 4);
668 printf("%d\n", a
% 20);
669 printf("%d\n", b
% 20);
670 printf("%d\n", (unsigned)b
% 20);
671 printf("%d\n", a
& 6);
672 printf("%d\n", a
^ 7);
673 printf("%d\n", a
| 8);
674 printf("%d\n", a
>> 3);
675 printf("%d\n", b
>> 3);
676 printf("%d\n", (unsigned)b
>> 3);
677 printf("%d\n", a
<< 4);
682 printf("%d\n", 12 + 1);
683 printf("%d\n", 12 - 2);
684 printf("%d\n", 12 * 312);
685 printf("%d\n", 12 / 4);
686 printf("%d\n", 12 % 20);
687 printf("%d\n", 12 & 6);
688 printf("%d\n", 12 ^ 7);
689 printf("%d\n", 12 | 8);
690 printf("%d\n", 12 >> 2);
691 printf("%d\n", 12 << 4);
695 printf("%d %d %d %d\n",
704 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
707 /**********************/
709 int vstack
[10], *vstack_ptr
;
711 void vpush(int vt
, int vc
)
717 void vpop(int *ft
, int *fc
)
730 vstack_ptr
[-2] &= ~0xffffff80;
732 printf("res= %d %d\n", a
, b
);
735 void constant_expr_test()
738 printf("constant_expr:\n");
740 printf("%d\n", a
* 16);
741 printf("%d\n", a
* 1);
742 printf("%d\n", a
+ 0);
752 printf("expr_ptr:\n");
755 printf("diff=%d\n", q
- p
);
757 printf("inc=%d\n", p
- tab4
);
759 printf("dec=%d\n", p
- tab4
);
761 printf("inc=%d\n", p
- tab4
);
763 printf("dec=%d\n", p
- tab4
);
764 printf("add=%d\n", p
+ 3 - tab4
);
765 printf("add=%d\n", 3 + p
- tab4
);
767 /* check if 64bit support is ok */
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
);
775 printf("%p %p %ld\n", q
, p
, p
-q
);
776 printf("%d %d %d %d %d %d\n",
777 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
778 p
= (int *)((char *)p
+ 0xf0000000);
779 printf("%p %p %ld\n", q
, p
, p
-q
);
780 printf("%d %d %d %d %d %d\n",
781 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
783 printf("%p %p %ld\n", q
, p
, p
-q
);
784 printf("%d %d %d %d %d %d\n",
785 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
790 struct size12 s
[2], *sp
= s
;
795 printf("%d\n", sp
[j
].i
);
802 printf("constant_expr:\n");
805 printf("%d\n", a
== a
);
806 printf("%d\n", a
!= a
);
808 printf("%d\n", a
< b
);
809 printf("%d\n", a
<= b
);
810 printf("%d\n", a
<= a
);
811 printf("%d\n", b
>= a
);
812 printf("%d\n", a
>= a
);
813 printf("%d\n", b
> a
);
815 printf("%d\n", (unsigned)a
< b
);
816 printf("%d\n", (unsigned)a
<= b
);
817 printf("%d\n", (unsigned)a
<= a
);
818 printf("%d\n", (unsigned)b
>= a
);
819 printf("%d\n", (unsigned)a
>= a
);
820 printf("%d\n", (unsigned)b
> a
);
849 printf("sizes: %d %d %d %d\n",
850 sizeof(struct struct1
),
851 sizeof(struct struct2
),
852 sizeof(union union1
),
853 sizeof(union union2
));
857 printf("st1: %d %d %d\n",
858 st1
.f1
, st1
.f2
, st1
.f3
);
861 printf("union1: %d\n", st1
.u
.v1
);
864 printf("union2: %d\n", u
.w1
);
869 printf("st2: %d %d %d\n",
870 s
->f1
, s
->f2
, s
->f3
);
871 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
873 /* align / size tests */
874 printf("aligntest1 sizeof=%d alignof=%d\n",
875 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
876 printf("aligntest2 sizeof=%d alignof=%d\n",
877 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
878 printf("aligntest3 sizeof=%d alignof=%d\n",
879 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
880 printf("aligntest4 sizeof=%d alignof=%d\n",
881 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
883 /* empty structures (GCC extension) */
884 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
885 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
888 /* XXX: depend on endianness */
889 void char_short_test()
893 printf("char_short:\n");
898 *(char *)&var1
, *(char *)&var2
);
900 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
901 printf("s16=%d %d\n",
902 *(short *)&var1
, *(short *)&var2
);
903 printf("u16=%d %d\n",
904 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
905 printf("s32=%d %d\n",
906 *(int *)&var1
, *(int *)&var2
);
907 printf("u32=%d %d\n",
908 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
909 *(char *)&var1
= 0x08;
910 printf("var1=%x\n", var1
);
911 *(short *)&var1
= 0x0809;
912 printf("var1=%x\n", var1
);
913 *(int *)&var1
= 0x08090a0b;
914 printf("var1=%x\n", var1
);
927 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
928 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
930 static int toupper1(int a
)
937 int *s
, a
, b
, t
, f
, i
;
941 printf("!s=%d\n", !s
);
947 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
948 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
949 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
964 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
966 /* test register spilling */
969 a
= (a
+ b
) * ((a
< b
) ?
970 ((b
- a
) * (a
- b
)): a
+ b
);
973 /* test complex || or && expressions */
977 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
978 printf("r=%d\n", (t
|| f
) + (t
&& f
));
983 int aspect_native
= 65536;
984 double bfu_aspect
= 1.0;
986 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
987 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
988 printf("aspect=%d\n", aspect
);
992 /* test ? : GCC extension */
994 static int v1
= 34 ? : -1; /* constant case */
995 static int v2
= 0 ? : -1; /* constant case */
998 printf("%d %d\n", v1
, v2
);
999 printf("%d %d\n", a
- 30 ? : a
* 2, a
+ 1 ? : a
* 2);
1002 /* again complex expression */
1003 for(i
=0;i
<256;i
++) {
1004 if (toupper1 (i
) != TOUPPER (i
))
1005 printf("error %d\n", i
);
1009 /* GCC accepts that */
1010 static int tab_reinit
[];
1011 static int tab_reinit
[10];
1013 //int cinit1; /* a global variable can be defined several times without error ! */
1017 int *cinit2
= (int []){3, 2, 1};
1019 void compound_literal_test(void)
1024 printf("compound_test:\n");
1026 p
= (int []){1, 2, 3};
1028 printf(" %d", p
[i
]);
1032 printf("%d", cinit2
[i
]);
1036 printf("q1=%s\n", q
);
1038 q
= (char *){ "tralala2" };
1039 printf("q2=%s\n", q
);
1042 printf("q3=%s\n", q3
);
1044 q
= (char []){ "tralala3" };
1045 printf("q4=%s\n", q
);
1048 p
= (int []){1, 2, cinit1
+ 3};
1050 printf(" %d", p
[i
]);
1054 p
= (int []){1, 2, 4 + i
};
1055 printf("%d %d %d\n",
1077 printf("kr_test:\n");
1078 printf("func1=%d\n", kr_func1(3, 4));
1079 printf("func2=%d\n", kr_func2(3, 4));
1086 tab
= (char*)malloc(20);
1103 /* structure assignment tests */
1109 struct structa1 ssta1
;
1111 void struct_assign_test1(struct structa1 s1
, int t
, float f
)
1113 printf("%d %d %d %f\n", s1
.f1
, s1
.f2
, t
, f
);
1116 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
1123 void struct_assign_test(void)
1126 struct structa1 lsta1
, lsta2
;
1133 printf("struct_assign_test:\n");
1137 printf("%d %d\n", s
.lsta1
.f1
, s
.lsta1
.f2
);
1139 printf("%d %d\n", s
.lsta2
.f1
, s
.lsta2
.f2
);
1144 struct_assign_test1(ps
->lsta2
, 3, 4.5);
1146 printf("before call: %d %d\n", s
.lsta2
.f1
, s
.lsta2
.f2
);
1147 ps
->lsta2
= struct_assign_test2(ps
->lsta2
, ps
->i
);
1148 printf("after call: %d %d\n", ps
->lsta2
.f1
, ps
->lsta2
.f2
);
1153 /* XXX: we should allow this even without braces */
1154 { struct_assign_test
}
1156 printf("%d\n", struct_assign_test
== t
[0].elem
);
1159 /* casts to short/char */
1161 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
1163 printf("%d %d %d %d\n", a
, b
, c
, d
);
1177 p
-= 0x700000000042;
1179 printf("cast_test:\n");
1183 printf("%d %d %d %d\n",
1186 (unsigned char)(a
+ 1),
1187 (unsigned short)(a
+ 1));
1188 printf("%d %d %d %d\n",
1191 (unsigned char)0xfffff,
1192 (unsigned short)0xfffff);
1194 a
= (bcast
= 128) + 1;
1196 a
= (scast
= 65536) + 1;
1199 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1201 /* test cast from unsigned to signed short to int */
1204 printf("((unsigned)(short)0x%08x) = 0x%08x\n", b
, d
);
1207 printf("((unsigned)(char)0x%08x) = 0x%08x\n", b
, d
);
1209 /* test implicit int casting for array accesses */
1213 printf("%d %d\n", tab
[0], tab
[1]);
1215 /* test implicit casting on some operators */
1216 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1217 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1218 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1220 /* from pointer to integer types */
1221 printf("%d %d %ld %ld %lld %lld\n",
1222 (int)p
, (unsigned int)p
,
1223 (long)p
, (unsigned long)p
,
1224 (long long)p
, (unsigned long long)p
);
1226 /* from integers to pointers */
1227 printf("%p %p %p %p\n",
1228 (void *)a
, (void *)b
, (void *)c
, (void *)d
);
1231 /* initializers tests */
1232 struct structinit1
{
1241 int sinit3
[3] = { 1, 2, {{3}}, };
1242 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1243 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1244 int sinit6
[] = { 1, 2, 3 };
1245 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1246 char sinit8
[] = "hello" "trala";
1248 struct structinit1 sinit9
= { 1, 2, 3 };
1249 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1250 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1258 char *sinit12
= "hello world";
1264 char sinit14
[10] = { "abc" };
1265 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1267 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1283 struct complexinit0
{
1288 struct complexinit
{
1290 const struct complexinit0
*b
;
1293 const static struct complexinit cix
[] = {
1296 .b
= (const struct complexinit0
[]) {
1304 struct complexinit2
{
1309 struct complexinit2 cix20
;
1311 struct complexinit2 cix21
= {
1313 .b
= { 3001, 3002, 3003 }
1316 struct complexinit2 cix22
= {
1318 .b
= { 4001, 4002, 4003, 4004, 4005, 4006 }
1321 void init_test(void)
1325 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1326 int linit6
[] = { 1, 2, 3 };
1328 char linit8
[] = "hello" "trala";
1329 int linit12
[10] = { 1, 2 };
1330 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1331 char linit14
[10] = "abc";
1332 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1333 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1334 int linit17
= sizeof(linit17
);
1336 printf("init_test:\n");
1338 printf("sinit1=%d\n", sinit1
);
1339 printf("sinit2=%d\n", sinit2
);
1340 printf("sinit3=%d %d %d %d\n",
1346 printf("sinit6=%d\n", sizeof(sinit6
));
1347 printf("sinit7=%d %d %d %d\n",
1353 printf("sinit8=%s\n", sinit8
);
1354 printf("sinit9=%d %d %d\n",
1359 printf("sinit10=%d %d %d\n",
1364 printf("sinit11=%d %d %d %d %d %d\n",
1375 printf("[%d][%d] = %d %d %d\n",
1376 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1377 printf("linit1=%d\n", linit1
);
1378 printf("linit2=%d\n", linit2
);
1379 printf("linit6=%d\n", sizeof(linit6
));
1380 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1382 printf("sinit12=%s\n", sinit12
);
1383 printf("sinit13=%d %s %s %s\n",
1388 printf("sinit14=%s\n", sinit14
);
1390 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1392 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1394 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1396 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1398 printf("%d %d %d %d\n",
1403 /* test that initialisation is done after variable declare */
1404 printf("linit17=%d\n", linit17
);
1405 printf("sinit15=%d\n", sinit15
[0]);
1406 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1407 printf("sinit17=%s %d %s %d\n",
1408 sinit17
[0].s
, sinit17
[0].len
,
1409 sinit17
[1].s
, sinit17
[1].len
);
1411 printf("%x ", sinit18
[i
]);
1413 /* complex init check */
1414 printf("cix: %d %d %d %d %d %d %d\n",
1416 cix
[0].b
[0].a
, cix
[0].b
[0].b
,
1417 cix
[0].b
[1].a
, cix
[0].b
[1].b
,
1418 cix
[0].b
[2].a
, cix
[0].b
[2].b
);
1419 printf("cix2: %d %d\n", cix21
.b
[2], cix22
.b
[5]);
1420 printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20
, sizeof cix21
, sizeof cix22
);
1448 /* ISOC99 _Bool type */
1449 void c99_bool_test(void)
1455 printf("bool_test:\n");
1456 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1458 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1460 printf("b = %d\n", b
);
1462 printf("b = %d\n", b
);
1466 void bitfield_test(void)
1478 unsigned int f5
: 7;
1480 printf("bitfield_test:");
1481 printf("sizeof(st1) = %d\n", sizeof(st1
));
1490 printf("%d %d %d %d %d\n",
1491 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1494 printf("%d %d\n", sa
, ca
);
1498 printf("st1.f1 == -1\n");
1500 printf("st1.f1 != -1\n");
1502 printf("st1.f2 == -1\n");
1504 printf("st1.f2 != -1\n");
1506 /* bit sizes below must be bigger than 32 since GCC doesn't allow
1507 long-long bitfields whose size is not bigger than int */
1512 unsigned long long f3
: 38;
1514 st2
.f1
= 0x123456789ULL
;
1516 st2
.f2
= (long long)a
<< 25;
1519 printf("%lld %lld %lld\n", st2
.f1
, st2
.f2
, st2
.f3
);
1523 #define FLOAT_FMT "%f\n"
1525 /* x86's float isn't compatible with GCC */
1526 #define FLOAT_FMT "%.5f\n"
1529 /* declare strto* functions as they are C99 */
1530 double strtod(const char *nptr
, char **endptr
);
1531 float strtof(const char *nptr
, char **endptr
);
1532 long double strtold(const char *nptr
, char **endptr
);
1534 #define FTEST(prefix, type, fmt)\
1535 void prefix ## cmp(type a, type b)\
1537 printf("%d %d %d %d %d %d\n",\
1544 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1552 printf(fmt "\n", ++a);\
1553 printf(fmt "\n", a++);\
1554 printf(fmt "\n", a);\
1556 printf("%d %d\n", !a, !b);\
1558 void prefix ## fcast(type a)\
1569 printf("ftof: %f %f %Lf\n", fa, da, la);\
1571 ua = (unsigned int)a;\
1572 printf("ftoi: %d %u\n", ia, ua);\
1576 printf("itof: " fmt "\n", b);\
1578 printf("utof: " fmt "\n", b);\
1581 float prefix ## retf(type a) { return a; }\
1582 double prefix ## retd(type a) { return a; }\
1583 long double prefix ## retld(type a) { return a; }\
1585 void prefix ## call(void)\
1587 printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
1588 printf("double: %f\n", prefix ## retd(42.123456789));\
1589 printf("long double: %Lf\n", prefix ## retld(42.123456789));\
1590 printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\
1593 void prefix ## test(void)\
1595 printf("testing '%s'\n", #type);\
1596 prefix ## cmp(1, 2.5);\
1597 prefix ## cmp(2, 1.5);\
1598 prefix ## cmp(1, 1);\
1599 prefix ## fcast(234.6);\
1600 prefix ## fcast(-2334.6);\
1604 FTEST(f
, float, "%f")
1605 FTEST(d
, double, "%f")
1606 FTEST(ld
, long double, "%Lf")
1608 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1611 void float_test(void)
1618 printf("float_test:\n");
1619 printf("sizeof(float) = %d\n", sizeof(float));
1620 printf("sizeof(double) = %d\n", sizeof(double));
1621 printf("sizeof(long double) = %d\n", sizeof(long double));
1625 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1626 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1627 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1629 printf("da=%f\n", da
);
1631 printf("fa=%f\n", fa
);
1634 printf("da = %f\n", da
);
1637 printf("db = %f\n", db
);
1645 return fib(n
-1) + fib(n
-2);
1657 printf("funcptr:\n");
1664 /* more complicated pointer computation */
1667 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1668 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1669 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1670 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1673 void lloptest(long long a
, long long b
)
1675 unsigned long long ua
, ub
;
1680 printf("arith: %Ld %Ld %Ld\n",
1686 printf("arith1: %Ld %Ld\n",
1692 printf("bin: %Ld %Ld %Ld\n",
1698 printf("test: %d %d %d %d %d %d\n",
1706 printf("utest: %d %d %d %d %d %d\n",
1717 printf("arith2: %Ld %Ld\n", a
, b
);
1718 printf("arith2: %Ld %Ld\n", a
++, b
++);
1719 printf("arith2: %Ld %Ld\n", --a
, --b
);
1720 printf("arith2: %Ld %Ld\n", a
, b
);
1722 printf("not: %d %d %d %d\n", !a
, !ua
, !b
, !ub
);
1725 void llshift(long long a
, int b
)
1727 printf("shift: %Ld %Ld %Ld\n",
1728 (unsigned long long)a
>> b
,
1731 printf("shiftc: %Ld %Ld %Ld\n",
1732 (unsigned long long)a
>> 3,
1735 printf("shiftc: %Ld %Ld %Ld\n",
1736 (unsigned long long)a
>> 35,
1746 long long la
, lb
, lc
;
1747 unsigned long long ula
, ulb
, ulc
;
1750 la
= (la
<< 20) | 0x12345;
1752 printf("la=%Ld ula=%Lu\n", la
, ula
);
1757 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1762 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1767 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1772 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1775 long long llfunc1(int a
)
1785 long long int value(struct S
*v
)
1787 return ((long long int)v
->item
);
1790 void longlong_test(void)
1795 printf("longlong_test:\n");
1796 printf("sizeof(long long) = %d\n", sizeof(long long));
1801 printf("%Ld %Ld\n", a
, b
);
1802 printf("%Ld %Ld %Ld %Lx\n",
1806 0x1234567812345679);
1811 lloptest(0xff, 0x1234);
1812 b
= 0x72345678 << 10;
1816 b
= 0x72345678LL
<< 10;
1827 /* long long reg spill test */
1832 printf("%lld\n", value(&a
));
1834 lloptest(0x80000000, 0);
1836 /* another long long spill test */
1842 printf("%lld\n", *p
);
1847 printf("%d %d %d %d\n", a
> b
, a
< b
, a
>= b
, a
<= b
);
1849 printf("%Ld\n", 0x123456789LLU
);
1852 void manyarg_test(void)
1854 long double ld
= 1234567891234LL;
1855 printf("manyarg_test:\n");
1856 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1857 1, 2, 3, 4, 5, 6, 7, 8,
1858 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1859 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1861 1, 2, 3, 4, 5, 6, 7, 8,
1862 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1863 1234567891234LL, 987654321986LL,
1865 printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1867 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1868 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1869 1234567891234LL, 987654321986LL,
1871 /* XXX: known bug of x86-64 */
1873 printf("%d %d %d %d %d %d %d %d %Lf\n",
1874 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1875 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1876 "%Ld %Ld %f %f %Lf\n",
1877 1, 2, 3, 4, 5, 6, 7, 8,
1878 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1879 1234567891234LL, 987654321986LL,
1881 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1882 "%Lf %Ld %Ld %f %f %Lf\n",
1883 1, 2, 3, 4, 5, 6, 7, 8,
1884 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1885 ld
, 1234567891234LL, 987654321986LL,
1890 void vprintf1(const char *fmt
, ...)
1914 i
= va_arg(ap
, int);
1918 d
= va_arg(ap
, double);
1922 ll
= va_arg(ap
, long long);
1926 ld
= va_arg(ap
, long double);
1944 void stdarg_for_struct(struct myspace bob
, ...)
1946 struct myspace george
, bill
;
1951 bill
= va_arg(ap
, struct myspace
);
1952 george
= va_arg(ap
, struct myspace
);
1953 validate
= va_arg(ap
, int);
1954 printf("stdarg_for_struct: %d %d %d %d\n",
1955 bob
.profile
, bill
.profile
, george
.profile
, validate
);
1959 void stdarg_test(void)
1961 long double ld
= 1234567891234LL;
1964 vprintf1("%d %d %d\n", 1, 2, 3);
1965 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1966 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1967 vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
1969 /* a bug of x86's TCC */
1970 vprintf1("%d %f %l %F %d %f %l %F\n",
1971 1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
1973 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1974 1, 2, 3, 4, 5, 6, 7, 8,
1975 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
1976 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
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 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1981 1, 2, 3, 4, 5, 6, 7, 8,
1982 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1983 1234567891234LL, 987654321986LL,
1985 vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1987 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1988 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1989 1234567891234LL, 987654321986LL,
1991 vprintf1("%d %d %d %d %d %d %d %d %F\n",
1992 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1993 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1995 1, 2, 3, 4, 5, 6, 7, 8,
1996 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1997 1234567891234LL, 987654321986LL,
1999 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
2000 "%F %l %l %f %f %F\n",
2001 1, 2, 3, 4, 5, 6, 7, 8,
2002 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
2003 ld
, 1234567891234LL, 987654321986LL,
2007 stdarg_for_struct(bob
, bob
, bob
, bob
.profile
);
2010 void whitespace_test(void)
2016 ntf("whitspace:\n");\f\v
2020 #ifdef CORRECT_CR_HANDLING
2029 #ifdef ACCEPT_CR_IN_STRINGS
2030 printf("len1=%d\n", strlen("
2032 #ifdef CORRECT_CR_HANDLING
2035 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
2037 printf("len1=%d\n", strlen("
a
2039 #endif /* ACCEPT_CR_IN_STRINGS */
2042 int reltab
[3] = { 1, 2, 3 };
2044 int *rel1
= &reltab
[1];
2045 int *rel2
= &reltab
[2];
2047 void relocation_test(void)
2049 printf("*rel1=%d\n", *rel1
);
2050 printf("*rel2=%d\n", *rel2
);
2053 void old_style_f(a
,b
,c
)
2057 printf("a=%d b=%d b=%f\n", a
, b
, c
);
2060 void decl_func1(int cmpfn())
2062 printf("cmpfn=%lx\n", (long)cmpfn
);
2065 void decl_func2(cmpfn
)
2068 printf("cmpfn=%lx\n", (long)cmpfn
);
2071 void old_style_function(void)
2073 old_style_f((void *)1, 2, 3.0);
2080 #if defined __i386__ || defined __x86_64__
2081 char *p
= alloca(16);
2082 strcpy(p
,"123456789012345");
2083 printf("alloca: p is %s\n", p
);
2084 char *demo
= "This is only a test.\n";
2085 /* Test alloca embedded in a larger expression */
2086 printf("alloca: %s\n", strcpy(alloca(strlen(demo
)+1),demo
) );
2090 void *bounds_checking_is_enabled()
2092 char ca
[10], *cp
= ca
-1;
2093 return (ca
!= cp
+ 1) ? cp
: NULL
;
2096 typedef int constant_negative_array_size_as_compile_time_assertion_idiom
[(1 ? 2 : 0) - 1];
2098 void c99_vla_test(int size1
, int size2
)
2100 #if defined __i386__ || defined __x86_64__
2101 int size
= size1
* size2
;
2102 int tab1
[size
][2], tab2
[10][2];
2103 void *tab1_ptr
, *tab2_ptr
, *bad_ptr
;
2105 /* "size" should have been 'captured' at tab1 declaration,
2106 so modifying it should have no effect on VLA behaviour. */
2109 printf("Test C99 VLA 1 (sizeof): ");
2110 printf("%s\n", (sizeof tab1
== size1
* size2
* 2 * sizeof(int)) ? "PASSED" : "FAILED");
2113 printf("Test C99 VLA 2 (ptrs substract): ");
2114 printf("%s\n", (tab2
- tab1
== (tab2_ptr
- tab1_ptr
) / (sizeof(int) * 2)) ? "PASSED" : "FAILED");
2115 printf("Test C99 VLA 3 (ptr add): ");
2116 printf("%s\n", &tab1
[5][1] == (tab1_ptr
+ (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED");
2117 printf("Test C99 VLA 4 (ptr access): ");
2118 tab1
[size1
][1] = 42;
2119 printf("%s\n", (*((int *) (tab1_ptr
+ (size1
* 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED");
2121 printf("Test C99 VLA 5 (bounds checking (might be disabled)): ");
2122 if (bad_ptr
= bounds_checking_is_enabled()) {
2123 int *t1
= &tab1
[size1
* size2
- 1][3];
2124 int *t2
= &tab2
[9][3];
2125 printf("%s ", bad_ptr
== t1
? "PASSED" : "FAILED");
2126 printf("%s ", bad_ptr
== t2
? "PASSED" : "FAILED");
2128 char*c1
= 1 + sizeof(tab1
) + (char*)tab1
;
2129 char*c2
= 1 + sizeof(tab2
) + (char*)tab2
;
2130 printf("%s ", bad_ptr
== c1
? "PASSED" : "FAILED");
2131 printf("%s ", bad_ptr
== c2
? "PASSED" : "FAILED");
2135 printf("%s ", bad_ptr
== i1
? "PASSED" : "FAILED");
2136 printf("%s ", bad_ptr
== i2
? "PASSED" : "FAILED");
2138 int *x1
= tab1
[size1
* size2
+ 1];
2139 int *x2
= tab2
[10 + 1];
2140 printf("%s ", bad_ptr
== x1
? "PASSED" : "FAILED");
2141 printf("%s ", bad_ptr
== x2
? "PASSED" : "FAILED");
2143 printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED ");
2149 void sizeof_test(void)
2154 printf("sizeof(int) = %d\n", sizeof(int));
2155 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
2156 printf("sizeof(long) = %d\n", sizeof(long));
2157 printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
2158 printf("sizeof(short) = %d\n", sizeof(short));
2159 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
2160 printf("sizeof(char) = %d\n", sizeof(char));
2161 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
2162 printf("sizeof(func) = %d\n", sizeof sizeof_test());
2164 printf("sizeof(a++) = %d\n", sizeof a
++);
2165 printf("a=%d\n", a
);
2167 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
2169 /* some alignof tests */
2170 printf("__alignof__(int) = %d\n", __alignof__(int));
2171 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
2172 printf("__alignof__(short) = %d\n", __alignof__(short));
2173 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
2174 printf("__alignof__(char) = %d\n", __alignof__(char));
2175 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
2176 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
2179 void typeof_test(void)
2188 printf("a=%f b=%f c=%f\n", a
, b
, c
);
2191 void statement_expr_test(void)
2204 printf("a=%d\n", a
);
2208 void local_label_test(void)
2214 __label__ l1
, l2
, l3
, l4
;
2228 printf("a=%d\n", a
);
2238 /* inline assembler test */
2241 /* from linux kernel */
2242 static char * strncat1(char * dest
,const char * src
,size_t count
)
2245 __asm__
__volatile__(
2254 "testb %%al,%%al\n\t"
2256 "2:\txorl %2,%2\n\t"
2258 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2259 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2264 static char * strncat2(char * dest
,const char * src
,size_t count
)
2267 __asm__
__volatile__(
2268 "repne scasb\n\t" /* one-line repne prefix + string op */
2275 "testb %%al,%%al\n\t"
2277 "2:\txorl %2,%2\n\t"
2279 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2280 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2285 static inline void * memcpy1(void * to
, const void * from
, size_t n
)
2288 __asm__
__volatile__(
2293 "1:\ttestb $1,%b4\n\t"
2297 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2298 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2303 static inline void * memcpy2(void * to
, const void * from
, size_t n
)
2306 __asm__
__volatile__(
2307 "rep movsl\n\t" /* one-line rep prefix + string op */
2311 "1:\ttestb $1,%b4\n\t"
2315 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2316 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2321 static __inline__
void sigaddset1(unsigned int *set
, int _sig
)
2323 __asm__("btsl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2326 static __inline__
void sigdelset1(unsigned int *set
, int _sig
)
2328 asm("btrl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2331 static __inline__ __const__
unsigned int swab32(unsigned int x
)
2333 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
2334 "rorl $16,%0\n\t" /* swap words */
2335 "xchgb %b0,%h0" /* swap higher bytes */
2341 static __inline__
unsigned long long mul64(unsigned int a
, unsigned int b
)
2343 unsigned long long res
;
2344 __asm__("mull %2" : "=A" (res
) : "a" (a
), "r" (b
));
2348 static __inline__
unsigned long long inc64(unsigned long long a
)
2350 unsigned long long res
;
2351 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res
) : "A" (a
));
2362 printf("inline asm:\n");
2363 /* test the no operand case */
2364 asm volatile ("xorl %eax, %eax");
2366 memcpy1(buf
, "hello", 6);
2367 strncat1(buf
, " worldXXXXX", 3);
2368 printf("%s\n", buf
);
2370 memcpy2(buf
, "hello", 6);
2371 strncat2(buf
, " worldXXXXX", 3);
2372 printf("%s\n", buf
);
2374 /* 'A' constraint test */
2375 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
2376 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
2379 sigdelset1(&set
, 2);
2380 sigaddset1(&set
, 16);
2381 /* NOTE: we test here if C labels are correctly restored after the
2385 __asm__("btsl %1,%0" : "=m"(set
) : "Ir"(20) : "cc");
2386 #ifdef __GNUC__ // works strange with GCC 4.3
2389 printf("set=0x%x\n", set
);
2391 printf("swab32(0x%08x) = 0x%0x\n", val
, swab32(val
));
2405 #define COMPAT_TYPE(type1, type2) \
2407 printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
2408 __builtin_types_compatible_p (type1, type2));\
2413 void builtin_test(void)
2416 COMPAT_TYPE(int, int);
2417 COMPAT_TYPE(int, unsigned int);
2418 COMPAT_TYPE(int, char);
2419 COMPAT_TYPE(int, const int);
2420 COMPAT_TYPE(int, volatile int);
2421 COMPAT_TYPE(int *, int *);
2422 COMPAT_TYPE(int *, void *);
2423 COMPAT_TYPE(int *, const int *);
2424 COMPAT_TYPE(char *, unsigned char *);
2425 /* space is needed because tcc preprocessor introduces a space between each token */
2426 COMPAT_TYPE(char * *, void *);
2428 printf("res = %d\n", __builtin_constant_p(1));
2429 printf("res = %d\n", __builtin_constant_p(1 + 2));
2430 printf("res = %d\n", __builtin_constant_p(&constant_p_var
));
2431 printf("res = %d\n", __builtin_constant_p(constant_p_var
));
2435 extern int __attribute__((weak
)) weak_f1(void);
2436 extern int __attribute__((weak
)) weak_f2(void);
2437 extern int weak_f3(void);
2438 extern int __attribute__((weak
)) weak_v1
;
2439 extern int __attribute__((weak
)) weak_v2
;
2442 extern int (*weak_fpa
)() __attribute__((weak
));
2443 extern int __attribute__((weak
)) (*weak_fpb
)();
2444 extern __attribute__((weak
)) int (*weak_fpc
)();
2446 extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak
));
2447 extern int __attribute((weak
)) weak_asm_f2(void) asm("weak_asm_f2x") ;
2448 extern int __attribute((weak
)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak
));
2449 extern int weak_asm_v1
asm("weak_asm_v1x") __attribute((weak
));
2450 extern int __attribute((weak
)) weak_asm_v2
asm("weak_asm_v2x") ;
2451 extern int __attribute((weak
)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak
));
2453 static const size_t dummy
= 0;
2454 extern __typeof(dummy
) weak_dummy1
__attribute__((weak
, alias("dummy")));
2455 extern __typeof(dummy
) __attribute__((weak
, alias("dummy"))) weak_dummy2
;
2456 extern __attribute__((weak
, alias("dummy"))) __typeof(dummy
) weak_dummy3
;
2458 int some_lib_func(void);
2459 int dummy_impl_of_slf(void) { return 444; }
2460 int some_lib_func(void) __attribute__((weak
, alias("dummy_impl_of_slf")));
2462 int weak_toolate() __attribute__((weak
));
2463 int weak_toolate() { return 0; }
2465 void __attribute__((weak
)) weak_test(void)
2467 printf("weak_f1=%d\n", weak_f1
? weak_f1() : 123);
2468 printf("weak_f2=%d\n", weak_f2
? weak_f2() : 123);
2469 printf("weak_f3=%d\n", weak_f3
? weak_f3() : 123);
2470 printf("weak_v1=%d\n",&weak_v1
? weak_v1
: 123);
2471 printf("weak_v2=%d\n",&weak_v2
? weak_v2
: 123);
2472 printf("weak_v3=%d\n",&weak_v3
? weak_v3
: 123);
2474 printf("weak_fpa=%d\n",&weak_fpa
? weak_fpa() : 123);
2475 printf("weak_fpb=%d\n",&weak_fpb
? weak_fpb() : 123);
2476 printf("weak_fpc=%d\n",&weak_fpc
? weak_fpc() : 123);
2478 printf("weak_asm_f1=%d\n", weak_asm_f1
!= NULL
);
2479 printf("weak_asm_f2=%d\n", weak_asm_f2
!= NULL
);
2480 printf("weak_asm_f3=%d\n", weak_asm_f3
!= NULL
);
2481 printf("weak_asm_v1=%d\n",&weak_asm_v1
!= NULL
);
2482 printf("weak_asm_v2=%d\n",&weak_asm_v2
!= NULL
);
2483 printf("weak_asm_v3=%d\n",&weak_asm_v3
!= NULL
);
2486 int __attribute__((weak
)) weak_f2() { return 222; }
2487 int __attribute__((weak
)) weak_f3() { return 333; }
2488 int __attribute__((weak
)) weak_v2
= 222;
2489 int __attribute__((weak
)) weak_v3
= 333;
2491 void const_func(const int a
)
2495 void const_warn_test(void)
2504 int getme (struct condstruct
*s
, int i
)
2506 int i1
= (i
== 0 ? 0 : s
)->i
;
2507 int i2
= (i
== 0 ? s
: 0)->i
;
2508 int i3
= (i
== 0 ? (void*)0 : s
)->i
;
2509 int i4
= (i
== 0 ? s
: (void*)0)->i
;
2510 return i1
+ i2
+ i3
+ i4
;