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)
293 #if 0 /* doesnt work yet */
294 #define ELF32_ST_TYPE(val) ((val) & 0xf)
295 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
296 #define STB_WEAK 2 /* Weak symbol */
297 #define ELFW(type) ELF##32##_##type
298 printf("%d\n", ELFW(ST_INFO
)(STB_WEAK
, ELFW(ST_TYPE
)(123)));
303 #define print_num(x) print_num(__FILE__,__LINE__,x)
305 WRAP(print_num(123));
306 WRAP(WRAP(print_num(123)));
308 static struct recursive_macro
{ int rm_field
; } G
;
309 #define rm_field (G.rm_field)
310 printf("rm_field = %d\n", rm_field
);
311 printf("rm_field = %d\n", WRAP(rm_field
));
312 WRAP((printf("rm_field = %d %d\n", rm_field
, WRAP(rm_field
))));
329 void ps(const char *s
)
341 const char foo1_string
[] = "\
350 printf("\141\1423\143\n");/* dezdez test */
351 printf("\x41\x42\x43\x3a\n");
352 printf("c=%c\n", 'r');
353 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
354 printf("foo1_string='%s'\n", foo1_string
);
356 printf("wstring=%S\n", L
"abc");
357 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
358 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
359 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
363 while ((b
= b
+ 1) < 96) {
367 printf("fib=%d\n", fib(33));
369 while (b
!= 0x80000000) {
382 for(i
= 0; i
< 10;i
++)
392 /* c99 for loop init test */
393 for (size_t count
= 1; count
< 3; count
++)
394 printf("count=%d\n", count
);
395 printf("count = %d\n", count
);
397 /* break/continue tests */
409 /* break/continue tests */
421 for(i
= 0;i
< 10;i
++) {
433 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
446 /* we also test computed gotos (GCC extension) */
448 goto *label_table
[i
];
476 printf("enum:\n%d %d %d %d %d %d\n",
477 E0
, E1
, E2
, E3
, E4
, E5
);
479 printf("b1=%d\n", b1
);
495 printf("typedef:\n");
496 printf("a=%d\n", *a
);
498 printf("mytype2=%d\n", mytype2
);
503 printf("forward:\n");
509 void forward_ref(void)
511 printf("forward ok\n");
514 typedef struct struct1
{
534 struct struct1 st1
, st2
;
536 int main(int argc
, char **argv
)
541 recursive_macro_test();
555 constant_expr_test();
559 compound_literal_test();
561 struct_assign_test();
571 old_style_function();
576 statement_expr_test();
591 printf("g1=%d\n", g
);
599 printf("g2=%d\n", g
);
603 printf("g3=%d\n", g
);
607 printf("g4=%d\n", g
);
610 printf("g5=%d\n", g
);
613 void array_test(int a
[4])
618 printf("sizeof(a) = %d\n", sizeof(a
));
619 printf("sizeof(\"a\") = %d\n", sizeof("a"));
621 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
623 printf("sizeof tab %d\n", sizeof(tab
));
624 printf("sizeof tab2 %d\n", sizeof tab2
);
628 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
631 tab2
[i
][j
] = 10 * i
+ j
;
633 printf(" %3d", ((int *)tab2
)[i
]);
636 printf("sizeof(size_t)=%d\n", sizeof(size_t));
637 printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
644 printf("%d\n", a
+= 1);
645 printf("%d\n", a
-= 2);
646 printf("%d\n", a
*= 31232132);
647 printf("%d\n", a
/= 4);
648 printf("%d\n", a
%= 20);
649 printf("%d\n", a
&= 6);
650 printf("%d\n", a
^= 7);
651 printf("%d\n", a
|= 8);
652 printf("%d\n", a
>>= 3);
653 printf("%d\n", a
<<= 4);
657 printf("%d\n", a
+ 1);
658 printf("%d\n", a
- 2);
659 printf("%d\n", a
* 312);
660 printf("%d\n", a
/ 4);
661 printf("%d\n", b
/ 4);
662 printf("%d\n", (unsigned)b
/ 4);
663 printf("%d\n", a
% 20);
664 printf("%d\n", b
% 20);
665 printf("%d\n", (unsigned)b
% 20);
666 printf("%d\n", a
& 6);
667 printf("%d\n", a
^ 7);
668 printf("%d\n", a
| 8);
669 printf("%d\n", a
>> 3);
670 printf("%d\n", b
>> 3);
671 printf("%d\n", (unsigned)b
>> 3);
672 printf("%d\n", a
<< 4);
677 printf("%d\n", 12 + 1);
678 printf("%d\n", 12 - 2);
679 printf("%d\n", 12 * 312);
680 printf("%d\n", 12 / 4);
681 printf("%d\n", 12 % 20);
682 printf("%d\n", 12 & 6);
683 printf("%d\n", 12 ^ 7);
684 printf("%d\n", 12 | 8);
685 printf("%d\n", 12 >> 2);
686 printf("%d\n", 12 << 4);
690 printf("%d %d %d %d\n",
699 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
702 /**********************/
704 int vstack
[10], *vstack_ptr
;
706 void vpush(int vt
, int vc
)
712 void vpop(int *ft
, int *fc
)
725 vstack_ptr
[-2] &= ~0xffffff80;
727 printf("res= %d %d\n", a
, b
);
730 void constant_expr_test()
733 printf("constant_expr:\n");
735 printf("%d\n", a
* 16);
736 printf("%d\n", a
* 1);
737 printf("%d\n", a
+ 0);
747 printf("expr_ptr:\n");
750 printf("diff=%d\n", q
- p
);
752 printf("inc=%d\n", p
- tab4
);
754 printf("dec=%d\n", p
- tab4
);
756 printf("inc=%d\n", p
- tab4
);
758 printf("dec=%d\n", p
- tab4
);
759 printf("add=%d\n", p
+ 3 - tab4
);
760 printf("add=%d\n", 3 + p
- tab4
);
762 /* check if 64bit support is ok */
765 printf("%p %p %ld\n", q
, p
, p
-q
);
766 printf("%d %d %d %d %d %d\n",
767 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
770 printf("%p %p %ld\n", q
, p
, p
-q
);
771 printf("%d %d %d %d %d %d\n",
772 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
773 p
= (int *)((char *)p
+ 0xf0000000);
774 printf("%p %p %ld\n", q
, p
, p
-q
);
775 printf("%d %d %d %d %d %d\n",
776 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
778 printf("%p %p %ld\n", q
, p
, p
-q
);
779 printf("%d %d %d %d %d %d\n",
780 p
== q
, p
!= q
, p
< q
, p
<= q
, p
>= q
, p
> q
);
785 struct size12 s
[2], *sp
= s
;
790 printf("%d\n", sp
[j
].i
);
797 printf("constant_expr:\n");
800 printf("%d\n", a
== a
);
801 printf("%d\n", a
!= a
);
803 printf("%d\n", a
< b
);
804 printf("%d\n", a
<= b
);
805 printf("%d\n", a
<= a
);
806 printf("%d\n", b
>= a
);
807 printf("%d\n", a
>= a
);
808 printf("%d\n", b
> a
);
810 printf("%d\n", (unsigned)a
< b
);
811 printf("%d\n", (unsigned)a
<= b
);
812 printf("%d\n", (unsigned)a
<= a
);
813 printf("%d\n", (unsigned)b
>= a
);
814 printf("%d\n", (unsigned)a
>= a
);
815 printf("%d\n", (unsigned)b
> a
);
844 printf("sizes: %d %d %d %d\n",
845 sizeof(struct struct1
),
846 sizeof(struct struct2
),
847 sizeof(union union1
),
848 sizeof(union union2
));
852 printf("st1: %d %d %d\n",
853 st1
.f1
, st1
.f2
, st1
.f3
);
856 printf("union1: %d\n", st1
.u
.v1
);
859 printf("union2: %d\n", u
.w1
);
864 printf("st2: %d %d %d\n",
865 s
->f1
, s
->f2
, s
->f3
);
866 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
868 /* align / size tests */
869 printf("aligntest1 sizeof=%d alignof=%d\n",
870 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
871 printf("aligntest2 sizeof=%d alignof=%d\n",
872 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
873 printf("aligntest3 sizeof=%d alignof=%d\n",
874 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
875 printf("aligntest4 sizeof=%d alignof=%d\n",
876 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
878 /* empty structures (GCC extension) */
879 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
880 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
883 /* XXX: depend on endianness */
884 void char_short_test()
888 printf("char_short:\n");
893 *(char *)&var1
, *(char *)&var2
);
895 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
896 printf("s16=%d %d\n",
897 *(short *)&var1
, *(short *)&var2
);
898 printf("u16=%d %d\n",
899 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
900 printf("s32=%d %d\n",
901 *(int *)&var1
, *(int *)&var2
);
902 printf("u32=%d %d\n",
903 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
904 *(char *)&var1
= 0x08;
905 printf("var1=%x\n", var1
);
906 *(short *)&var1
= 0x0809;
907 printf("var1=%x\n", var1
);
908 *(int *)&var1
= 0x08090a0b;
909 printf("var1=%x\n", var1
);
922 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
923 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
925 static int toupper1(int a
)
932 int *s
, a
, b
, t
, f
, i
;
936 printf("!s=%d\n", !s
);
942 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
943 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
944 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
959 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
961 /* test register spilling */
964 a
= (a
+ b
) * ((a
< b
) ?
965 ((b
- a
) * (a
- b
)): a
+ b
);
968 /* test complex || or && expressions */
972 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
973 printf("r=%d\n", (t
|| f
) + (t
&& f
));
978 int aspect_native
= 65536;
979 double bfu_aspect
= 1.0;
981 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
982 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
983 printf("aspect=%d\n", aspect
);
987 /* test ? : GCC extension */
989 static int v1
= 34 ? : -1; /* constant case */
990 static int v2
= 0 ? : -1; /* constant case */
993 printf("%d %d\n", v1
, v2
);
994 printf("%d %d\n", a
- 30 ? : a
* 2, a
+ 1 ? : a
* 2);
997 /* again complex expression */
999 if (toupper1 (i
) != TOUPPER (i
))
1000 printf("error %d\n", i
);
1004 /* GCC accepts that */
1005 static int tab_reinit
[];
1006 static int tab_reinit
[10];
1008 //int cinit1; /* a global variable can be defined several times without error ! */
1012 int *cinit2
= (int []){3, 2, 1};
1014 void compound_literal_test(void)
1019 printf("compound_test:\n");
1021 p
= (int []){1, 2, 3};
1023 printf(" %d", p
[i
]);
1027 printf("%d", cinit2
[i
]);
1031 printf("q1=%s\n", q
);
1033 q
= (char *){ "tralala2" };
1034 printf("q2=%s\n", q
);
1037 printf("q3=%s\n", q3
);
1039 q
= (char []){ "tralala3" };
1040 printf("q4=%s\n", q
);
1043 p
= (int []){1, 2, cinit1
+ 3};
1045 printf(" %d", p
[i
]);
1049 p
= (int []){1, 2, 4 + i
};
1050 printf("%d %d %d\n",
1072 printf("kr_test:\n");
1073 printf("func1=%d\n", kr_func1(3, 4));
1074 printf("func2=%d\n", kr_func2(3, 4));
1081 tab
= (char*)malloc(20);
1098 /* structure assignment tests */
1104 struct structa1 ssta1
;
1106 void struct_assign_test1(struct structa1 s1
, int t
, float f
)
1108 printf("%d %d %d %f\n", s1
.f1
, s1
.f2
, t
, f
);
1111 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
1118 void struct_assign_test(void)
1120 struct structa1 lsta1
, lsta2
;
1123 printf("struct_assign_test:\n");
1127 printf("%d %d\n", lsta1
.f1
, lsta1
.f2
);
1129 printf("%d %d\n", lsta2
.f1
, lsta2
.f2
);
1134 struct_assign_test1(lsta2
, 3, 4.5);
1136 printf("before call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1137 lsta2
= struct_assign_test2(lsta2
, 4);
1138 printf("after call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
1143 /* XXX: we should allow this even without braces */
1144 { struct_assign_test
}
1146 printf("%d\n", struct_assign_test
== t
[0].elem
);
1149 /* casts to short/char */
1151 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
1153 printf("%d %d %d %d\n", a
, b
, c
, d
);
1167 p
-= 0x700000000042;
1169 printf("cast_test:\n");
1173 printf("%d %d %d %d\n",
1176 (unsigned char)(a
+ 1),
1177 (unsigned short)(a
+ 1));
1178 printf("%d %d %d %d\n",
1181 (unsigned char)0xfffff,
1182 (unsigned short)0xfffff);
1184 a
= (bcast
= 128) + 1;
1186 a
= (scast
= 65536) + 1;
1189 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1191 /* test cast from unsigned to signed short to int */
1194 printf("((unsigned)(short)0x%08x) = 0x%08x\n", b
, d
);
1197 printf("((unsigned)(char)0x%08x) = 0x%08x\n", b
, d
);
1199 /* test implicit int casting for array accesses */
1203 printf("%d %d\n", tab
[0], tab
[1]);
1205 /* test implicit casting on some operators */
1206 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1207 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1208 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1210 /* from pointer to integer types */
1211 printf("%d %d %ld %ld %lld %lld\n",
1212 (int)p
, (unsigned int)p
,
1213 (long)p
, (unsigned long)p
,
1214 (long long)p
, (unsigned long long)p
);
1216 /* from integers to pointers */
1217 printf("%p %p %p %p\n",
1218 (void *)a
, (void *)b
, (void *)c
, (void *)d
);
1221 /* initializers tests */
1222 struct structinit1
{
1231 int sinit3
[3] = { 1, 2, {{3}}, };
1232 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1233 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1234 int sinit6
[] = { 1, 2, 3 };
1235 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1236 char sinit8
[] = "hello" "trala";
1238 struct structinit1 sinit9
= { 1, 2, 3 };
1239 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1240 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1248 char *sinit12
= "hello world";
1254 char sinit14
[10] = { "abc" };
1255 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1257 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1273 struct complexinit0
{
1278 struct complexinit
{
1280 const struct complexinit0
*b
;
1283 const static struct complexinit cix
[] = {
1286 .b
= (const struct complexinit0
[]) {
1294 struct complexinit2
{
1299 struct complexinit2 cix21
= {
1301 .b
= { 3001, 3002, 3003 }
1304 struct complexinit2 cix22
= {
1306 .b
= { 4001, 4002, 4003, 4004, 4005, 4006 }
1309 void init_test(void)
1313 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1314 int linit6
[] = { 1, 2, 3 };
1316 char linit8
[] = "hello" "trala";
1317 int linit12
[10] = { 1, 2 };
1318 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1319 char linit14
[10] = "abc";
1320 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1321 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1322 int linit17
= sizeof(linit17
);
1324 printf("init_test:\n");
1326 printf("sinit1=%d\n", sinit1
);
1327 printf("sinit2=%d\n", sinit2
);
1328 printf("sinit3=%d %d %d %d\n",
1334 printf("sinit6=%d\n", sizeof(sinit6
));
1335 printf("sinit7=%d %d %d %d\n",
1341 printf("sinit8=%s\n", sinit8
);
1342 printf("sinit9=%d %d %d\n",
1347 printf("sinit10=%d %d %d\n",
1352 printf("sinit11=%d %d %d %d %d %d\n",
1363 printf("[%d][%d] = %d %d %d\n",
1364 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1365 printf("linit1=%d\n", linit1
);
1366 printf("linit2=%d\n", linit2
);
1367 printf("linit6=%d\n", sizeof(linit6
));
1368 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1370 printf("sinit12=%s\n", sinit12
);
1371 printf("sinit13=%d %s %s %s\n",
1376 printf("sinit14=%s\n", sinit14
);
1378 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1380 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1382 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1384 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1386 printf("%d %d %d %d\n",
1391 /* test that initialisation is done after variable declare */
1392 printf("linit17=%d\n", linit17
);
1393 printf("sinit15=%d\n", sinit15
[0]);
1394 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1395 printf("sinit17=%s %d %s %d\n",
1396 sinit17
[0].s
, sinit17
[0].len
,
1397 sinit17
[1].s
, sinit17
[1].len
);
1399 printf("%x ", sinit18
[i
]);
1401 /* complex init check */
1402 printf("cix: %d %d %d %d %d %d %d\n",
1404 cix
[0].b
[0].a
, cix
[0].b
[0].b
,
1405 cix
[0].b
[1].a
, cix
[0].b
[1].b
,
1406 cix
[0].b
[2].a
, cix
[0].b
[2].b
);
1407 printf("cix2: %d %d\n", cix21
.b
[2], cix22
.b
[5]);
1408 printf("sizeof cix21 %d, sizeof cix22 %d\n", sizeof cix21
, sizeof cix22
);
1436 /* ISOC99 _Bool type */
1437 void c99_bool_test(void)
1443 printf("bool_test:\n");
1444 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1446 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1448 printf("b = %d\n", b
);
1450 printf("b = %d\n", b
);
1454 void bitfield_test(void)
1464 unsigned int f5
: 7;
1466 printf("bitfield_test:");
1467 printf("sizeof(st1) = %d\n", sizeof(st1
));
1476 printf("%d %d %d %d %d\n",
1477 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1481 printf("st1.f1 == -1\n");
1483 printf("st1.f1 != -1\n");
1485 printf("st1.f2 == -1\n");
1487 printf("st1.f2 != -1\n");
1489 /* bit sizes below must be bigger than 32 since GCC doesn't allow
1490 long-long bitfields whose size is not bigger than int */
1495 unsigned long long f3
: 38;
1497 st2
.f1
= 0x123456789ULL
;
1499 st2
.f2
= (long long)a
<< 25;
1502 printf("%lld %lld %lld\n", st2
.f1
, st2
.f2
, st2
.f3
);
1506 #define FLOAT_FMT "%f\n"
1508 /* x86's float isn't compatible with GCC */
1509 #define FLOAT_FMT "%.5f\n"
1512 /* declare strto* functions as they are C99 */
1513 double strtod(const char *nptr
, char **endptr
);
1514 float strtof(const char *nptr
, char **endptr
);
1515 long double strtold(const char *nptr
, char **endptr
);
1517 #define FTEST(prefix, type, fmt)\
1518 void prefix ## cmp(type a, type b)\
1520 printf("%d %d %d %d %d %d\n",\
1527 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1535 printf(fmt "\n", ++a);\
1536 printf(fmt "\n", a++);\
1537 printf(fmt "\n", a);\
1539 printf("%d %d\n", !a, !b);\
1541 void prefix ## fcast(type a)\
1552 printf("ftof: %f %f %Lf\n", fa, da, la);\
1554 ua = (unsigned int)a;\
1555 printf("ftoi: %d %u\n", ia, ua);\
1559 printf("itof: " fmt "\n", b);\
1561 printf("utof: " fmt "\n", b);\
1564 float prefix ## retf(type a) { return a; }\
1565 double prefix ## retd(type a) { return a; }\
1566 long double prefix ## retld(type a) { return a; }\
1568 void prefix ## call(void)\
1570 printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
1571 printf("double: %f\n", prefix ## retd(42.123456789));\
1572 printf("long double: %Lf\n", prefix ## retld(42.123456789));\
1573 printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\
1576 void prefix ## test(void)\
1578 printf("testing '%s'\n", #type);\
1579 prefix ## cmp(1, 2.5);\
1580 prefix ## cmp(2, 1.5);\
1581 prefix ## cmp(1, 1);\
1582 prefix ## fcast(234.6);\
1583 prefix ## fcast(-2334.6);\
1587 FTEST(f
, float, "%f")
1588 FTEST(d
, double, "%f")
1589 FTEST(ld
, long double, "%Lf")
1591 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1594 void float_test(void)
1601 printf("float_test:\n");
1602 printf("sizeof(float) = %d\n", sizeof(float));
1603 printf("sizeof(double) = %d\n", sizeof(double));
1604 printf("sizeof(long double) = %d\n", sizeof(long double));
1608 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1609 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1610 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1612 printf("da=%f\n", da
);
1614 printf("fa=%f\n", fa
);
1617 printf("da = %f\n", da
);
1620 printf("db = %f\n", db
);
1628 return fib(n
-1) + fib(n
-2);
1640 printf("funcptr:\n");
1647 /* more complicated pointer computation */
1650 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1651 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1652 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1653 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1656 void lloptest(long long a
, long long b
)
1658 unsigned long long ua
, ub
;
1663 printf("arith: %Ld %Ld %Ld\n",
1669 printf("arith1: %Ld %Ld\n",
1675 printf("bin: %Ld %Ld %Ld\n",
1681 printf("test: %d %d %d %d %d %d\n",
1689 printf("utest: %d %d %d %d %d %d\n",
1700 printf("arith2: %Ld %Ld\n", a
, b
);
1701 printf("arith2: %Ld %Ld\n", a
++, b
++);
1702 printf("arith2: %Ld %Ld\n", --a
, --b
);
1703 printf("arith2: %Ld %Ld\n", a
, b
);
1705 printf("not: %d %d %d %d\n", !a
, !ua
, !b
, !ub
);
1708 void llshift(long long a
, int b
)
1710 printf("shift: %Ld %Ld %Ld\n",
1711 (unsigned long long)a
>> b
,
1714 printf("shiftc: %Ld %Ld %Ld\n",
1715 (unsigned long long)a
>> 3,
1718 printf("shiftc: %Ld %Ld %Ld\n",
1719 (unsigned long long)a
>> 35,
1729 long long la
, lb
, lc
;
1730 unsigned long long ula
, ulb
, ulc
;
1733 la
= (la
<< 20) | 0x12345;
1735 printf("la=%Ld ula=%Lu\n", la
, ula
);
1740 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1745 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1750 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1755 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1758 long long llfunc1(int a
)
1768 long long int value(struct S
*v
)
1770 return ((long long int)v
->item
);
1773 void longlong_test(void)
1778 printf("longlong_test:\n");
1779 printf("sizeof(long long) = %d\n", sizeof(long long));
1784 printf("%Ld %Ld\n", a
, b
);
1785 printf("%Ld %Ld %Ld %Lx\n",
1789 0x1234567812345679);
1794 lloptest(0xff, 0x1234);
1795 b
= 0x72345678 << 10;
1799 b
= 0x72345678LL
<< 10;
1810 /* long long reg spill test */
1815 printf("%lld\n", value(&a
));
1817 lloptest(0x80000000, 0);
1819 /* another long long spill test */
1825 printf("%lld\n", *p
);
1830 printf("%d %d %d %d\n", a
> b
, a
< b
, a
>= b
, a
<= b
);
1832 printf("%Ld\n", 0x123456789LLU
);
1835 void manyarg_test(void)
1837 long double ld
= 1234567891234LL;
1838 printf("manyarg_test:\n");
1839 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1840 1, 2, 3, 4, 5, 6, 7, 8,
1841 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1842 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1844 1, 2, 3, 4, 5, 6, 7, 8,
1845 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1846 1234567891234LL, 987654321986LL,
1848 printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1850 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1851 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1852 1234567891234LL, 987654321986LL,
1854 /* XXX: known bug of x86-64 */
1856 printf("%d %d %d %d %d %d %d %d %Lf\n",
1857 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1858 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1859 "%Ld %Ld %f %f %Lf\n",
1860 1, 2, 3, 4, 5, 6, 7, 8,
1861 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1862 1234567891234LL, 987654321986LL,
1864 printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1865 "%Lf %Ld %Ld %f %f %Lf\n",
1866 1, 2, 3, 4, 5, 6, 7, 8,
1867 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1868 ld
, 1234567891234LL, 987654321986LL,
1873 void vprintf1(const char *fmt
, ...)
1897 i
= va_arg(ap
, int);
1901 d
= va_arg(ap
, double);
1905 ll
= va_arg(ap
, long long);
1909 ld
= va_arg(ap
, long double);
1927 void stdarg_for_struct(struct myspace bob
, ...)
1929 struct myspace george
, bill
;
1934 bill
= va_arg(ap
, struct myspace
);
1935 george
= va_arg(ap
, struct myspace
);
1936 validate
= va_arg(ap
, int);
1937 printf("stdarg_for_struct: %d %d %d %d\n",
1938 bob
.profile
, bill
.profile
, george
.profile
, validate
);
1942 void stdarg_test(void)
1944 long double ld
= 1234567891234LL;
1947 vprintf1("%d %d %d\n", 1, 2, 3);
1948 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1949 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1950 vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
1952 /* a bug of x86's TCC */
1953 vprintf1("%d %f %l %F %d %f %l %F\n",
1954 1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
1956 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1957 1, 2, 3, 4, 5, 6, 7, 8,
1958 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
1959 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1960 1, 2, 3, 4, 5, 6, 7, 8,
1961 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1962 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1964 1, 2, 3, 4, 5, 6, 7, 8,
1965 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1966 1234567891234LL, 987654321986LL,
1968 vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1970 ld
, 1, 2, 3, 4, 5, 6, 7, 8,
1971 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1972 1234567891234LL, 987654321986LL,
1974 vprintf1("%d %d %d %d %d %d %d %d %F\n",
1975 1, 2, 3, 4, 5, 6, 7, 8, ld
);
1976 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1978 1, 2, 3, 4, 5, 6, 7, 8,
1979 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1980 1234567891234LL, 987654321986LL,
1982 vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1983 "%F %l %l %f %f %F\n",
1984 1, 2, 3, 4, 5, 6, 7, 8,
1985 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1986 ld
, 1234567891234LL, 987654321986LL,
1990 stdarg_for_struct(bob
, bob
, bob
, bob
.profile
);
1993 void whitespace_test(void)
1999 ntf("whitspace:\n");\f\v
2003 #ifdef CORRECT_CR_HANDLING
2012 #ifdef ACCEPT_CR_IN_STRINGS
2013 printf("len1=%d\n", strlen("
2015 #ifdef CORRECT_CR_HANDLING
2018 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
2020 printf("len1=%d\n", strlen("
a
2022 #endif /* ACCEPT_CR_IN_STRINGS */
2025 int reltab
[3] = { 1, 2, 3 };
2027 int *rel1
= &reltab
[1];
2028 int *rel2
= &reltab
[2];
2030 void relocation_test(void)
2032 printf("*rel1=%d\n", *rel1
);
2033 printf("*rel2=%d\n", *rel2
);
2036 void old_style_f(a
,b
,c
)
2040 printf("a=%d b=%d b=%f\n", a
, b
, c
);
2043 void decl_func1(int cmpfn())
2045 printf("cmpfn=%lx\n", (long)cmpfn
);
2048 void decl_func2(cmpfn
)
2051 printf("cmpfn=%lx\n", (long)cmpfn
);
2054 void old_style_function(void)
2056 old_style_f((void *)1, 2, 3.0);
2063 #if defined __i386__ || defined __x86_64__
2064 char *p
= alloca(16);
2065 strcpy(p
,"123456789012345");
2066 printf("alloca: p is %s\n", p
);
2067 char *demo
= "This is only a test.\n";
2068 /* Test alloca embedded in a larger expression */
2069 printf("alloca: %s\n", strcpy(alloca(strlen(demo
)+1),demo
) );
2073 void c99_vla_test(int size1
, int size2
)
2075 #if defined __i386__ || defined __x86_64__
2076 int tab1
[size1
* size2
][2], tab2
[10][2];
2077 void *tab1_ptr
, *tab2_ptr
;
2079 printf("Test C99 VLA 1 (sizeof): ");
2080 printf("%s\n", (sizeof tab1
== size1
* size2
* 2 * sizeof(int)) ? "PASSED" : "FAILED");
2083 printf("Test C99 VLA 2 (ptrs substract): ");
2084 printf("%s\n", (tab2
- tab1
== (tab2_ptr
- tab1_ptr
) / (sizeof(int) * 2)) ? "PASSED" : "FAILED");
2085 printf("Test C99 VLA 3 (ptr add): ");
2086 printf("%s\n", &tab1
[5][1] == (tab1_ptr
+ (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED");
2087 printf("Test C99 VLA 4 (ptr access): ");
2088 tab1
[size1
][1] = 42;
2089 printf("%s\n", (*((int *) (tab1_ptr
+ (size1
* 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED");
2093 void sizeof_test(void)
2098 printf("sizeof(int) = %d\n", sizeof(int));
2099 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
2100 printf("sizeof(long) = %d\n", sizeof(long));
2101 printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
2102 printf("sizeof(short) = %d\n", sizeof(short));
2103 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
2104 printf("sizeof(char) = %d\n", sizeof(char));
2105 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
2106 printf("sizeof(func) = %d\n", sizeof sizeof_test());
2108 printf("sizeof(a++) = %d\n", sizeof a
++);
2109 printf("a=%d\n", a
);
2111 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
2113 /* some alignof tests */
2114 printf("__alignof__(int) = %d\n", __alignof__(int));
2115 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
2116 printf("__alignof__(short) = %d\n", __alignof__(short));
2117 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
2118 printf("__alignof__(char) = %d\n", __alignof__(char));
2119 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
2120 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
2123 void typeof_test(void)
2132 printf("a=%f b=%f c=%f\n", a
, b
, c
);
2135 void statement_expr_test(void)
2148 printf("a=%d\n", a
);
2152 void local_label_test(void)
2158 __label__ l1
, l2
, l3
, l4
;
2172 printf("a=%d\n", a
);
2182 /* inline assembler test */
2185 /* from linux kernel */
2186 static char * strncat1(char * dest
,const char * src
,size_t count
)
2189 __asm__
__volatile__(
2198 "testb %%al,%%al\n\t"
2200 "2:\txorl %2,%2\n\t"
2202 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2203 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2208 static char * strncat2(char * dest
,const char * src
,size_t count
)
2211 __asm__
__volatile__(
2212 "repne scasb\n\t" /* one-line repne prefix + string op */
2219 "testb %%al,%%al\n\t"
2221 "2:\txorl %2,%2\n\t"
2223 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
), "=&c" (d3
)
2224 : "0" (src
),"1" (dest
),"2" (0),"3" (0xffffffff), "g" (count
)
2229 static inline void * memcpy1(void * to
, const void * from
, size_t n
)
2232 __asm__
__volatile__(
2237 "1:\ttestb $1,%b4\n\t"
2241 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2242 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2247 static inline void * memcpy2(void * to
, const void * from
, size_t n
)
2250 __asm__
__volatile__(
2251 "rep movsl\n\t" /* one-line rep prefix + string op */
2255 "1:\ttestb $1,%b4\n\t"
2259 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
2260 :"0" (n
/4), "q" (n
),"1" ((long) to
),"2" ((long) from
)
2265 static __inline__
void sigaddset1(unsigned int *set
, int _sig
)
2267 __asm__("btsl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2270 static __inline__
void sigdelset1(unsigned int *set
, int _sig
)
2272 asm("btrl %1,%0" : "=m"(*set
) : "Ir"(_sig
- 1) : "cc");
2275 static __inline__ __const__
unsigned int swab32(unsigned int x
)
2277 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
2278 "rorl $16,%0\n\t" /* swap words */
2279 "xchgb %b0,%h0" /* swap higher bytes */
2285 static __inline__
unsigned long long mul64(unsigned int a
, unsigned int b
)
2287 unsigned long long res
;
2288 __asm__("mull %2" : "=A" (res
) : "a" (a
), "r" (b
));
2292 static __inline__
unsigned long long inc64(unsigned long long a
)
2294 unsigned long long res
;
2295 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res
) : "A" (a
));
2306 printf("inline asm:\n");
2307 /* test the no operand case */
2308 asm volatile ("xorl %eax, %eax");
2310 memcpy1(buf
, "hello", 6);
2311 strncat1(buf
, " worldXXXXX", 3);
2312 printf("%s\n", buf
);
2314 memcpy2(buf
, "hello", 6);
2315 strncat2(buf
, " worldXXXXX", 3);
2316 printf("%s\n", buf
);
2318 /* 'A' constraint test */
2319 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
2320 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
2323 sigdelset1(&set
, 2);
2324 sigaddset1(&set
, 16);
2325 /* NOTE: we test here if C labels are correctly restored after the
2329 __asm__("btsl %1,%0" : "=m"(set
) : "Ir"(20) : "cc");
2330 #ifdef __GNUC__ // works strange with GCC 4.3
2333 printf("set=0x%x\n", set
);
2335 printf("swab32(0x%08x) = 0x%0x\n", val
, swab32(val
));
2349 #define COMPAT_TYPE(type1, type2) \
2351 printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
2352 __builtin_types_compatible_p (type1, type2));\
2357 void builtin_test(void)
2360 COMPAT_TYPE(int, int);
2361 COMPAT_TYPE(int, unsigned int);
2362 COMPAT_TYPE(int, char);
2363 COMPAT_TYPE(int, const int);
2364 COMPAT_TYPE(int, volatile int);
2365 COMPAT_TYPE(int *, int *);
2366 COMPAT_TYPE(int *, void *);
2367 COMPAT_TYPE(int *, const int *);
2368 COMPAT_TYPE(char *, unsigned char *);
2369 /* space is needed because tcc preprocessor introduces a space between each token */
2370 COMPAT_TYPE(char * *, void *);
2372 printf("res = %d\n", __builtin_constant_p(1));
2373 printf("res = %d\n", __builtin_constant_p(1 + 2));
2374 printf("res = %d\n", __builtin_constant_p(&constant_p_var
));
2375 printf("res = %d\n", __builtin_constant_p(constant_p_var
));
2379 extern int __attribute__((weak
)) weak_f1(void);
2380 extern int __attribute__((weak
)) weak_f2(void);
2381 extern int weak_f3(void);
2382 extern int __attribute__((weak
)) weak_v1
;
2383 extern int __attribute__((weak
)) weak_v2
;
2386 extern int (*weak_fpa
)() __attribute__((weak
));
2387 extern int __attribute__((weak
)) (*weak_fpb
)();
2388 extern __attribute__((weak
)) int (*weak_fpc
)();
2390 extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak
));
2391 extern int __attribute((weak
)) weak_asm_f2(void) asm("weak_asm_f2x") ;
2392 extern int __attribute((weak
)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak
));
2393 extern int weak_asm_v1
asm("weak_asm_v1x") __attribute((weak
));
2394 extern int __attribute((weak
)) weak_asm_v2
asm("weak_asm_v2x") ;
2395 extern int __attribute((weak
)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak
));
2397 static const size_t dummy
= 0;
2398 extern __typeof(dummy
) weak_dummy1
__attribute__((weak
, alias("dummy")));
2399 extern __typeof(dummy
) __attribute__((weak
, alias("dummy"))) weak_dummy2
;
2400 extern __attribute__((weak
, alias("dummy"))) __typeof(dummy
) weak_dummy3
;
2402 int some_lib_func(void);
2403 int dummy_impl_of_slf(void) { return 444; }
2404 int some_lib_func(void) __attribute__((weak
, alias("dummy_impl_of_slf")));
2406 int weak_toolate() { return 0; }
2407 int weak_toolate() __attribute__((weak
));
2409 void __attribute__((weak
)) weak_test(void)
2411 printf("weak_f1=%d\n", weak_f1
? weak_f1() : 123);
2412 printf("weak_f2=%d\n", weak_f2
? weak_f2() : 123);
2413 printf("weak_f3=%d\n", weak_f3
? weak_f3() : 123);
2414 printf("weak_v1=%d\n",&weak_v1
? weak_v1
: 123);
2415 printf("weak_v2=%d\n",&weak_v2
? weak_v2
: 123);
2416 printf("weak_v3=%d\n",&weak_v3
? weak_v3
: 123);
2418 printf("weak_fpa=%d\n",&weak_fpa
? weak_fpa() : 123);
2419 printf("weak_fpb=%d\n",&weak_fpb
? weak_fpb() : 123);
2420 printf("weak_fpc=%d\n",&weak_fpc
? weak_fpc() : 123);
2422 printf("weak_asm_f1=%d\n", weak_asm_f1
!= NULL
);
2423 printf("weak_asm_f2=%d\n", weak_asm_f2
!= NULL
);
2424 printf("weak_asm_f3=%d\n", weak_asm_f3
!= NULL
);
2425 printf("weak_asm_v1=%d\n",&weak_asm_v1
!= NULL
);
2426 printf("weak_asm_v2=%d\n",&weak_asm_v2
!= NULL
);
2427 printf("weak_asm_v3=%d\n",&weak_asm_v3
!= NULL
);
2430 int __attribute__((weak
)) weak_f2() { return 222; }
2431 int __attribute__((weak
)) weak_f3() { return 333; }
2432 int __attribute__((weak
)) weak_v2
= 222;
2433 int __attribute__((weak
)) weak_v3
= 333;
2435 void const_func(const int a
)
2439 void const_warn_test(void)