├── VERSION ├── tests ├── pp │ ├── 04.expect │ ├── 06.expect │ ├── 07.expect │ ├── 09.expect │ ├── 08.expect │ ├── 01.expect │ ├── 13.expect │ ├── 16.expect │ ├── 18.expect │ ├── 07.c │ ├── 06.c │ ├── 10.expect │ ├── 16.c │ ├── 04.c │ ├── 09.c │ ├── 12.expect │ ├── 14.expect │ ├── 05.expect │ ├── 15.expect │ ├── 21.expect │ ├── 17.expect │ ├── 08.c │ ├── 20.expect │ ├── 13.S │ ├── 03.expect │ ├── 19.expect │ ├── 01.c │ ├── 10.c │ ├── 11.expect │ ├── 14.c │ ├── 12.S │ ├── 05.c │ ├── 02.expect │ ├── pp-counter.expect │ ├── 17.c │ ├── 03.c │ ├── 15.c │ ├── 20.c │ ├── 21.c │ ├── 18.c │ ├── pp-counter.c │ ├── 02.c │ ├── 11.c │ └── Makefile ├── tests2 │ ├── 81_types.expect │ ├── 80_flexarray.expect │ ├── 100_c99array-decls.expect │ ├── 92_enum_bitfield.expect │ ├── 102_alignas.expect │ ├── 103_implicit_memmove.expect │ ├── 43_void_param.expect │ ├── 48_nested_break.expect │ ├── 64_macro_nesting.expect │ ├── 86_memory-model.expect │ ├── 99_fastcall.expect │ ├── 105_local_extern.expect │ ├── 29_array_address.expect │ ├── 35_sizeof.expect │ ├── 71_macro_empty_arg.expect │ ├── 84_hex-float.expect │ ├── 88_codeopt.expect │ ├── 18_include.h │ ├── 27_sizeof.expect │ ├── 82_attribs_position.expect │ ├── 85_asm-outside-function.expect │ ├── 00_assignment.expect │ ├── 12_hashdefine.expect │ ├── 14_if.expect │ ├── 39_typedef.expect │ ├── 42_function_pointer.expect │ ├── 55_lshift_type.expect │ ├── 44_scoped_declarations.expect │ ├── 47_switch_return.expect │ ├── 07_function.expect │ ├── 18_include.expect │ ├── 49_bracket_evaluation.expect │ ├── 67_macro_concat.expect │ ├── 91_ptr_longlong_arith32.expect │ ├── 03_struct.expect │ ├── 34_array_assignment.expect │ ├── 72_long_long_constant.expect │ ├── 79_vla_continue.expect │ ├── 83_utf8_in_identifiers.expect │ ├── 06_case.expect │ ├── 41_hashif.expect │ ├── 78_vla_label.expect │ ├── 01_comment.expect │ ├── 19_pointer_arithmetic.expect │ ├── 20_pointer_comparison.expect │ ├── 17_enum.expect │ ├── 95_bitfields_ms.c │ ├── 13_integer_literals.expect │ ├── 04_for.expect │ ├── 26_character_constants.expect │ ├── 51_static.expect │ ├── 05_array.expect │ ├── 45_empty_for.expect │ ├── 46_grep.expect │ ├── 08_while.expect │ ├── 33_ternary_op.expect │ ├── 09_do_while.expect │ ├── 52_unnamed_enum.expect │ ├── 77_push_pop_macro.expect │ ├── 38_multiple_array_index.expect │ ├── 15_recursion.expect │ ├── 21_char_array.expect │ ├── 31_args.expect │ ├── 54_goto.expect │ ├── 32_led.expect │ ├── 25_quicksort.expect │ ├── 94_generic.expect │ ├── 97_utf8_string_literal.expect │ ├── 11_precedence.expect │ ├── 10_pointer.expect │ ├── 28_strings.expect │ ├── 50_logical_second_arg.expect │ ├── 71_macro_empty_arg.c │ ├── 23_type_coercion.expect │ ├── 98_al_ax_extend.expect │ ├── 16_nesting.expect │ ├── 85_asm-outside-function.c │ ├── 89_nocode_wanted.expect │ ├── 76_dollars_in_identifiers.expect │ ├── 43_void_param.c │ ├── 83_utf8_in_identifiers.c │ ├── 18_include.c │ ├── 37_sprintf.expect │ ├── 36_array_initialisers.expect │ ├── 64_macro_nesting.c │ ├── 29_array_address.c │ ├── 22_floating_point.expect │ ├── 04_for.c │ ├── 24_math_library.expect │ ├── 87_dead_code.expect │ ├── 105_local_extern.c │ ├── 35_sizeof.c │ ├── 02_printf.expect │ ├── 44_scoped_declarations.c │ ├── 12_hashdefine.c │ ├── 45_empty_for.c │ ├── 84_hex-float.c │ ├── 67_macro_concat.c │ ├── 00_assignment.c │ ├── 97_utf8_string_literal.c │ ├── 31_args.c │ ├── 37_sprintf.c │ ├── 01_comment.c │ ├── 27_sizeof.c │ ├── 91_ptr_longlong_arith32.c │ ├── 08_while.c │ ├── 09_do_while.c │ ├── 14_if.c │ ├── 15_recursion.c │ ├── 16_nesting.c │ ├── 26_character_constants.c │ ├── 05_array.c │ ├── 13_integer_literals.c │ ├── 34_array_assignment.c │ ├── 47_switch_return.c │ ├── 40_stdio.expect │ ├── 72_long_long_constant.c │ ├── 48_nested_break.c │ ├── 02_printf.c │ ├── 49_bracket_evaluation.c │ ├── 103_implicit_memmove.c │ ├── 20_pointer_comparison.c │ ├── 19_pointer_arithmetic.c │ ├── 07_function.c │ ├── 42_function_pointer.c │ ├── 36_array_initialisers.c │ ├── 51_static.c │ ├── 52_unnamed_enum.c │ ├── 06_case.c │ ├── 38_multiple_array_index.c │ ├── 21_char_array.c │ ├── 80_flexarray.c │ ├── 03_struct.c │ ├── 50_logical_second_arg.c │ ├── 77_push_pop_macro.c │ ├── 100_c99array-decls.c │ ├── 70_floating_point_literals.expect │ ├── 10_pointer.c │ ├── 24_math_library.c │ ├── 96_nodata_wanted.expect │ ├── 54_goto.c │ ├── 101_cleanup.expect │ ├── 11_precedence.c │ ├── 86_memory-model.c │ ├── 78_vla_label.c │ ├── 76_dollars_in_identifiers.c │ ├── 23_type_coercion.c │ ├── 93_integer_promotion.expect │ ├── 102_alignas.c │ ├── 98_al_ax_extend.c │ ├── 28_strings.c │ ├── 40_stdio.c │ ├── 41_hashif.c │ ├── 104_inline.expect │ ├── 81_types.c │ ├── 22_floating_point.c │ ├── 33_ternary_op.c │ ├── 39_typedef.c │ ├── 75_array_in_struct_init.expect │ ├── 17_enum.c │ ├── 88_codeopt.c │ ├── 92_enum_bitfield.c │ ├── 93_integer_promotion.c │ ├── 25_quicksort.c │ ├── 55_lshift_type.c │ ├── 104+_inline.c │ ├── 90_struct-init.expect │ ├── 30_hanoi.expect │ ├── 79_vla_continue.c │ ├── LICENSE │ ├── 82_attribs_position.c │ ├── 70_floating_point_literals.c │ └── 96_nodata_wanted.c ├── tcctest.h ├── 42test.h ├── asm-c-connect-2.c ├── gcctestsuite.sh ├── asm-c-connect-1.c ├── vla_test.c └── libtcc_test.c ├── win32 ├── lib │ ├── crt1w.c │ ├── wincrt1w.c │ ├── dllmain.c │ ├── dllcrt1.c │ ├── chkstk.S │ ├── wincrt1.c │ └── crt1.c ├── include │ ├── values.h │ ├── winapi │ │ ├── poppack.h │ │ ├── pshpack1.h │ │ ├── pshpack2.h │ │ ├── pshpack4.h │ │ ├── pshpack8.h │ │ ├── ws2ipdef.h │ │ ├── qos.h │ │ ├── basetyps.h │ │ └── windows.h │ ├── vadefs.h │ ├── mem.h │ ├── sys │ │ ├── unistd.h │ │ ├── fcntl.h │ │ ├── file.h │ │ ├── locking.h │ │ ├── time.h │ │ └── types.h │ ├── sec_api │ │ ├── crtdbg_s.h │ │ ├── sys │ │ │ └── timeb_s.h │ │ ├── search_s.h │ │ ├── stralign_s.h │ │ ├── io_s.h │ │ ├── conio_s.h │ │ ├── string_s.h │ │ └── time_s.h │ ├── iso646.h │ ├── share.h │ ├── dir.h │ ├── uchar.h │ ├── dos.h │ ├── memory.h │ ├── fcntl.h │ ├── assert.h │ ├── errno.h │ ├── signal.h │ ├── direct.h │ └── locale.h └── examples │ ├── dll.c │ ├── fib.c │ └── hello_dll.c ├── lib ├── dsohandle.c ├── alloca-arm.S ├── alloca86.S ├── alloca86_64.S ├── alloca86-bt.S ├── alloca86_64-bt.S ├── armflush.c ├── va_list.c └── Makefile ├── examples ├── ex5.c ├── ex1.c ├── ex3.c ├── ex4.c └── ex2.c ├── include ├── stdnoreturn.h ├── stdbool.h ├── varargs.h ├── stdalign.h ├── float.h └── stddef.h ├── stab.h ├── .gitignore ├── arm-asm.c ├── CodingStyle ├── conftest.c └── RELICENSING /VERSION: -------------------------------------------------------------------------------- 1 | 0.9.27 2 | -------------------------------------------------------------------------------- /tests/pp/04.expect: -------------------------------------------------------------------------------- 1 | (1) 2 | -------------------------------------------------------------------------------- /tests/pp/06.expect: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/tests2/81_types.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/pp/07.expect: -------------------------------------------------------------------------------- 1 | a 2 | YES 3 | -------------------------------------------------------------------------------- /tests/pp/09.expect: -------------------------------------------------------------------------------- 1 | aaaaoooo 2 | -------------------------------------------------------------------------------- /tests/tests2/80_flexarray.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/pp/08.expect: -------------------------------------------------------------------------------- 1 | (hej.s_s.s_pos) 2 | -------------------------------------------------------------------------------- /tests/tests2/100_c99array-decls.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/tests2/92_enum_bitfield.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/pp/01.expect: -------------------------------------------------------------------------------- 1 | char p[] = "x ## y"; 2 | -------------------------------------------------------------------------------- /tests/pp/13.expect: -------------------------------------------------------------------------------- 1 | .text 2 | endtext: 3 | -------------------------------------------------------------------------------- /tests/tests2/102_alignas.expect: -------------------------------------------------------------------------------- 1 | 1 1 1 1 2 | -------------------------------------------------------------------------------- /tests/tests2/103_implicit_memmove.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/tests2/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /tests/tests2/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/tests2/64_macro_nesting.expect: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /tests/tests2/86_memory-model.expect: -------------------------------------------------------------------------------- 1 | Ok 2 | -------------------------------------------------------------------------------- /tests/tests2/99_fastcall.expect: -------------------------------------------------------------------------------- 1 | TEST OK 2 | -------------------------------------------------------------------------------- /tests/tests2/105_local_extern.expect: -------------------------------------------------------------------------------- 1 | f 2 | f 3 | -------------------------------------------------------------------------------- /tests/tests2/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /tests/tests2/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tests/tests2/71_macro_empty_arg.expect: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /tests/tests2/84_hex-float.expect: -------------------------------------------------------------------------------- 1 | n+1 = 15 2 | -------------------------------------------------------------------------------- /tests/tests2/88_codeopt.expect: -------------------------------------------------------------------------------- 1 | okay 2 | okay 3 | -------------------------------------------------------------------------------- /tests/tests2/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | 4 5 | -------------------------------------------------------------------------------- /tests/tests2/82_attribs_position.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 42 3 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.expect: -------------------------------------------------------------------------------- 1 | okay 2 | -------------------------------------------------------------------------------- /tests/pp/16.expect: -------------------------------------------------------------------------------- 1 | 2 | 16.c:3: warning: A redefined 3 | -------------------------------------------------------------------------------- /tests/pp/18.expect: -------------------------------------------------------------------------------- 1 | X181 1 2 | X182 0 3 | X183 yeah 4 | -------------------------------------------------------------------------------- /tests/tests2/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /tests/tests2/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tests/tests2/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /tests/tests2/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /tests/tests2/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.expect: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tests/tests2/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /tests/tests2/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /tests/tests2/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /tests/tests2/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.expect: -------------------------------------------------------------------------------- 1 | jim: 21, bob: 42 2 | jim: 63 3 | -------------------------------------------------------------------------------- /tests/tests2/91_ptr_longlong_arith32.expect: -------------------------------------------------------------------------------- 1 | data = "0123-5678" 2 | -------------------------------------------------------------------------------- /tests/pp/07.c: -------------------------------------------------------------------------------- 1 | #define a() YES 2 | #define b() a 3 | b() 4 | b()() 5 | -------------------------------------------------------------------------------- /tests/tests2/03_struct.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /tests/tests2/72_long_long_constant.expect: -------------------------------------------------------------------------------- 1 | long long constant test ok. 2 | -------------------------------------------------------------------------------- /tests/tests2/79_vla_continue.expect: -------------------------------------------------------------------------------- 1 | OK 2 | OK 3 | OK 4 | OK 5 | OK 6 | -------------------------------------------------------------------------------- /tests/tests2/83_utf8_in_identifiers.expect: -------------------------------------------------------------------------------- 1 | привет=0.1 2 | Lefèvre=2 3 | -------------------------------------------------------------------------------- /tests/pp/06.c: -------------------------------------------------------------------------------- 1 | #define X(a,b, \ 2 | c,d) \ 3 | foo 4 | 5 | X(1,2,3,4) 6 | -------------------------------------------------------------------------------- /tests/tests2/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /tests/tests2/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /tests/tests2/78_vla_label.expect: -------------------------------------------------------------------------------- 1 | boom! 2 | boom! 3 | 11 4 | 12 5 | 0 6 | 1 7 | -------------------------------------------------------------------------------- /tests/tests2/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /tests/tests2/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /tests/tests2/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /tests/pp/10.expect: -------------------------------------------------------------------------------- 1 | x 2 | x x 3 | x x x x 4 | x x x x x x x x 5 | x x x x x x x x)))) 6 | -------------------------------------------------------------------------------- /tests/pp/16.c: -------------------------------------------------------------------------------- 1 | /* The following should warn */ 2 | #define A ... 3 | #define A <<= 4 | -------------------------------------------------------------------------------- /tests/tests2/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | enum to int: 1 5 | -------------------------------------------------------------------------------- /tests/tests2/95_bitfields_ms.c: -------------------------------------------------------------------------------- 1 | #define MS_BITFIELDS 1 2 | #include "95_bitfields.c" 3 | -------------------------------------------------------------------------------- /win32/lib/crt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "crt1.c" 4 | -------------------------------------------------------------------------------- /lib/dsohandle.c: -------------------------------------------------------------------------------- 1 | void * __dso_handle __attribute((visibility("hidden"))) = &__dso_handle; 2 | -------------------------------------------------------------------------------- /tests/tests2/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /win32/lib/wincrt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "wincrt1.c" 4 | -------------------------------------------------------------------------------- /tests/pp/04.c: -------------------------------------------------------------------------------- 1 | #define foobar 1 2 | #define C(x,y) x##y 3 | #define D(x) (C(x,bar)) 4 | D(foo) 5 | -------------------------------------------------------------------------------- /tests/tests2/04_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/tests2/26_character_constants.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @ 9 | -------------------------------------------------------------------------------- /tests/tests2/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /tests/pp/09.c: -------------------------------------------------------------------------------- 1 | #define C(a,b,c) a##b##c 2 | #define N(x,y) C(x,_,y) 3 | #define A_O aaaaoooo 4 | N(A,O) 5 | -------------------------------------------------------------------------------- /tests/tests2/05_array.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /tests/tests2/45_empty_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/tests2/46_grep.expect: -------------------------------------------------------------------------------- 1 | File 46_grep.c: 2 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 3 | 4 | -------------------------------------------------------------------------------- /tests/pp/12.expect: -------------------------------------------------------------------------------- 1 | 9999: 1: movw (%esi), %bx; .section __ex_table, "a"; .long 9999b, 6001f ; 2 | 6001: 3 | -------------------------------------------------------------------------------- /tests/tests2/08_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/tests2/33_ternary_op.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /tests/pp/14.expect: -------------------------------------------------------------------------------- 1 | return Z(Z(1,2),2); 2 | return Q(1,2); 3 | return ((A + A) * (A + A)) + ((B * B) + (B * B)); 4 | -------------------------------------------------------------------------------- /tests/tests2/09_do_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/tests2/52_unnamed_enum.expect: -------------------------------------------------------------------------------- 1 | a=0 2 | b=1 3 | c=2 4 | e=0 5 | f=1 6 | g=2 7 | i=0 8 | j=1 9 | k=2 10 | -------------------------------------------------------------------------------- /tests/tests2/77_push_pop_macro.expect: -------------------------------------------------------------------------------- 1 | abort = 111 2 | abort = 222 3 | abort = 333 4 | abort = 222 5 | abort = 111 6 | -------------------------------------------------------------------------------- /tests/pp/05.expect: -------------------------------------------------------------------------------- 1 | int j[] = { 123, 45, 67, 89, 2 | 10, 11, 12, }; 3 | int j[] = { 123, 45, 67, 89, 10, 11, 12, }; 4 | -------------------------------------------------------------------------------- /tests/pp/15.expect: -------------------------------------------------------------------------------- 1 | return (long double)d; 2 | return A+++B; 3 | return A+ ++B; 4 | return A+++ +B; 5 | return 0x1E -1; 6 | -------------------------------------------------------------------------------- /tests/pp/21.expect: -------------------------------------------------------------------------------- 1 | ----- 1 ------ 2 | OK 3 | ----- 2 ------ 4 | OK 5 | ----- 3 ------ 6 | OK 7 | ----- 4 ------ 8 | OK 9 | -------------------------------------------------------------------------------- /tests/tests2/38_multiple_array_index.expect: -------------------------------------------------------------------------------- 1 | x=0: 1 2 3 4 2 | x=1: 5 6 7 8 3 | x=2: 9 10 11 12 4 | x=3: 13 14 15 16 5 | -------------------------------------------------------------------------------- /tests/tests2/15_recursion.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /tests/tests2/21_char_array.expect: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /tests/tests2/31_args.expect: -------------------------------------------------------------------------------- 1 | hello world 6 2 | arg 1: arg1 3 | arg 2: arg2 4 | arg 3: arg3 5 | arg 4: arg4 6 | arg 5: arg5 7 | -------------------------------------------------------------------------------- /tests/tests2/54_goto.expect: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /tests/pp/17.expect: -------------------------------------------------------------------------------- 1 | X162 "onetok" 2 | X161 "onetok" 3 | X163 "one##tok" 4 | X170 x ## y 5 | X171 x ## y 6 | X180 return Z(Z(1)); 7 | -------------------------------------------------------------------------------- /tests/tests2/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tests/pp/08.c: -------------------------------------------------------------------------------- 1 | // test macro expansion in arguments 2 | #define s_pos s_s.s_pos 3 | #define foo(x) (x) 4 | foo(hej.s_pos) 5 | -------------------------------------------------------------------------------- /tests/tests2/25_quicksort.expect: -------------------------------------------------------------------------------- 1 | 62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 2 | 4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 3 | -------------------------------------------------------------------------------- /tests/tests2/94_generic.expect: -------------------------------------------------------------------------------- 1 | 20 2 | 10 3 | 20 4 | 123 5 | 2 6 | 0 7 | 5 8 | 1 9 | 2 10 | 3 11 | 4 12 | long 13 | 1 14 | 3 15 | -------------------------------------------------------------------------------- /examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/tests2/97_utf8_string_literal.expect: -------------------------------------------------------------------------------- 1 | 0068 0065 006C 006C 006F 0024 0024 4F60 597D 00A2 00A2 4E16 754C 20AC 20AC 0077 006F 0072 006C 0064 2 | -------------------------------------------------------------------------------- /examples/ex1.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/pp/20.expect: -------------------------------------------------------------------------------- 1 | X1 printk(KERN_WARNING "pipapo",bla); 2 | X2 printk(KERN_WARNING "bla",foo); 3 | X2 twoopq 4 | X3 otwopq 5 | X4 optwoq 6 | X5 opqtwo 7 | -------------------------------------------------------------------------------- /tests/tests2/11_precedence.expect: -------------------------------------------------------------------------------- 1 | 134 2 | 134 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 46 9 | 1, 0 10 | 0, 1 11 | 1 12 | 1916 13 | 1916 14 | 64 15 | 4 16 | -------------------------------------------------------------------------------- /win32/include/values.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TODO: Nothing here yet. Should provide UNIX compatibility constants 3 | * comparable to those in limits.h and float.h. 4 | */ 5 | -------------------------------------------------------------------------------- /include/stdnoreturn.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDNORETURN_H 2 | #define _STDNORETURN_H 3 | 4 | /* ISOC11 noreturn */ 5 | #define noreturn _Noreturn 6 | 7 | #endif /* _STDNORETURN_H */ 8 | -------------------------------------------------------------------------------- /tests/tests2/10_pointer.expect: -------------------------------------------------------------------------------- 1 | a = 42 2 | bolshevic.a = 12 3 | bolshevic.b = 34 4 | bolshevic.c = 56 5 | tsar->a = 12 6 | tsar->b = 34 7 | tsar->c = 56 8 | bolshevic.b = 34 9 | -------------------------------------------------------------------------------- /tests/pp/13.S: -------------------------------------------------------------------------------- 1 | # `modelist' label. Each video mode record looks like: 2 | #ifdef AAA 3 | # modelist' label. Each video mode record looks like: 4 | #endif 5 | .text 6 | endtext: 7 | -------------------------------------------------------------------------------- /tests/tests2/28_strings.expect: -------------------------------------------------------------------------------- 1 | hello 2 | gollo 3 | 1 4 | 1 5 | 1 6 | 5 7 | gollo! 8 | 1 9 | 1 10 | 1 11 | 1 12 | ollo! 13 | lo! 14 | 1 15 | grrrr! 16 | grgrr! 17 | 1 18 | 1 19 | 1 20 | -------------------------------------------------------------------------------- /tests/pp/03.expect: -------------------------------------------------------------------------------- 1 | printf("x" "1" "= %d, x" "2" "= %s", x1, x2); 2 | fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s); 3 | \#include "vers2.h" 4 | "hello"; 5 | "hello" ", world" 6 | -------------------------------------------------------------------------------- /tests/pp/19.expect: -------------------------------------------------------------------------------- 1 | X92 M_IFI_1 2 | X93 KO 3 | X94 KO 4 | X95 a 5 | X96 M_IFI_1 6 | X97 ok 7 | X98 (1)(ok, nok) 8 | X99 ok 9 | X1 ok 10 | X2 1 11 | X3 ok 12 | X4 1 13 | X5 nok 14 | X6 ok 15 | -------------------------------------------------------------------------------- /tests/pp/01.c: -------------------------------------------------------------------------------- 1 | #define hash_hash # ## # 2 | #define mkstr(a) # a 3 | #define in_between(a) mkstr(a) 4 | #define join(c, d) in_between(c hash_hash d) 5 | char p[] = join(x, y); 6 | // char p[] = "x ## y"; 7 | -------------------------------------------------------------------------------- /tests/pp/10.c: -------------------------------------------------------------------------------- 1 | #define f(x) x 2 | #define g(x) f(x) f(x 3 | #define i(x) g(x)) g(x 4 | #define h(x) i(x))) i(x 5 | #define k(x) i(x))) i(x)))) 6 | f(x) 7 | g(x)) 8 | i(x))) 9 | h(x)))) 10 | k(x)))) 11 | -------------------------------------------------------------------------------- /tests/tests2/50_logical_second_arg.expect: -------------------------------------------------------------------------------- 1 | fred 2 | 0 3 | fred 4 | joe 5 | 1 6 | joe 7 | fred 8 | 0 9 | joe 10 | 1 11 | fred 12 | 0 13 | fred 14 | joe 15 | 1 16 | joe 17 | fred 18 | 0 19 | joe 20 | 1 21 | -------------------------------------------------------------------------------- /tests/tests2/71_macro_empty_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define T(a,b,c) a b c 4 | 5 | int main(void) 6 | { 7 | printf("%d", T(1,+,2) T(+,,) T(,2,*) T(,7,) T(,,)); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/pp/11.expect: -------------------------------------------------------------------------------- 1 | a 2 | a b 3 | a b c 4 | a b c d 5 | x a b c d y 6 | x a b c y 7 | x a b y 8 | x a y 9 | x y 10 | x A,B,C y 11 | x A,B y 12 | x A y 13 | x y 14 | __attribute__((__noreturn__)) 15 | 1 2 16 | -------------------------------------------------------------------------------- /tests/tcctest.h: -------------------------------------------------------------------------------- 1 | static inline const char *get_basefile_from_header(void) 2 | { 3 | return __BASE_FILE__; 4 | } 5 | 6 | static inline const char *get_file_from_header(void) 7 | { 8 | return __FILE__; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/23_type_coercion.expect: -------------------------------------------------------------------------------- 1 | char: a 2 | char: b 3 | char: c 4 | int: 97 5 | int: 98 6 | int: 99 7 | float: 97.000000 8 | float: 98.000000 9 | float: 99.000000 10 | 97 97 11 | 97 97 12 | 97.000000 97.000000 13 | -------------------------------------------------------------------------------- /tests/tests2/98_al_ax_extend.expect: -------------------------------------------------------------------------------- 1 | 0000ABCE 0000ABCE 2 | FFFFABCE FFFFABCE 3 | 000000CE 000000CE 4 | FFFFFFCE FFFFFFCE 5 | 6 | 0000ABCE 0000ABCE 7 | FFFFABCE FFFFABCE 8 | 000000CE 000000CE 9 | FFFFFFCE FFFFFFCE 10 | -------------------------------------------------------------------------------- /tests/tests2/16_nesting.expect: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 1 3 | 0 0 2 4 | 0 1 0 5 | 0 1 1 6 | 0 1 2 7 | 0 2 0 8 | 0 2 1 9 | 0 2 2 10 | 1 0 0 11 | 1 0 1 12 | 1 0 2 13 | 1 1 0 14 | 1 1 1 15 | 1 1 2 16 | 1 2 0 17 | 1 2 1 18 | 1 2 2 19 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.c: -------------------------------------------------------------------------------- 1 | extern int printf (const char *, ...); 2 | extern void vide(void); 3 | __asm__("vide: ret"); 4 | 5 | int main() { 6 | vide(); 7 | printf ("okay\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/tests2/89_nocode_wanted.expect: -------------------------------------------------------------------------------- 1 | begin 2 | timeout=2 3 | timeout=1 4 | timeout=2 5 | timeout=1 6 | timeout=2 7 | timeout=1 8 | timeout=2 9 | timeout=1 10 | timeout=2 11 | timeout=1 12 | timeout=2 13 | timeout=1 14 | end 15 | -------------------------------------------------------------------------------- /tests/tests2/76_dollars_in_identifiers.expect: -------------------------------------------------------------------------------- 1 | fred=10 2 | joe=20 3 | henry=30 4 | fred2=10 5 | joe2=20 6 | henry2=30 7 | fred10=100 8 | joe_10=2 9 | local=10 10 | a100$=100 11 | a$$=1000 12 | a$c$b=2121 13 | $100=10000 14 | $$$=money 15 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /* ISOC99 boolean */ 5 | 6 | #define bool _Bool 7 | #define true 1 8 | #define false 0 9 | #define __bool_true_false_are_defined 1 10 | 11 | #endif /* _STDBOOL_H */ 12 | -------------------------------------------------------------------------------- /tests/tests2/43_void_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(void) 4 | { 5 | printf("yo\n"); 6 | } 7 | 8 | int main() 9 | { 10 | fred(); 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tests/tests2/83_utf8_in_identifiers.c: -------------------------------------------------------------------------------- 1 | #include 2 | double привет=0.1; 3 | int Lefèvre=2; 4 | int main(){ 5 | printf("привет=%g\n",привет); 6 | printf("Lefèvre=%d\n",Lefèvre); 7 | return 0; 8 | } 9 | // pcc & tcc only 10 | -------------------------------------------------------------------------------- /tests/pp/14.c: -------------------------------------------------------------------------------- 1 | #define W Z 2 | #define Z(X) W(X,2) 3 | #define Y(X) Z(X) 4 | #define X Y 5 | return X(X(1)); 6 | 7 | #define P Q 8 | #define Q(n) P(n,2) 9 | return P(1); 10 | 11 | #define A (B * B) 12 | #define B (A + A) 13 | return A + B; 14 | -------------------------------------------------------------------------------- /tests/tests2/18_include.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("including\n"); 6 | #include "18_include.h" 7 | printf("done\n"); 8 | 9 | return 0; 10 | } 11 | 12 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 13 | -------------------------------------------------------------------------------- /win32/lib/dllmain.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) 6 | { 7 | return TRUE; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/pp/12.S: -------------------------------------------------------------------------------- 1 | #define SRC(y...) \ 2 | 9999: y; \ 3 | .section __ex_table, "a"; \ 4 | .long 9999b, 6001f ; \ 5 | // .previous 6 | 7 | SRC(1: movw (%esi), %bx) 8 | 6001: 9 | -------------------------------------------------------------------------------- /tests/tests2/37_sprintf.expect: -------------------------------------------------------------------------------- 1 | ->01<- 2 | ->02<- 3 | ->03<- 4 | ->04<- 5 | ->05<- 6 | ->06<- 7 | ->07<- 8 | ->08<- 9 | ->09<- 10 | ->10<- 11 | ->11<- 12 | ->12<- 13 | ->13<- 14 | ->14<- 15 | ->15<- 16 | ->16<- 17 | ->17<- 18 | ->18<- 19 | ->19<- 20 | ->20<- 21 | -------------------------------------------------------------------------------- /tests/pp/05.c: -------------------------------------------------------------------------------- 1 | #define t(x,y,z) x ## y ## z 2 | #define xxx(s) int s[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), \ 3 | t(10,,), t(,11,), t(,,12), t(,,) }; 4 | 5 | int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), 6 | t(10,,), t(,11,), t(,,12), t(,,) }; 7 | xxx(j) 8 | -------------------------------------------------------------------------------- /tests/tests2/36_array_initialisers.expect: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /tests/tests2/64_macro_nesting.c: -------------------------------------------------------------------------------- 1 | #include // printf() 2 | 3 | #define CAT2(a,b) a##b 4 | #define CAT(a,b) CAT2(a,b) 5 | #define AB(x) CAT(x,y) 6 | 7 | int main(void) 8 | { 9 | int xy = 42; 10 | printf("%d\n", CAT(A,B)(x)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/tests2/29_array_address.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | strcpy(a, "abcdef"); 8 | printf("%s\n", &a[1]); 9 | 10 | return 0; 11 | } 12 | 13 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 14 | -------------------------------------------------------------------------------- /tests/tests2/22_floating_point.expect: -------------------------------------------------------------------------------- 1 | 69.120003 2 | 69.120000 3 | -44.440000 4 | 700.665200 5 | 0.217330 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.120003 10 | -44.439999 11 | 700.665222 12 | 0.217330 13 | 12.340000 14 | -12.340000 15 | 2.000000 16 | 0.909297 17 | -------------------------------------------------------------------------------- /tests/tests2/04_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 1; Count <= 10; Count++) 8 | { 9 | printf("%d\n", Count); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 16 | -------------------------------------------------------------------------------- /tests/tests2/24_math_library.expect: -------------------------------------------------------------------------------- 1 | 0.119712 2 | 0.992809 3 | 0.120579 4 | 0.120290 5 | 1.450506 6 | 0.119429 7 | 0.120288 8 | 1.007209 9 | 0.119427 10 | 1.127497 11 | 0.120000 12 | -2.120264 13 | -0.920819 14 | 0.775357 15 | 0.346410 16 | 12.000000 17 | 13.000000 18 | 12.000000 19 | -------------------------------------------------------------------------------- /tests/tests2/87_dead_code.expect: -------------------------------------------------------------------------------- 1 | timeout=2 2 | timeout=1 3 | boo 4 | yeah 5 | twice 6 | once 7 | twice 8 | SEtwice 9 | SEonce 10 | SEtwice 11 | twice2 12 | once2 13 | twice2 14 | twice3 15 | once3 16 | twice3 17 | caseok 18 | caseok2 19 | g=1 20 | check 1 21 | g=2 22 | check 2 23 | g=3 24 | -------------------------------------------------------------------------------- /tests/pp/02.expect: -------------------------------------------------------------------------------- 1 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 2 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 3 | char c[2][6] = { "hello", "" }; 4 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 5 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 6 | -------------------------------------------------------------------------------- /tests/tests2/105_local_extern.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char *, ...); 2 | void f(void); 3 | void bar(void) { void f(void); f(); } 4 | void foo(void) { extern void f(void); f(); } 5 | void f(void) { printf("f\n"); } 6 | 7 | int main() 8 | { 9 | bar(); 10 | foo(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/tests2/35_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | short b; 7 | 8 | printf("%d %d\n", sizeof(char), sizeof(a)); 9 | printf("%d %d\n", sizeof(short), sizeof(b)); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tests/tests2/02_printf.expect: -------------------------------------------------------------------------------- 1 | Hello world 2 | Count = -5 3 | Count = -4 4 | Count = -3 5 | Count = -2 6 | Count = -1 7 | Count = 0 8 | Count = 1 9 | Count = 2 10 | Count = 3 11 | Count = 4 12 | Count = 5 13 | String 'hello', 'there' is 'hello', 'there' 14 | Character 'A' is 'A' 15 | Character 'a' is 'a' 16 | -------------------------------------------------------------------------------- /tests/tests2/44_scoped_declarations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | 7 | for (a = 0; a < 2; a++) 8 | { 9 | int b = a; 10 | } 11 | 12 | printf("it's all good\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tests/tests2/12_hashdefine.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FRED 12 4 | #define BLOGGS(x) (12*(x)) 5 | 6 | int main() 7 | { 8 | printf("%d\n", FRED); 9 | printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tests/tests2/45_empty_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count = 0; 6 | 7 | for (;;) 8 | { 9 | Count++; 10 | printf("%d\n", Count); 11 | if (Count >= 10) 12 | break; 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /tests/tests2/84_hex-float.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char *format, ...); 2 | 3 | #define ACPI_TYPE_INVALID 0x1E 4 | #define NUM_NS_TYPES ACPI_TYPE_INVALID+1 5 | int array[NUM_NS_TYPES]; 6 | 7 | #define n 0xe 8 | int main() 9 | { 10 | printf("n+1 = %d\n", n+1); 11 | // printf("n+1 = %d\n", 0xe+1); 12 | } 13 | -------------------------------------------------------------------------------- /tests/pp/pp-counter.expect: -------------------------------------------------------------------------------- 1 | X1 0 2 | X2 1 3 | X3 3 4 | X4 x 4 y 5 | X5 x 5 y 6 6 | X6 b 7 7 | X7 8 9 8 | X8 x 10 y x 10 y 11 x2 x 10 y 12 y2 13 9 | X9 x 14 y 15 x 14 y 15 16 x2 x 14 y 15 17 y2 18 10 | X10 19 19 20 x2 19 21 y2 22 11 | X11 23 23 24 x2 23 25 y2 26 12 | X12 "__COUNTER__" 13 | X13 x27 14 | X14 x__COUNTER__ 15 | X15 x2828 16 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define P(A,B) A ## B ; bob 4 | #define Q(A,B) A ## B+ 5 | 6 | int main(void) 7 | { 8 | int bob, jim = 21; 9 | bob = P(jim,) *= 2; 10 | printf("jim: %d, bob: %d\n", jim, bob); 11 | jim = 60 Q(+,)3; 12 | printf("jim: %d\n", jim); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /win32/include/winapi/poppack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(pop) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,1) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,2) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,4) 8 | #endif 9 | -------------------------------------------------------------------------------- /win32/include/winapi/pshpack8.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,8) 8 | #endif 9 | -------------------------------------------------------------------------------- /stab.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNU_STAB__ 2 | 3 | /* Indicate the GNU stab.h is in use. */ 4 | 5 | #define __GNU_STAB__ 6 | 7 | #define __define_stab(NAME, CODE, STRING) NAME=CODE, 8 | 9 | enum __stab_debug_code 10 | { 11 | #include "stab.def" 12 | LAST_UNUSED_STAB_CODE 13 | }; 14 | 15 | #undef __define_stab 16 | 17 | #endif /* __GNU_STAB_ */ 18 | -------------------------------------------------------------------------------- /tests/tests2/00_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | a = 42; 7 | printf("%d\n", a); 8 | 9 | int b = 64; 10 | printf("%d\n", b); 11 | 12 | int c = 12, d = 34; 13 | printf("%d, %d\n", c, d); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tests/tests2/97_utf8_string_literal.c: -------------------------------------------------------------------------------- 1 | // this file contains BMP chars encoded in UTF-8 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | wchar_t s[] = L"hello$$你好¢¢世界€€world"; 8 | wchar_t *p; 9 | for (p = s; *p; p++) printf("%04X ", (unsigned) *p); 10 | printf("\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/tests2/31_args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int Count; 6 | 7 | printf("hello world %d\n", argc); 8 | for (Count = 1; Count < argc; Count++) 9 | printf("arg %d: %s\n", Count, argv[Count]); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tests/tests2/37_sprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char Buf[100]; 6 | int Count; 7 | 8 | for (Count = 1; Count <= 20; Count++) 9 | { 10 | sprintf(Buf, "->%02d<-\n", Count); 11 | printf("%s", Buf); 12 | } 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tests/tests2/01_comment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello\n"); 6 | printf("Hello\n"); /* this is a comment */ printf("Hello\n"); 7 | printf("Hello\n"); 8 | // this is also a comment sayhello(); 9 | printf("Hello\n"); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tests/pp/17.c: -------------------------------------------------------------------------------- 1 | #define STR1(u) # u 2 | #define pass(a) a 3 | #define __ASM_REG(reg) STR1(one##reg) 4 | #define _ASM_DX __ASM_REG(tok) 5 | X162 pass(__ASM_REG(tok)) 6 | X161 pass(_ASM_DX) 7 | X163 pass(STR1(one##tok)) 8 | 9 | X170 pass(x ## y) 10 | X171 pass(x pass(##) y) 11 | 12 | #define Y(x) Z(x) 13 | #define X Y 14 | X180 return X(X(1)); 15 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | int b; 7 | double c; 8 | 9 | printf("%d\n", sizeof(a)); 10 | printf("%d\n", sizeof(b)); 11 | printf("%d\n", sizeof(c)); 12 | 13 | printf("%d\n", sizeof(!a)); 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /lib/alloca-arm.S: -------------------------------------------------------------------------------- 1 | .text 2 | .align 2 3 | .global alloca 4 | .type alloca, %function 5 | alloca: 6 | #ifdef __TINYC__ 7 | .int 0xe060d00d 8 | .int 0xe3cdd007 9 | .int 0xe1a0000d 10 | .int 0xe1a0f00e 11 | #else 12 | rsb sp, r0, sp 13 | bic sp, sp, #7 14 | mov r0, sp 15 | mov pc, lr 16 | #endif 17 | .size alloca, .-alloca 18 | -------------------------------------------------------------------------------- /tests/tests2/91_ptr_longlong_arith32.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | char t[] = "012345678"; 3 | 4 | int main(void) 5 | { 6 | char *data = t; 7 | unsigned long long r = 4; 8 | unsigned a = 5; 9 | unsigned long long b = 12; 10 | 11 | *(unsigned*)(data + r) += a - b; 12 | 13 | printf("data = \"%s\"\n", data); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /win32/include/vadefs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_VADEFS 7 | #define _INC_VADEFS 8 | 9 | //!__TINYC__: GNUC specific stuff removed 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /tests/tests2/08_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | while (a < 100) 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tests/tests2/09_do_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | do 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } while (a < 100); 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tests/tests2/14_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 1; 6 | 7 | if (a) 8 | printf("a is true\n"); 9 | else 10 | printf("a is false\n"); 11 | 12 | int b = 0; 13 | if (b) 14 | printf("b is true\n"); 15 | else 16 | printf("b is false\n"); 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved); 6 | 7 | BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) 8 | { 9 | BOOL bRet; 10 | bRet = DllMain (hDll, dwReason, lpReserved); 11 | return bRet; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/tests2/15_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial(int i) 4 | { 5 | if (i < 2) 6 | return i; 7 | else 8 | return i * factorial(i - 1); 9 | } 10 | 11 | int main() 12 | { 13 | int Count; 14 | 15 | for (Count = 1; Count <= 10; Count++) 16 | printf("%d\n", factorial(Count)); 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tests/tests2/16_nesting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x, y, z; 6 | 7 | for (x = 0; x < 2; x++) 8 | { 9 | for (y = 0; y < 3; y++) 10 | { 11 | for (z = 0; z < 3; z++) 12 | { 13 | printf("%d %d %d\n", x, y, z); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /win32/examples/dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // dll.c - Windows DLL example - dynamically linked part 4 | // 5 | 6 | #include 7 | 8 | __declspec(dllexport) const char *hello_data = "(not set)"; 9 | 10 | __declspec(dllexport) void hello_func (void) 11 | { 12 | MessageBox (0, hello_data, "From DLL", MB_ICONINFORMATION); 13 | } 14 | -------------------------------------------------------------------------------- /include/varargs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _VARARGS_H 7 | #define _VARARGS_H 8 | 9 | #error "TinyCC no longer implements ." 10 | #error "Revise your code to use ." 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tests/tests2/26_character_constants.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("%d\n", '\1'); 6 | printf("%d\n", '\10'); 7 | printf("%d\n", '\100'); 8 | printf("%d\n", '\x01'); 9 | printf("%d\n", '\x0e'); 10 | printf("%d\n", '\x10'); 11 | printf("%d\n", '\x40'); 12 | printf("test \x40\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /win32/include/mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * mem.h maps to string.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/tests2/05_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | int Array[10]; 7 | 8 | for (Count = 1; Count <= 10; Count++) 9 | { 10 | Array[Count-1] = Count * Count; 11 | } 12 | 13 | for (Count = 0; Count < 10; Count++) 14 | { 15 | printf("%d\n", Array[Count]); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /win32/include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * unistd.h maps (roughly) to io.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /include/stdalign.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDALIGN_H 2 | #define _STDALIGN_H 3 | 4 | #if __STDC_VERSION__ < 201112L && (defined(__GNUC__) || defined(__TINYC__)) 5 | # define _Alignas(t) __attribute__((__aligned__(t))) 6 | # define _Alignof(t) __alignof__(t) 7 | #endif 8 | 9 | #define alignas _Alignas 10 | #define alignof _Alignof 11 | 12 | #define __alignas_is_defined 1 13 | #define __alignof_is_defined 1 14 | 15 | #endif /* _STDALIGN_H */ 16 | 17 | -------------------------------------------------------------------------------- /tests/tests2/13_integer_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 24680; 6 | int b = 01234567; 7 | int c = 0x2468ac; 8 | int d = 0x2468AC; 9 | int e = 0b010101010101; 10 | 11 | printf("%d\n", a); 12 | printf("%d\n", b); 13 | printf("%d\n", c); 14 | printf("%d\n", d); 15 | printf("%d\n", e); 16 | 17 | return 0; 18 | } 19 | 20 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 21 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4]; 6 | 7 | a[0] = 12; 8 | a[1] = 23; 9 | a[2] = 34; 10 | a[3] = 45; 11 | 12 | printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); 13 | 14 | int b[4]; 15 | 16 | b = a; 17 | 18 | printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /win32/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This fcntl.h maps to the root fcntl.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /win32/include/sys/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This file.h maps to the root fcntl.h 10 | * TODO? 11 | */ 12 | #ifndef __STRICT_ANSI__ 13 | #include 14 | #endif 15 | -------------------------------------------------------------------------------- /tests/tests2/47_switch_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(int x) 4 | { 5 | switch (x) 6 | { 7 | case 1: printf("1\n"); return; 8 | case 2: printf("2\n"); break; 9 | case 3: printf("3\n"); return; 10 | } 11 | 12 | printf("out\n"); 13 | } 14 | 15 | int main() 16 | { 17 | fred(1); 18 | fred(2); 19 | fred(3); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tests/tests2/40_stdio.expect: -------------------------------------------------------------------------------- 1 | hello 2 | ch: 104 'h' 3 | ch: 101 'e' 4 | ch: 108 'l' 5 | ch: 108 'l' 6 | ch: 111 'o' 7 | ch: 10 '.' 8 | ch: 104 'h' 9 | ch: 101 'e' 10 | ch: 108 'l' 11 | ch: 108 'l' 12 | ch: 111 'o' 13 | ch: 10 '.' 14 | ch: 104 'h' 15 | ch: 101 'e' 16 | ch: 108 'l' 17 | ch: 108 'l' 18 | ch: 111 'o' 19 | ch: 10 '.' 20 | ch: 104 'h' 21 | ch: 101 'e' 22 | ch: 108 'l' 23 | ch: 108 'l' 24 | ch: 111 'o' 25 | ch: 10 '.' 26 | x: hello 27 | x: hello 28 | -------------------------------------------------------------------------------- /tests/tests2/72_long_long_constant.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long long int res = 0; 6 | 7 | if (res < -2147483648LL) { 8 | printf("Error: 0 < -2147483648\n"); 9 | return 1; 10 | } 11 | else 12 | if (2147483647LL < res) { 13 | printf("Error: 2147483647 < 0\n"); 14 | return 2; 15 | } 16 | else 17 | printf("long long constant test ok.\n"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /win32/include/winapi/ws2ipdef.h: -------------------------------------------------------------------------------- 1 | #ifndef _WS2IPDEF_H 2 | #define _WS2IPDEF_H 3 | 4 | #if __GNUC__ >=3 5 | #pragma GCC system_header 6 | #endif 7 | 8 | #include 9 | 10 | struct ip_mreq { 11 | struct in_addr imr_multiaddr; 12 | struct in_addr imr_interface; 13 | }; 14 | 15 | struct ip_mreq_source { 16 | struct in_addr imr_multiaddr; 17 | struct in_addr imr_sourceaddr; 18 | struct in_addr imr_interface; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /tests/tests2/48_nested_break.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | char b; 7 | 8 | a = 0; 9 | while (a < 2) 10 | { 11 | printf("%d", a++); 12 | break; 13 | 14 | b = 'A'; 15 | while (b < 'C') 16 | { 17 | printf("%c", b++); 18 | } 19 | printf("e"); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | 26 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 27 | -------------------------------------------------------------------------------- /tests/42test.h: -------------------------------------------------------------------------------- 1 | /* This file is to test compute #include directives. It's named so 2 | that it starts with a pre-processing number which isn't a valid 3 | number (42test.h). Including this must work. */ 4 | #ifndef INC42_FIRST 5 | int have_included_42test_h; 6 | #define INC42_FIRST 7 | #elif !defined INC42_SECOND 8 | #define INC42_SECOND 9 | int have_included_42test_h_second; 10 | #else 11 | #define INC42_THIRD 12 | int have_included_42test_h_third; 13 | #endif 14 | -------------------------------------------------------------------------------- /win32/examples/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // atoi() 3 | 4 | int fib(n) 5 | { 6 | if (n <= 2) 7 | return 1; 8 | else 9 | return fib(n-1) + fib(n-2); 10 | } 11 | 12 | int main(int argc, char **argv) 13 | { 14 | int n; 15 | if (argc < 2) { 16 | printf("usage: fib n\n" 17 | "Compute nth Fibonacci number\n"); 18 | return 1; 19 | } 20 | 21 | n = atoi(argv[1]); 22 | printf("fib(%d) = %d\n", n, fib(n)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/tests2/02_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello world\n"); 6 | 7 | int Count; 8 | for (Count = -5; Count <= 5; Count++) 9 | printf("Count = %d\n", Count); 10 | 11 | printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 12 | printf("Character 'A' is '%c'\n", 65); 13 | printf("Character 'a' is '%c'\n", 'a'); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct point 4 | { 5 | double x; 6 | double y; 7 | }; 8 | 9 | struct point point_array[100]; 10 | 11 | int main() 12 | { 13 | int my_point = 10; 14 | 15 | point_array[my_point].x = 12.34; 16 | point_array[my_point].y = 56.78; 17 | 18 | printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /examples/ex3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(n) 4 | { 5 | if (n <= 2) 6 | return 1; 7 | else 8 | return fib(n-1) + fib(n-2); 9 | } 10 | 11 | int main(int argc, char **argv) 12 | { 13 | int n; 14 | if (argc < 2) { 15 | printf("usage: fib n\n" 16 | "Compute nth Fibonacci number\n"); 17 | return 1; 18 | } 19 | 20 | n = atoi(argv[1]); 21 | printf("fib(%d) = %d\n", n, fib(n, 2)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/pp/03.c: -------------------------------------------------------------------------------- 1 | #define str(s) # s 2 | #define xstr(s) str(s) 3 | #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ 4 | x ## s, x ## t) 5 | #define INCFILE(n) vers ## n 6 | #define glue(a, b) a ## b 7 | #define xglue(a, b) glue(a, b) 8 | #define HIGHLOW "hello" 9 | #define LOW LOW ", world" 10 | debug(1, 2); 11 | fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away 12 | == 0) str(: @\n), s); 13 | \#include xstr(INCFILE(2).h) 14 | glue(HIGH, LOW); 15 | xglue(HIGH, LOW) 16 | -------------------------------------------------------------------------------- /tests/tests2/103_implicit_memmove.c: -------------------------------------------------------------------------------- 1 | /* Test that the memmove TCC is emitting for the struct copy 2 | and hence implicitely declares can be declared properly also 3 | later. */ 4 | struct S { int a,b,c,d, e[1024];}; 5 | int foo (struct S *a, struct S *b) 6 | { 7 | *a = *b; 8 | return 0; 9 | } 10 | 11 | void *memmove(void*,void*,long); 12 | void foo2 (struct S *a, struct S *b) 13 | { 14 | memmove(a, b, sizeof *a); 15 | } 16 | 17 | int main() 18 | { 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/tests2/20_pointer_comparison.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int *d; 8 | int *e; 9 | d = &a; 10 | e = &b; 11 | a = 12; 12 | b = 34; 13 | printf("%d\n", *d); 14 | printf("%d\n", *e); 15 | printf("%d\n", d == e); 16 | printf("%d\n", d != e); 17 | d = e; 18 | printf("%d\n", d == e); 19 | printf("%d\n", d != e); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tests/pp/15.c: -------------------------------------------------------------------------------- 1 | // insert a space between two tokens if otherwise they 2 | // would form a single token when read back 3 | 4 | #define n(x) x 5 | 6 | return (n(long)n(double))d; 7 | return n(A)n(++)n(+)n(B); 8 | return n(A)n(+)n(++)n(B); 9 | return n(A)n(++)n(+)n(+)n(B); 10 | 11 | // not a hex float 12 | return n(0x1E)n(-1); 13 | 14 | // unlike gcc but correct 15 | // XXX: return n(x)+n(x)-n(1)+n(1)-2; 16 | 17 | // unlike gcc, but cannot appear in valid C 18 | // XXX: return n(x)n(x)n(1)n(2)n(x); 19 | -------------------------------------------------------------------------------- /tests/tests2/19_pointer_arithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int *b; 7 | int *c; 8 | 9 | a = 42; 10 | b = &a; 11 | c = NULL; 12 | 13 | printf("%d\n", *b); 14 | 15 | if (b == NULL) 16 | printf("b is NULL\n"); 17 | else 18 | printf("b is not NULL\n"); 19 | 20 | if (c == NULL) 21 | printf("c is NULL\n"); 22 | else 23 | printf("c is not NULL\n"); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /tests/tests2/07_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int myfunc(int x) 4 | { 5 | return x * x; 6 | } 7 | 8 | void vfunc(int a) 9 | { 10 | printf("a=%d\n", a); 11 | } 12 | 13 | void qfunc() 14 | { 15 | printf("qfunc()\n"); 16 | } 17 | 18 | void zfunc() 19 | { 20 | ((void (*)(void))0) (); 21 | } 22 | 23 | int main() 24 | { 25 | printf("%d\n", myfunc(3)); 26 | printf("%d\n", myfunc(4)); 27 | 28 | vfunc(1234); 29 | 30 | qfunc(); 31 | 32 | return 0; 33 | } 34 | 35 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 36 | -------------------------------------------------------------------------------- /tests/tests2/42_function_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | /* To test what this is supposed to test the destination function 12 | (fprint here) must not be called directly anywhere in the test. */ 13 | int (*fprintfptr)(FILE *, const char *, ...) = &fprintf; 14 | 15 | int main() 16 | { 17 | fprintfptr(stdout, "%d\n", (*f)(24)); 18 | 19 | return 0; 20 | } 21 | 22 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 23 | -------------------------------------------------------------------------------- /win32/examples/hello_dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // HELLO_DLL.C - Windows DLL example - main application part 4 | // 5 | 6 | #include 7 | 8 | void hello_func (void); 9 | __declspec(dllimport) extern const char *hello_data; 10 | 11 | int WINAPI WinMain( 12 | HINSTANCE hInstance, 13 | HINSTANCE hPrevInstance, 14 | LPSTR lpCmdLine, 15 | int nCmdShow) 16 | { 17 | hello_data = "Hello World!"; 18 | hello_func(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/tests2/36_array_initialisers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 8 | 9 | for (Count = 0; Count < 10; Count++) 10 | printf("%d: %d\n", Count, Array[Count]); 11 | 12 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 13 | 14 | for (Count = 0; Count < 10; Count++) 15 | printf("%d: %d\n", Count, Array2[Count]); 16 | 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tests/tests2/51_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int fred = 1234; 4 | static int joe; 5 | 6 | void henry() 7 | { 8 | static int fred = 4567; 9 | 10 | printf("%d\n", fred); 11 | fred++; 12 | } 13 | 14 | int main() 15 | { 16 | printf("%d\n", fred); 17 | henry(); 18 | henry(); 19 | henry(); 20 | henry(); 21 | printf("%d\n", fred); 22 | fred = 8901; 23 | joe = 2345; 24 | printf("%d\n", fred); 25 | printf("%d\n", joe); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /tests/tests2/52_unnamed_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred { a, b, c }; 4 | 5 | int main() 6 | { 7 | printf("a=%d\n", a); 8 | printf("b=%d\n", b); 9 | printf("c=%d\n", c); 10 | 11 | enum fred d; 12 | 13 | typedef enum { e, f, g } h; 14 | typedef enum { i, j, k } m; 15 | 16 | printf("e=%d\n", e); 17 | printf("f=%d\n", f); 18 | printf("g=%d\n", g); 19 | 20 | printf("i=%d\n", i); 21 | printf("j=%d\n", j); 22 | printf("k=%d\n", k); 23 | 24 | return 0; 25 | } 26 | 27 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 28 | -------------------------------------------------------------------------------- /tests/pp/20.c: -------------------------------------------------------------------------------- 1 | /* Various things I encountered while hacking the pre processor */ 2 | #define wrap(x) x 3 | #define pr_warning(fmt, ...) printk(KERN_WARNING fmt, ##__VA_ARGS__) 4 | #define pr_warn(x,y) pr_warning(x,y) 5 | #define net_ratelimited_function(function, ...) function(__VA_ARGS__) 6 | X1 net_ratelimited_function(pr_warn, "pipapo", bla); 7 | X2 net_ratelimited_function(wrap(pr_warn), "bla", foo); 8 | #define two m n 9 | #define chain4(a,b,c,d) a ## b ## c ## d 10 | X2 chain4(two,o,p,q) 11 | X3 chain4(o,two,p,q) 12 | X4 chain4(o,p,two,q) 13 | X5 chain4(o,p,q,two) 14 | -------------------------------------------------------------------------------- /win32/include/sec_api/crtdbg_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CRTDBG_S 8 | #define _INC_CRTDBG_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #define _dupenv_s_dbg(ps1,size,s2,t,f,l) _dupenv_s(ps1,size,s2) 15 | #define _wdupenv_s_dbg(ps1,size,s2,t,f,l) _wdupenv_s(ps1,size,s2) 16 | 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /tests/tests2/06_case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 4; Count++) 8 | { 9 | printf("%d\n", Count); 10 | switch (Count) 11 | { 12 | case 1: 13 | printf("%d\n", 1); 14 | break; 15 | 16 | case 2: 17 | printf("%d\n", 2); 18 | break; 19 | 20 | default: 21 | printf("%d\n", 0); 22 | break; 23 | } 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 30 | -------------------------------------------------------------------------------- /tests/pp/21.c: -------------------------------------------------------------------------------- 1 | /* accept 'defined' as result of substitution */ 2 | 3 | ----- 1 ------ 4 | #define AAA 2 5 | #define BBB 6 | #define CCC (defined ( AAA ) && AAA > 1 && !defined BBB) 7 | #if !CCC 8 | OK 9 | #else 10 | NOT OK 11 | #endif 12 | 13 | ----- 2 ------ 14 | #undef BBB 15 | #if CCC 16 | OK 17 | #else 18 | NOT OK 19 | #endif 20 | 21 | ----- 3 ------ 22 | #define DEFINED defined 23 | #define DDD (DEFINED ( AAA ) && AAA > 1 && !DEFINED BBB) 24 | #if (DDD) 25 | OK 26 | #else 27 | NOT OK 28 | #endif 29 | 30 | ----- 4 ------ 31 | #undef AAA 32 | #if !(DDD) 33 | OK 34 | #else 35 | NOT OK 36 | #endif 37 | -------------------------------------------------------------------------------- /tests/tests2/38_multiple_array_index.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4][4]; 6 | int b = 0; 7 | int x; 8 | int y; 9 | 10 | for (x = 0; x < 4; x++) 11 | { 12 | for (y = 0; y < 4; y++) 13 | { 14 | b++; 15 | a[x][y] = b; 16 | } 17 | } 18 | 19 | for (x = 0; x < 4; x++) 20 | { 21 | printf("x=%d: ", x); 22 | for (y = 0; y < 4; y++) 23 | { 24 | printf("%d ", a[x][y]); 25 | } 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 33 | -------------------------------------------------------------------------------- /lib/alloca86.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %edx 8 | pop %eax 9 | add $3,%eax 10 | and $-4,%eax 11 | jz p3 12 | 13 | #ifdef _WIN32 14 | p1: 15 | cmp $4096,%eax 16 | jbe p2 17 | test %eax,-4096(%esp) 18 | sub $4096,%esp 19 | sub $4096,%eax 20 | jmp p1 21 | p2: 22 | #endif 23 | 24 | sub %eax,%esp 25 | mov %esp,%eax 26 | p3: 27 | push %edx 28 | push %edx 29 | ret 30 | 31 | /* ---------------------------------------------- */ 32 | -------------------------------------------------------------------------------- /tests/tests2/21_char_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 'a'; 6 | char y = x; 7 | 8 | char *a = "hello"; 9 | 10 | printf("%s\n", a); 11 | 12 | int c; 13 | c = *a; 14 | 15 | char *b; 16 | for (b = a; *b != 0; b++) 17 | printf("%c: %d\n", *b, *b); 18 | 19 | char destarray[10]; 20 | char *dest = &destarray[0]; 21 | char *src = a; 22 | 23 | while (*src != 0) 24 | *dest++ = *src++; 25 | 26 | *dest = 0; 27 | 28 | printf("copied string is %s\n", destarray); 29 | 30 | return 0; 31 | } 32 | 33 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 34 | -------------------------------------------------------------------------------- /tests/tests2/80_flexarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct wchar { 3 | char *data; char mem[]; 4 | }; 5 | struct wint { 6 | char *data; int mem[]; 7 | }; 8 | int f1char (void) { 9 | char s[9]="nonono"; 10 | struct wchar q = {"bugs"}; 11 | return !s[0]; 12 | } 13 | int f1int (void) { 14 | char s[9]="nonono"; 15 | struct wint q = {"bugs"}; 16 | return !s[0]; 17 | } 18 | int main (void) { 19 | char s[9]="nonono"; 20 | static struct wchar q = {"bugs", {'c'}}; 21 | //printf ("tcc has %s %s\n", s, q.data); 22 | if (f1char() || f1int()) 23 | printf ("bla\n"); 24 | return !s[0]; 25 | } 26 | -------------------------------------------------------------------------------- /tests/tests2/03_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct fred 4 | { 5 | int boris; 6 | int natasha; 7 | }; 8 | 9 | int main() 10 | { 11 | struct fred bloggs; 12 | 13 | bloggs.boris = 12; 14 | bloggs.natasha = 34; 15 | 16 | printf("%d\n", bloggs.boris); 17 | printf("%d\n", bloggs.natasha); 18 | 19 | struct fred jones[2]; 20 | jones[0].boris = 12; 21 | jones[0].natasha = 34; 22 | jones[1].boris = 56; 23 | jones[1].natasha = 78; 24 | 25 | printf("%d\n", jones[0].boris); 26 | printf("%d\n", jones[0].natasha); 27 | printf("%d\n", jones[1].boris); 28 | printf("%d\n", jones[1].natasha); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/tests2/50_logical_second_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred() 4 | { 5 | printf("fred\n"); 6 | return 0; 7 | } 8 | 9 | int joe() 10 | { 11 | printf("joe\n"); 12 | return 1; 13 | } 14 | 15 | int main() 16 | { 17 | printf("%d\n", fred() && joe()); 18 | printf("%d\n", fred() || joe()); 19 | printf("%d\n", joe() && fred()); 20 | printf("%d\n", joe() || fred()); 21 | printf("%d\n", fred() && (1 + joe())); 22 | printf("%d\n", fred() || (0 + joe())); 23 | printf("%d\n", joe() && (0 + fred())); 24 | printf("%d\n", joe() || (1 + fred())); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /lib/alloca86_64.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %rdx 8 | #ifdef _WIN32 9 | mov %rcx,%rax 10 | #else 11 | mov %rdi,%rax 12 | #endif 13 | add $15,%rax 14 | and $-16,%rax 15 | jz p3 16 | 17 | #ifdef _WIN32 18 | p1: 19 | cmp $4096,%rax 20 | jbe p2 21 | test %rax,-4096(%rsp) 22 | sub $4096,%rsp 23 | sub $4096,%rax 24 | jmp p1 25 | p2: 26 | #endif 27 | 28 | sub %rax,%rsp 29 | mov %rsp,%rax 30 | p3: 31 | push %rdx 32 | ret 33 | 34 | /* ---------------------------------------------- */ 35 | -------------------------------------------------------------------------------- /tests/pp/18.c: -------------------------------------------------------------------------------- 1 | #define M_RETI_ARG27(x,y,z,aa, ...) aa 2 | #define M_RET_ARG27(...) M_RETI_ARG27(__VA_ARGS__) 3 | #define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 0, useless) 4 | #define M_EMPTYI_DETECT(...) 0, 1, 5 | #define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ () ) 6 | #define EX 7 | #define empty(x) 8 | #define fnlike(x) yeah x 9 | /* If the following macro is called with empty arg (X183), the use 10 | of 'x' between fnlike and '(' doesn't hinder the recognition of this 11 | being a further fnlike macro invocation. */ 12 | #define usefnlike(x) fnlike x (x) 13 | X181 M_EMPTYI_P_C1() 14 | X182 M_EMPTYI_P_C1(x) 15 | X183 usefnlike() 16 | -------------------------------------------------------------------------------- /tests/asm-c-connect-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined _WIN32 && !defined __TINYC__ 4 | # define _ "_" 5 | #else 6 | # define _ 7 | #endif 8 | 9 | int x3(void) 10 | { 11 | printf(" x3"); 12 | return 3; 13 | } 14 | 15 | /* That callx4 is defined globally (as if ".globl callx4") 16 | is a TCC extension. GCC doesn't behave like this. */ 17 | void callx4(void); 18 | __asm__(_"callx4: call "_"x4; ret;" 19 | #ifndef __TINYC__ 20 | " .global "_"callx4" 21 | #endif 22 | ); 23 | 24 | extern void x5(void); 25 | 26 | void callx5_again(void); 27 | void callx5_again(void) 28 | { 29 | x5(); 30 | asm("call "_"x6"); 31 | } 32 | 33 | static void x6() 34 | { 35 | printf(" x6-2"); 36 | } 37 | -------------------------------------------------------------------------------- /tests/pp/pp-counter.c: -------------------------------------------------------------------------------- 1 | X1 __COUNTER__ 2 | X2 __COUNTER__ 3 | #if __COUNTER__ 4 | X3 __COUNTER__ 5 | #endif 6 | #define pass(x) x 7 | #define a x __COUNTER__ y 8 | #define a2 pass(__COUNTER__) 9 | #define f(c) c __COUNTER__ 10 | #define apply(d) d d __COUNTER__ x2 f(d) y2 __COUNTER__ 11 | #define _paste(a,b) a ## b 12 | #define paste(a,b) _paste(a,b) 13 | #define _paste3(a,b,c) a ## b ## c 14 | #define doublepaste(a,b) _paste3(a,b,b) 15 | #define str(x) #x 16 | X4 a 17 | X5 f(a) 18 | X6 f(b) 19 | X7 f(__COUNTER__) 20 | X8 apply(a) 21 | X9 apply(f(a)) 22 | X10 apply(__COUNTER__) 23 | X11 apply(a2) 24 | X12 str(__COUNTER__) 25 | X13 paste(x,__COUNTER__) 26 | X14 _paste(x,__COUNTER__) 27 | X15 doublepaste(x,__COUNTER__) 28 | -------------------------------------------------------------------------------- /tests/pp/02.c: -------------------------------------------------------------------------------- 1 | #define x 3 2 | #define f(a) f(x * (a)) 3 | #undef x 4 | #define x 2 5 | #define g f 6 | #define z z[0] 7 | #define h g(~ 8 | #define m(a) a(w) 9 | #define w 0,1 10 | #define t(a) a 11 | #define p() int 12 | #define q(x) x 13 | #define r(x,y) x ## y 14 | #define str(x) # x 15 | f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); 16 | g(x+(3,4)-w) | h 5) & m 17 | (f)^m(m); 18 | char c[2][6] = { str(hello), str() }; 19 | /* 20 | * f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); 21 | * f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); 22 | * char c[2][6] = { "hello", "" }; 23 | */ 24 | #define L21 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1); 25 | #define L22 g(x+(3,4)-w) | h 5) & m\ 26 | (f)^m(m); 27 | L21 28 | L22 29 | -------------------------------------------------------------------------------- /win32/include/iso646.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the TinyCC package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | /* 8 | * ISO C Standard: 7.9 Alternative spellings 9 | */ 10 | 11 | #ifndef _ISO646_H_ 12 | #define _ISO646_H_ 13 | 14 | #define and && 15 | #define and_eq &= 16 | #define bitand & 17 | #define bitor | 18 | #define compl ~ 19 | #define not ! 20 | #define not_eq != 21 | #define or || 22 | #define or_eq |= 23 | #define xor ^ 24 | #define xor_eq ^= 25 | 26 | #endif /* _ISO646_H_ */ 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/ex4.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 2 | #include 3 | #include 4 | #include 5 | 6 | /* Yes, TCC can use X11 too ! */ 7 | 8 | int main(int argc, char **argv) 9 | { 10 | Display *display; 11 | Screen *screen; 12 | 13 | display = XOpenDisplay(""); 14 | if (!display) { 15 | fprintf(stderr, "Could not open X11 display\n"); 16 | exit(1); 17 | } 18 | printf("X11 display opened.\n"); 19 | screen = XScreenOfDisplay(display, 0); 20 | printf("width = %d\nheight = %d\ndepth = %d\n", 21 | screen->width, 22 | screen->height, 23 | screen->root_depth); 24 | XCloseDisplay(display); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/pp/11.c: -------------------------------------------------------------------------------- 1 | #define D1(s, ...) s 2 | #define D2(s, ...) s D1(__VA_ARGS__) 3 | #define D3(s, ...) s D2(__VA_ARGS__) 4 | #define D4(s, ...) s D3(__VA_ARGS__) 5 | 6 | D1(a) 7 | D2(a, b) 8 | D3(a, b, c) 9 | D4(a, b, c, d) 10 | 11 | x D4(a, b, c, d) y 12 | x D4(a, b, c) y 13 | x D4(a, b) y 14 | x D4(a) y 15 | x D4() y 16 | 17 | #define GNU_COMMA(X,Y...) X,## Y 18 | 19 | x GNU_COMMA(A,B,C) y 20 | x GNU_COMMA(A,B) y 21 | x GNU_COMMA(A) y 22 | x GNU_COMMA() y 23 | 24 | #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 25 | #define ___sun_attr_inner(__a) __sun_attr_##__a 26 | #define __sun_attr__(__a) ___sun_attr_inner __a 27 | #define __NORETURN __sun_attr__((__noreturn__)) 28 | __NORETURN 29 | #define X(...) 30 | #define Y(...) 1 __VA_ARGS__ 2 31 | Y(X X() ()) 32 | -------------------------------------------------------------------------------- /win32/include/share.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SHARE 7 | #define _INC_SHARE 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #define _SH_COMPAT 0x00 14 | #define _SH_DENYRW 0x10 15 | #define _SH_DENYWR 0x20 16 | #define _SH_DENYRD 0x30 17 | #define _SH_DENYNO 0x40 18 | #define _SH_SECURE 0x80 19 | 20 | #ifndef NO_OLDNAMES 21 | #define SH_COMPAT _SH_COMPAT 22 | #define SH_DENYRW _SH_DENYRW 23 | #define SH_DENYWR _SH_DENYWR 24 | #define SH_DENYRD _SH_DENYRD 25 | #define SH_DENYNO _SH_DENYNO 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /tests/tests2/77_push_pop_macro.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | /* must not affect how #pragma ppop_macro works */ 6 | #define pop_macro foobar1 7 | 8 | /* must not affect how #pragma push_macro works */ 9 | #define push_macro foobar2 10 | 11 | #undef abort 12 | #define abort "111" 13 | printf("abort = %s\n", abort); 14 | 15 | #pragma push_macro("abort") 16 | #undef abort 17 | #define abort "222" 18 | printf("abort = %s\n", abort); 19 | 20 | #pragma push_macro("abort") 21 | #undef abort 22 | #define abort "333" 23 | printf("abort = %s\n", abort); 24 | 25 | #pragma pop_macro("abort") 26 | printf("abort = %s\n", abort); 27 | 28 | #pragma pop_macro("abort") 29 | printf("abort = %s\n", abort); 30 | } 31 | -------------------------------------------------------------------------------- /win32/include/sys/locking.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCKING 7 | #define _INC_LOCKING 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | /* All the headers include this file. */ 14 | #include <_mingw.h> 15 | 16 | #define _LK_UNLCK 0 17 | #define _LK_LOCK 1 18 | #define _LK_NBLCK 2 19 | #define _LK_RLCK 3 20 | #define _LK_NBRLCK 4 21 | 22 | #ifndef NO_OLDNAMES 23 | #define LK_UNLCK _LK_UNLCK 24 | #define LK_LOCK _LK_LOCK 25 | #define LK_NBLCK _LK_NBLCK 26 | #define LK_RLCK _LK_RLCK 27 | #define LK_NBRLCK _LK_NBRLCK 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /tests/tests2/100_c99array-decls.c: -------------------------------------------------------------------------------- 1 | void foo(int [5]); 2 | void fooc(int x[const 5]); 3 | void foos(int x[static 5]); 4 | void foov(int x[volatile 5]); 5 | void foor(int x[restrict 5]); 6 | void fooc(int [const 5]); 7 | void foos(int [static 5]); 8 | void foov(int [volatile 5]); 9 | void foor(int [restrict 5]); 10 | void fooc(int (* const x)); 11 | void foos(int *x); 12 | void foov(int * volatile x); 13 | void foor(int * restrict x); 14 | void fooc(int x[volatile 5]) 15 | { 16 | x[3] = 42; 17 | #ifdef INVALID 18 | x = 0; 19 | #endif 20 | } 21 | void foovm(int x[const *]); 22 | void foovm(int * const x); 23 | #ifdef INVALID 24 | void wrongc(int x[3][const 4]); 25 | void wrongvm(int x[static *]); 26 | void foovm(int x[const *]) 27 | { 28 | x[2] = 1; 29 | } 30 | #endif 31 | int main() 32 | { 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /win32/include/sec_api/sys/timeb_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _TIMEB_H_S 8 | #define _TIMEB_H_S 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #if defined(MINGW_HAS_SECURE_API) 17 | 18 | #ifdef _USE_32BIT_TIME_T 19 | #define _ftime_s _ftime32_s 20 | #else 21 | #define _ftime_s _ftime64_s 22 | #endif 23 | 24 | _CRTIMP errno_t __cdecl _ftime32_s(struct __timeb32 *_Time); 25 | #if _INTEGRAL_MAX_BITS >= 64 26 | _CRTIMP errno_t __cdecl _ftime64_s(struct __timeb64 *_Time); 27 | #endif 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /tests/tests2/70_floating_point_literals.expect: -------------------------------------------------------------------------------- 1 | 0.123000 2 | 122999996416.000000 3 | 0.000000 4 | 122999996416.000000 5 | 6 | 123.123001 7 | 123122997002240.000000 8 | 0.000000 9 | 123122997002240.000000 10 | 11 | 123.000000 12 | 123000003231744.000000 13 | 0.000000 14 | 123000003231744.000000 15 | 16 | 123000003231744.000000 17 | 0.000000 18 | 123000003231744.000000 19 | 20 | 21 | 428.000000 22 | 0.000026 23 | 428.000000 24 | 25 | 1756112.000000 26 | 0.104672 27 | 1756592.000000 28 | 29 | 1753088.000000 30 | 0.104492 31 | 1753088.000000 32 | 33 | 1753088.000000 34 | 0.104492 35 | 1753088.000000 36 | 37 | 38 | 3424.000000 39 | 0.000204 40 | 3424.000000 41 | 42 | 1756112.000000 43 | 0.104672 44 | 1756112.000000 45 | 46 | 1753088.000000 47 | 0.104492 48 | 1753088.000000 49 | 50 | 1753088.000000 51 | 0.104492 52 | 1753088.000000 53 | 54 | -------------------------------------------------------------------------------- /tests/tests2/10_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct ziggy 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | } bolshevic; 9 | 10 | int main() 11 | { 12 | int a; 13 | int *b; 14 | int c; 15 | 16 | a = 42; 17 | b = &a; 18 | printf("a = %d\n", *b); 19 | 20 | bolshevic.a = 12; 21 | bolshevic.b = 34; 22 | bolshevic.c = 56; 23 | 24 | printf("bolshevic.a = %d\n", bolshevic.a); 25 | printf("bolshevic.b = %d\n", bolshevic.b); 26 | printf("bolshevic.c = %d\n", bolshevic.c); 27 | 28 | struct ziggy *tsar = &bolshevic; 29 | 30 | printf("tsar->a = %d\n", tsar->a); 31 | printf("tsar->b = %d\n", tsar->b); 32 | printf("tsar->c = %d\n", tsar->c); 33 | 34 | b = &(bolshevic.b); 35 | printf("bolshevic.b = %d\n", *b); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tests/tests2/24_math_library.c: -------------------------------------------------------------------------------- 1 | #define _ISOC99_SOURCE 1 2 | 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | printf("%f\n", sin(0.12)); 9 | printf("%f\n", cos(0.12)); 10 | printf("%f\n", tan(0.12)); 11 | printf("%f\n", asin(0.12)); 12 | printf("%f\n", acos(0.12)); 13 | printf("%f\n", atan(0.12)); 14 | printf("%f\n", sinh(0.12)); 15 | printf("%f\n", cosh(0.12)); 16 | printf("%f\n", tanh(0.12)); 17 | printf("%f\n", exp(0.12)); 18 | printf("%f\n", fabs(-0.12)); 19 | printf("%f\n", log(0.12)); 20 | printf("%f\n", log10(0.12)); 21 | printf("%f\n", pow(0.12, 0.12)); 22 | printf("%f\n", sqrt(0.12)); 23 | printf("%f\n", round(12.34)); 24 | printf("%f\n", ceil(12.34)); 25 | printf("%f\n", floor(12.34)); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /tests/tests2/96_nodata_wanted.expect: -------------------------------------------------------------------------------- 1 | [test_static_data_error] 2 | 96_nodata_wanted.c:7: error: initializer element is not computable at load time 3 | 4 | [test_static_nodata_error] 5 | 96_nodata_wanted.c:14: error: initializer element is not computable at load time 6 | 7 | [test_global_data_error] 8 | 96_nodata_wanted.c:20: error: initializer element is not computable at load time 9 | 10 | [test_local_data_noerror] 11 | 96_nodata_wanted.c:25: warning: assignment makes integer from pointer without a cast 12 | 96_nodata_wanted.c:25: warning: nonportable conversion from pointer to char/short 13 | 14 | [test_data_suppression_off] 15 | data: 16 | 8 - 8.0 - 8.0 - main - static string 17 | 333 44 555555 6 7 18 | size of data/text: 19 | non-zero/non-zero 20 | 21 | [test_data_suppression_on] 22 | size of data/text: 23 | zero/zero 24 | 25 | [test_static_data] 26 | a = 1 27 | -------------------------------------------------------------------------------- /tests/tests2/54_goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred() 4 | { 5 | printf("In fred()\n"); 6 | goto done; 7 | printf("In middle\n"); 8 | done: 9 | printf("At end\n"); 10 | } 11 | 12 | void joe() 13 | { 14 | int b = 5678; 15 | 16 | printf("In joe()\n"); 17 | 18 | { 19 | int c = 1234; 20 | printf("c = %d\n", c); 21 | goto outer; 22 | printf("uh-oh\n"); 23 | } 24 | 25 | outer: 26 | 27 | printf("done\n"); 28 | } 29 | 30 | void henry() 31 | { 32 | int a; 33 | 34 | printf("In henry()\n"); 35 | goto inner; 36 | 37 | { 38 | int b; 39 | inner: 40 | b = 1234; 41 | printf("b = %d\n", b); 42 | } 43 | 44 | printf("done\n"); 45 | } 46 | 47 | int main() 48 | { 49 | fred(); 50 | joe(); 51 | henry(); 52 | 53 | return 0; 54 | } 55 | 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | .#* 4 | *.o 5 | *.a 6 | *.exe 7 | *.dll 8 | *.obj 9 | *.pdb 10 | *.lib 11 | *.exp 12 | *.log 13 | *.bz2 14 | *.zip 15 | .gdb_history 16 | a.out 17 | tcc_g 18 | tcc 19 | *-tcc 20 | libtcc*.def 21 | 22 | config*.h 23 | config*.mak 24 | config.texi 25 | conftest* 26 | tags 27 | TAGS 28 | tcc.1 29 | tcc.pod 30 | tcc-doc.html 31 | tcc-doc.info 32 | 33 | win32/doc 34 | win32/libtcc 35 | win32/lib/32 36 | win32/lib/64 37 | win32/include/float.h 38 | win32/include/stdarg.h 39 | win32/include/stdbool.h 40 | win32/include/stddef.h 41 | win32/include/varargs.h 42 | win32/include/tcclib.h 43 | 44 | tests/tcctest[1234] 45 | tests/tcctest.gcc 46 | tests/*.out* 47 | tests/*.ref 48 | tests/*.txt 49 | tests/*.gcc 50 | tests/*-cc* 51 | tests/*-tcc* 52 | tests/libtcc_test 53 | tests/asm-c-connect 54 | tests/asm-c-connect-sep 55 | tests/vla_test 56 | tests/hello 57 | tests/tests2/fred.txt 58 | -------------------------------------------------------------------------------- /tests/gcctestsuite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture 4 | TCC="./tcc -B. -I. -DNO_TRAMPOLINES" 5 | rm -f tcc.sum tcc.log 6 | nb_failed="0" 7 | 8 | for src in $TESTSUITE_PATH/compile/*.c ; do 9 | echo $TCC -o /tmp/test.o -c $src 10 | $TCC -o /tmp/test.o -c $src >> tcc.log 2>&1 11 | if [ "$?" = "0" ] ; then 12 | result="PASS" 13 | else 14 | result="FAIL" 15 | nb_failed=$(( $nb_failed + 1 )) 16 | fi 17 | echo "$result: $src" >> tcc.sum 18 | done 19 | 20 | for src in $TESTSUITE_PATH/execute/*.c ; do 21 | echo $TCC $src 22 | $TCC $src >> tcc.log 2>&1 23 | if [ "$?" = "0" ] ; then 24 | result="PASS" 25 | else 26 | result="FAIL" 27 | nb_failed=$(( $nb_failed + 1 )) 28 | fi 29 | echo "$result: $src" >> tcc.sum 30 | done 31 | 32 | echo "$nb_failed test(s) failed." >> tcc.sum 33 | echo "$nb_failed test(s) failed." 34 | -------------------------------------------------------------------------------- /tests/tests2/101_cleanup.expect: -------------------------------------------------------------------------------- 1 | c: a 2 | c: o 3 | glob_i: 65536 4 | oo: 2.600000 5 | c: f 6 | str: I don't think this should be print(but gcc got it wrong too) 7 | because what if free was call inside cleanup function I don't think this should be print(but gcc got it wrong too) 8 | should be print before 9 | str: that 10 | str: this should appear only once 11 | str: -that2 12 | str: -that 13 | str: test2 14 | str: one 15 | ---- 1 16 | str: two 17 | str: three 18 | -- loop 0 -- 19 | 100 20 | 100 21 | 100 22 | 100 23 | 100 24 | 100 25 | 100 26 | 100 27 | 100 28 | 100 29 | 10 30 | -- loop 1 -- 31 | 200 32 | 200 33 | 200 34 | 200 35 | 200 36 | 200 37 | 200 38 | 200 39 | 200 40 | 200 41 | 10 42 | -- loop 2 -- 43 | 300 44 | 0 45 | -- loop 3 -- 46 | 400 47 | 500 48 | 400 49 | after break 50 | 1000 51 | ---- 0 52 | ---- 1 53 | str: plop 54 | str: tata ! 55 | str: 3 56 | str: 2 57 | str: 1 58 | str: last goto out 59 | str: wololo 60 | -------------------------------------------------------------------------------- /win32/include/sec_api/search_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SEARCH_S 7 | #define _INC_SEARCH_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP void *__cdecl _lfind_s(const void *_Key,const void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 18 | _CRTIMP void *__cdecl _lsearch_s(const void *_Key,void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /tests/tests2/11_precedence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | int d; 9 | int e; 10 | int f; 11 | int x; 12 | int y; 13 | 14 | a = 12; 15 | b = 34; 16 | c = 56; 17 | d = 78; 18 | e = 0; 19 | f = 1; 20 | 21 | printf("%d\n", c + d); 22 | printf("%d\n", (y = c + d)); 23 | printf("%d\n", e || e && f); 24 | printf("%d\n", e || f && f); 25 | printf("%d\n", e && e || f); 26 | printf("%d\n", e && f || f); 27 | printf("%d\n", a && f | f); 28 | printf("%d\n", a | b ^ c & d); 29 | printf("%d, %d\n", a == a, a == b); 30 | printf("%d, %d\n", a != a, a != b); 31 | printf("%d\n", a != b && c != d); 32 | printf("%d\n", a + b * c / f); 33 | printf("%d\n", a + b * c / f); 34 | printf("%d\n", (4 << 4)); 35 | printf("%d\n", (64 >> 4)); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tests/asm-c-connect-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined _WIN32 && !defined __TINYC__ 4 | # define _ "_" 5 | #else 6 | # define _ 7 | #endif 8 | 9 | static int x1_c(void) 10 | { 11 | printf(" x1"); 12 | return 1; 13 | } 14 | 15 | asm(".text;"_"x1: call "_"x1_c; ret"); 16 | 17 | void callx4(void); 18 | void callx5_again(void); 19 | 20 | void x6() 21 | { 22 | printf(" x6-1"); 23 | } 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | printf("*"); 28 | asm("call "_"x1"); 29 | asm("call "_"x2"); 30 | asm("call "_"x3"); 31 | callx4(); 32 | asm("call "_"x5"); 33 | callx5_again(); 34 | x6(); 35 | printf(" *\n"); 36 | return 0; 37 | } 38 | 39 | static 40 | int x2(void) 41 | { 42 | printf(" x2"); 43 | return 2; 44 | } 45 | 46 | extern int x3(void); 47 | 48 | void x4(void) 49 | { 50 | printf(" x4"); 51 | } 52 | 53 | void x5(void); 54 | void x5(void) 55 | { 56 | printf(" x5"); 57 | } 58 | -------------------------------------------------------------------------------- /tests/tests2/86_memory-model.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main() 5 | { 6 | #if defined(__LLP64__) 7 | if (sizeof(short) == 2 8 | && sizeof(int) == 4 9 | && sizeof(long int) == 4 10 | && sizeof(long long int) == 8 11 | && sizeof(void*) == 8) { 12 | (void)printf("Ok\n"); 13 | } else { 14 | (void)printf("KO __LLP64__\n"); 15 | } 16 | #elif defined(__LP64__) 17 | if (sizeof(short) == 2 18 | && sizeof(int) == 4 19 | && sizeof(long int) == 8 20 | && sizeof(long long int) == 8 21 | && sizeof(void*) == 8) { 22 | (void)printf("Ok\n"); 23 | } else { 24 | (void)printf("KO __LP64__\n"); 25 | } 26 | #elif defined(__ILP32__) 27 | if (sizeof(short) == 2 28 | && sizeof(int) == 4 29 | && sizeof(long int) == 4 30 | && sizeof(void*) == 4) { 31 | (void)printf("Ok\n"); 32 | } else { 33 | (void)printf("KO __ILP32__\n"); 34 | } 35 | #else 36 | (void)printf("KO no __*LP*__ defined.\n"); 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /win32/include/sec_api/stralign_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __STRALIGN_H_S_ 7 | #define __STRALIGN_H_S_ 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #if !defined(I_X86_) && defined(_WSTRING_S_DEFINED) 18 | #if defined(__cplusplus) && defined(_WConst_Return) 19 | static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) { 20 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); 21 | return uaw_wcscpy((PCUWSTR)String,Character); 22 | } 23 | #endif 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /tests/tests2/78_vla_label.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* This test segfaults as of April 27, 2015. */ 4 | void f1(int argc) 5 | { 6 | char test[argc]; 7 | if(0) 8 | label: 9 | printf("boom!\n"); 10 | if(argc-- == 0) 11 | return; 12 | goto label; 13 | } 14 | 15 | /* This segfaulted on 2015-11-19. */ 16 | void f2(void) 17 | { 18 | goto start; 19 | { 20 | int a[1 && 1]; /* not a variable-length array */ 21 | int b[1 || 1]; /* not a variable-length array */ 22 | int c[1 ? 1 : 1]; /* not a variable-length array */ 23 | start: 24 | a[0] = 0; 25 | b[0] = 0; 26 | c[0] = 0; 27 | } 28 | } 29 | 30 | void f3(void) 31 | { 32 | printf("%d\n", 0 ? printf("x1\n") : 11); 33 | printf("%d\n", 1 ? 12 : printf("x2\n")); 34 | printf("%d\n", 0 && printf("x3\n")); 35 | printf("%d\n", 1 || printf("x4\n")); 36 | } 37 | 38 | int main() 39 | { 40 | f1(2); 41 | f2(); 42 | f3(); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /tests/tests2/76_dollars_in_identifiers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define $(x) x 4 | #define $fred 10 5 | #define joe$ 20 6 | #define hen$y 30 7 | 8 | #define $10(x) x*10 9 | #define _$10(x) x/10 10 | 11 | int main() 12 | { 13 | printf("fred=%d\n", $fred); 14 | printf("joe=%d\n", joe$); 15 | printf("henry=%d\n", hen$y); 16 | 17 | printf("fred2=%d\n", $($fred)); 18 | printf("joe2=%d\n", $(joe$)); 19 | printf("henry2=%d\n", $(hen$y)); 20 | 21 | printf("fred10=%d\n", $10($fred)); 22 | printf("joe_10=%d\n", _$10(joe$)); 23 | 24 | int $ = 10; 25 | int a100$ = 100; 26 | int a$$ = 1000; 27 | int a$c$b = 2121; 28 | int $100 = 10000; 29 | const char *$$$ = "money"; 30 | 31 | printf("local=%d\n", $); 32 | printf("a100$=%d\n", a100$); 33 | printf("a$$=%d\n", a$$); 34 | printf("a$c$b=%d\n", a$c$b); 35 | printf("$100=%d\n", $100); 36 | printf("$$$=%s", $$$); 37 | 38 | return 0; 39 | } 40 | 41 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 42 | -------------------------------------------------------------------------------- /lib/alloca86-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86-bt.S */ 3 | 4 | .globl __bound_alloca 5 | 6 | __bound_alloca: 7 | pop %edx 8 | pop %eax 9 | mov %eax, %ecx 10 | add $3,%eax 11 | and $-4,%eax 12 | jz p6 13 | 14 | #ifdef _WIN32 15 | p4: 16 | cmp $4096,%eax 17 | jbe p5 18 | test %eax,-4096(%esp) 19 | sub $4096,%esp 20 | sub $4096,%eax 21 | jmp p4 22 | 23 | p5: 24 | #endif 25 | 26 | sub %eax,%esp 27 | mov %esp,%eax 28 | 29 | push %edx 30 | push %eax 31 | push %ecx 32 | push %eax 33 | call __bound_new_region 34 | add $8, %esp 35 | pop %eax 36 | pop %edx 37 | 38 | p6: 39 | push %edx 40 | push %edx 41 | ret 42 | 43 | /* mark stack as nonexecutable */ 44 | #if defined __ELF__ && defined __linux__ 45 | .section .note.GNU-stack,"",@progbits 46 | #endif 47 | /* ---------------------------------------------- */ 48 | -------------------------------------------------------------------------------- /tests/tests2/23_type_coercion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void charfunc(char a) 4 | { 5 | printf("char: %c\n", a); 6 | } 7 | 8 | void intfunc(int a) 9 | { 10 | printf("int: %d\n", a); 11 | } 12 | 13 | void floatfunc(float a) 14 | { 15 | printf("float: %f\n", a); 16 | } 17 | 18 | int main() 19 | { 20 | charfunc('a'); 21 | charfunc(98); 22 | charfunc(99.0); 23 | 24 | intfunc('a'); 25 | intfunc(98); 26 | intfunc(99.0); 27 | 28 | floatfunc('a'); 29 | floatfunc(98); 30 | floatfunc(99.0); 31 | 32 | /* printf("%c %d %f\n", 'a', 'b', 'c'); */ 33 | /* printf("%c %d %f\n", 97, 98, 99); */ 34 | /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ 35 | 36 | char b = 97; 37 | char c = 97.0; 38 | 39 | printf("%d %d\n", b, c); 40 | 41 | int d = 'a'; 42 | int e = 97.0; 43 | 44 | printf("%d %d\n", d, e); 45 | 46 | float f = 'a'; 47 | float g = 97; 48 | 49 | printf("%f %f\n", f, g); 50 | 51 | return 0; 52 | } 53 | 54 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 55 | -------------------------------------------------------------------------------- /win32/include/sec_api/io_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_IO_S 7 | #define _INC_IO_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode); 18 | _CRTIMP errno_t __cdecl _chsize_s(int _FileHandle,__int64 _Size); 19 | _CRTIMP errno_t __cdecl _mktemp_s(char *_TemplateName,size_t _Size); 20 | _CRTIMP errno_t __cdecl _umask_s(int _NewMode,int *_OldMode); 21 | 22 | #ifndef _WIO_S_DEFINED 23 | #define _WIO_S_DEFINED 24 | _CRTIMP errno_t __cdecl _waccess_s(const wchar_t *_Filename,int _AccessMode); 25 | _CRTIMP errno_t __cdecl _wmktemp_s(wchar_t *_TemplateName,size_t _SizeInWords); 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /tests/tests2/93_integer_promotion.expect: -------------------------------------------------------------------------------- 1 | signed : s.ub 2 | unsigned : s.u 3 | signed : s.ullb 4 | unsigned : s.ull 5 | signed : s.c 6 | 7 | signed : (1 ? s.ub : 1) 8 | unsigned : (1 ? s.u : 1) 9 | signed : (1 ? s.ullb : 1) 10 | unsigned : (1 ? s.ull : 1) 11 | signed : (1 ? s.c : 1) 12 | 13 | signed : s.ub << 1 14 | unsigned : s.u << 1 15 | signed : s.ullb << 1 16 | unsigned : s.ull << 1 17 | signed : s.c << 1 18 | 19 | signed : +s.ub 20 | unsigned : +s.u 21 | signed : +s.ullb 22 | unsigned : +s.ull 23 | signed : +s.c 24 | 25 | signed : -s.ub 26 | unsigned : -s.u 27 | signed : -s.ullb 28 | unsigned : -s.ull 29 | signed : -s.c 30 | 31 | signed : ~s.ub 32 | unsigned : ~s.u 33 | signed : ~s.ullb 34 | unsigned : ~s.ull 35 | signed : ~s.c 36 | 37 | signed : !s.ub 38 | signed : !s.u 39 | signed : !s.ullb 40 | signed : !s.ull 41 | signed : !s.c 42 | 43 | unsigned : +(unsigned)s.ub 44 | unsigned : -(unsigned)s.ub 45 | unsigned : ~(unsigned)s.ub 46 | signed : !(unsigned)s.ub 47 | -------------------------------------------------------------------------------- /tests/tests2/102_alignas.c: -------------------------------------------------------------------------------- 1 | _Alignas(16) int i1; 2 | int _Alignas(16) i2; 3 | void _Alignas(16) *p2; 4 | _Alignas(16) i3; 5 | int _Alignas(double) i4; 6 | int _Alignas(int) i5; 7 | #if 0 8 | /* The following are currently wrongly accepted by TCC but really shouldn't. */ 9 | int _Alignas(int _Alignas(16)) i6; //wrong, 'int _Alignas(16)' is no type-name 10 | typedef int _Alignas(16) int16aligned_t; //wrong, _Alignas invalid on typedef 11 | int16aligned_t i7; 12 | #endif 13 | /* i8 should get an alignment of 16, because unlike _Alignas the 14 | corresponding attribute _does_ apply to type-name, though not in 15 | some clang versions. */ 16 | int _Alignas(int __attribute__((aligned(16)))) i8; 17 | extern int printf(const char*, ...); 18 | #ifdef _MSC_VER 19 | #define alignof(x) (int)__alignof(x) 20 | #else 21 | #define alignof(x) (int)__alignof__(x) 22 | #endif 23 | int main() 24 | { 25 | printf("%d %d %d %d\n", 26 | alignof(i1) == 16, alignof(i4) == alignof(double), 27 | alignof(i5) == alignof(int) , alignof(i8) == 16); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /win32/include/dir.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * dir.h 8 | * 9 | * This file OBSOLESCENT and only provided for backward compatibility. 10 | * Please use io.h instead. 11 | * 12 | * This file is part of the Mingw32 package. 13 | * 14 | * Contributors: 15 | * Created by Colin Peters 16 | * Mumit Khan 17 | * 18 | * THIS SOFTWARE IS NOT COPYRIGHTED 19 | * 20 | * This source code is offered for use in the public domain. You may 21 | * use, modify or distribute it freely. 22 | * 23 | * This code is distributed in the hope that it will be useful but 24 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 25 | * DISCLAIMED. This includes but is not limited to warranties of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | * 28 | */ 29 | 30 | #include 31 | 32 | -------------------------------------------------------------------------------- /win32/include/uchar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the TinyCC package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_UCHAR 8 | #define _INC_UCHAR 9 | 10 | /* 11 | * The following defines are only valid when C11 (-std=c11) is used. 12 | * 13 | * ... a wide character constant prefixed by the letter u or U has type char16_t 14 | * or char32_t, respectively, unsigned integer types defined in the 15 | * header. 16 | */ 17 | 18 | #if __STDC_VERSION__ >= 201112L 19 | /** 20 | * __STDC_UTF_16__ The integer constant 1, intended to indicate that 21 | * values of type char16_t are UTF-16 encoded. 22 | */ 23 | #define __STDC_UTF_16__ 1 24 | /** 25 | * __STDC_UTF_32__ The integer constant 1, intended to indicate that 26 | * values of type char32_t are UTF-32 encoded. 27 | */ 28 | #define __STDC_UTF_32__ 1 29 | 30 | typedef unsigned short char16_t; 31 | typedef unsigned int char32_t; 32 | #endif /* __STDC_VERSION__ >= 201112L */ 33 | #endif /* _INC_UCHAR */ 34 | -------------------------------------------------------------------------------- /tests/tests2/98_al_ax_extend.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | asm ( 4 | ".text;" 5 | ".globl _us;.globl _ss;.globl _uc;.globl _sc;" 6 | "_us:;_ss:;_uc:;_sc:;" 7 | "movl $0x1234ABCD, %eax;" 8 | "ret;" 9 | ); 10 | 11 | #if 1 12 | #define us _us 13 | #define ss _ss 14 | #define uc _uc 15 | #define sc _sc 16 | #endif 17 | 18 | int main() 19 | { 20 | unsigned short us(void); 21 | short ss(void); 22 | unsigned char uc(void); 23 | signed char sc(void); 24 | 25 | unsigned short (*fpus)(void) = us; 26 | short (*fpss)(void) = ss; 27 | unsigned char (*fpuc)(void) = uc; 28 | signed char (*fpsc)(void) = sc; 29 | 30 | printf("%08X %08X\n", us() + 1, fpus() + 1); 31 | printf("%08X %08X\n", ss() + 1, fpss() + 1); 32 | printf("%08X %08X\n", uc() + 1, fpuc() + 1); 33 | printf("%08X %08X\n", sc() + 1, fpsc() + 1); 34 | printf("\n"); 35 | printf("%08X %08X\n", fpus() + 1, us() + 1); 36 | printf("%08X %08X\n", fpss() + 1, ss() + 1); 37 | printf("%08X %08X\n", fpuc() + 1, uc() + 1); 38 | printf("%08X %08X\n", fpsc() + 1, sc() + 1); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/tests2/28_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | 8 | strcpy(a, "hello"); 9 | printf("%s\n", a); 10 | 11 | strncpy(a, "gosh", 2); 12 | printf("%s\n", a); 13 | 14 | printf("%d\n", strcmp(a, "apple") > 0); 15 | printf("%d\n", strcmp(a, "goere") > 0); 16 | printf("%d\n", strcmp(a, "zebra") < 0); 17 | 18 | printf("%d\n", strlen(a)); 19 | 20 | strcat(a, "!"); 21 | printf("%s\n", a); 22 | 23 | printf("%d\n", strncmp(a, "apple", 2) > 0); 24 | printf("%d\n", strncmp(a, "goere", 2) == 0); 25 | printf("%d\n", strncmp(a, "goerg", 2) == 0); 26 | printf("%d\n", strncmp(a, "zebra", 2) < 0); 27 | 28 | printf("%s\n", strchr(a, 'o')); 29 | printf("%s\n", strrchr(a, 'l')); 30 | printf("%d\n", strrchr(a, 'x') == NULL); 31 | 32 | memset(&a[1], 'r', 4); 33 | printf("%s\n", a); 34 | 35 | memcpy(&a[2], a, 2); 36 | printf("%s\n", a); 37 | 38 | printf("%d\n", memcmp(a, "apple", 4) > 0); 39 | printf("%d\n", memcmp(a, "grgr", 4) == 0); 40 | printf("%d\n", memcmp(a, "zebra", 4) < 0); 41 | 42 | return 0; 43 | } 44 | 45 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 46 | -------------------------------------------------------------------------------- /tests/tests2/40_stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | FILE *f = fopen("fred.txt", "w"); 6 | fwrite("hello\nhello\n", 1, 12, f); 7 | fclose(f); 8 | 9 | char freddy[7]; 10 | f = fopen("fred.txt", "r"); 11 | if (fread(freddy, 1, 6, f) != 6) 12 | printf("couldn't read fred.txt\n"); 13 | 14 | freddy[6] = '\0'; 15 | fclose(f); 16 | 17 | printf("%s", freddy); 18 | 19 | int InChar; 20 | char ShowChar; 21 | f = fopen("fred.txt", "r"); 22 | while ( (InChar = fgetc(f)) != EOF) 23 | { 24 | ShowChar = InChar; 25 | if (ShowChar < ' ') 26 | ShowChar = '.'; 27 | 28 | printf("ch: %d '%c'\n", InChar, ShowChar); 29 | } 30 | fclose(f); 31 | 32 | f = fopen("fred.txt", "r"); 33 | while ( (InChar = getc(f)) != EOF) 34 | { 35 | ShowChar = InChar; 36 | if (ShowChar < ' ') 37 | ShowChar = '.'; 38 | 39 | printf("ch: %d '%c'\n", InChar, ShowChar); 40 | } 41 | fclose(f); 42 | 43 | f = fopen("fred.txt", "r"); 44 | while (fgets(freddy, sizeof(freddy), f) != NULL) 45 | printf("x: %s", freddy); 46 | 47 | fclose(f); 48 | 49 | return 0; 50 | } 51 | 52 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 53 | -------------------------------------------------------------------------------- /lib/alloca86_64-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl __bound_alloca 5 | __bound_alloca: 6 | 7 | #ifdef _WIN32 8 | # bound checking is not implemented 9 | pop %rdx 10 | mov %rcx,%rax 11 | add $15,%rax 12 | and $-16,%rax 13 | jz p3 14 | 15 | p1: 16 | cmp $4096,%rax 17 | jbe p2 18 | test %rax,-4096(%rsp) 19 | sub $4096,%rsp 20 | sub $4096,%rax 21 | jmp p1 22 | p2: 23 | 24 | sub %rax,%rsp 25 | mov %rsp,%rax 26 | add $32,%rax 27 | 28 | p3: 29 | push %rdx 30 | ret 31 | #else 32 | pop %rdx 33 | mov %rdi,%rax 34 | mov %rax,%rsi # size, a second parm to the __bound_new_region 35 | 36 | add $15,%rax 37 | and $-16,%rax 38 | jz p3 39 | 40 | 41 | sub %rax,%rsp 42 | mov %rsp,%rdi # pointer, a first parm to the __bound_new_region 43 | mov %rsp,%rax 44 | 45 | push %rdx 46 | push %rax 47 | call __bound_new_region 48 | pop %rax 49 | pop %rdx 50 | 51 | p3: 52 | push %rdx 53 | ret 54 | #endif 55 | 56 | /* ---------------------------------------------- */ 57 | -------------------------------------------------------------------------------- /tests/tests2/41_hashif.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("#include test\n"); 6 | 7 | #if 1 8 | #if 0 9 | printf("a\n"); 10 | #else 11 | printf("b\n"); 12 | #endif 13 | #else 14 | #if 0 15 | printf("c\n"); 16 | #else 17 | printf("d\n"); 18 | #endif 19 | #endif 20 | 21 | #if 0 22 | #if 1 23 | printf("e\n"); 24 | #else 25 | printf("f\n"); 26 | #endif 27 | #else 28 | #if 1 29 | printf("g\n"); 30 | #else 31 | printf("h\n"); 32 | #endif 33 | #endif 34 | 35 | #define DEF 36 | 37 | #ifdef DEF 38 | #ifdef DEF 39 | printf("i\n"); 40 | #else 41 | printf("j\n"); 42 | #endif 43 | #else 44 | #ifdef DEF 45 | printf("k\n"); 46 | #else 47 | printf("l\n"); 48 | #endif 49 | #endif 50 | 51 | #ifndef DEF 52 | #ifndef DEF 53 | printf("m\n"); 54 | #else 55 | printf("n\n"); 56 | #endif 57 | #else 58 | #ifndef DEF 59 | printf("o\n"); 60 | #else 61 | printf("p\n"); 62 | #endif 63 | #endif 64 | 65 | #define ONE 1 66 | #define ZERO 0 67 | 68 | #if ONE 69 | #if ZERO 70 | printf("q\n"); 71 | #else 72 | printf("r\n"); 73 | #endif 74 | #else 75 | #if ZERO 76 | printf("s\n"); 77 | #else 78 | printf("t\n"); 79 | #endif 80 | #endif 81 | 82 | return 0; 83 | } 84 | 85 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 86 | -------------------------------------------------------------------------------- /tests/tests2/104_inline.expect: -------------------------------------------------------------------------------- 1 | 0 inline_inline_2decl_only 2 | 0 inline_inline_undeclared 3 | 0 inline_inline_predeclared 4 | 0 inline_inline_postdeclared 5 | 0 inline_inline_prepostdeclared 6 | 0 inline_inline_undeclared2 7 | 0 inline_inline_predeclared2 8 | 0 inline_inline_postdeclared2 9 | 0 inline_inline_prepostdeclared2 10 | 1 extern_extern_postdeclared 11 | 1 extern_extern_postdeclared2 12 | 1 extern_extern_predeclared 13 | 1 extern_extern_predeclared2 14 | 1 extern_extern_prepostdeclared 15 | 1 extern_extern_prepostdeclared2 16 | 1 extern_extern_undeclared 17 | 1 extern_extern_undeclared2 18 | 1 extern_postdeclared 19 | 1 extern_postdeclared2 20 | 1 extern_predeclared 21 | 1 extern_predeclared2 22 | 1 extern_prepostdeclared 23 | 1 extern_undeclared 24 | 1 extern_undeclared2 25 | 1 inst2_extern_inline_postdeclared 26 | 1 inst2_extern_inline_predeclared 27 | 1 inst3_extern_inline_predeclared 28 | 1 inst_extern_inline_postdeclared 29 | 1 inst_extern_inline_predeclared 30 | 1 main 31 | 1 noinst_extern_inline_func 32 | 1 noinst_extern_inline_postdeclared 33 | 1 noinst_extern_inline_postdeclared2 34 | 1 noinst_extern_inline_undeclared 35 | 0 noinst_static_inline_postdeclared 36 | 0 noinst2_static_inline_postdeclared 37 | 0 noinst_static_inline_predeclared 38 | 0 noinst2_static_inline_predeclared 39 | 0 static_func 40 | -------------------------------------------------------------------------------- /tests/tests2/81_types.c: -------------------------------------------------------------------------------- 1 | /* The following are all valid decls, even though some subtypes 2 | are incomplete. */ 3 | enum E *e; 4 | const enum E *e1; 5 | enum E const *e2; 6 | struct S *s; 7 | const struct S *s1; 8 | struct S const *s2; 9 | 10 | /* Various strangely looking declarators, which are all valid 11 | and have to map to the same numbered typedefs. */ 12 | typedef int (*fptr1)(); 13 | int f1 (int (), int); 14 | typedef int (*fptr2)(int x); 15 | int f2 (int (int x), int); 16 | typedef int (*fptr3)(int); 17 | int f3 (int (int), int); 18 | typedef int (*fptr4[4])(int); 19 | int f4 (int (*[4])(int), int); 20 | typedef int (*fptr5)(fptr1); 21 | int f5 (int (int()), fptr1); 22 | int f1 (fptr1 fp, int i) 23 | { 24 | return (*fp)(i); 25 | } 26 | int f2 (fptr2 fp, int i) 27 | { 28 | return (*fp)(i); 29 | } 30 | int f3 (fptr3 fp, int i) 31 | { 32 | return (*fp)(i); 33 | } 34 | int f4 (fptr4 fp, int i) 35 | { 36 | return (*fp[i])(i); 37 | } 38 | int f5 (fptr5 fp, fptr1 i) 39 | { 40 | return fp(i); 41 | } 42 | typedef int intx4[4]; 43 | int f8 (intx4, int); 44 | int f8 (int ([4]), int); 45 | int f8 (int y[4], int i) 46 | { 47 | return y[i]; 48 | } 49 | int f9 (int (*)(int), int); 50 | int f9 (int ((int)), int); 51 | int f9 (int f(int), int i) 52 | { 53 | return f(i); 54 | } 55 | int main () { return 0; } 56 | -------------------------------------------------------------------------------- /win32/include/dos.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DOS 7 | #define _INC_DOS 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | 21 | struct _diskfree_t { 22 | unsigned total_clusters; 23 | unsigned avail_clusters; 24 | unsigned sectors_per_cluster; 25 | unsigned bytes_per_sector; 26 | }; 27 | #endif 28 | 29 | #define _A_NORMAL 0x00 30 | #define _A_RDONLY 0x01 31 | #define _A_HIDDEN 0x02 32 | #define _A_SYSTEM 0x04 33 | #define _A_SUBDIR 0x10 34 | #define _A_ARCH 0x20 35 | 36 | #ifndef _GETDISKFREE_DEFINED 37 | #define _GETDISKFREE_DEFINED 38 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 39 | #endif 40 | 41 | #if (defined(_X86_) && !defined(__x86_64)) 42 | void __cdecl _disable(void); 43 | void __cdecl _enable(void); 44 | #endif 45 | 46 | #ifndef NO_OLDNAMES 47 | #define diskfree_t _diskfree_t 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #pragma pack(pop) 55 | #endif 56 | -------------------------------------------------------------------------------- /tests/pp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # credits: 01..13.c from the pcc cpp-tests suite 3 | # 4 | 5 | TOP = ../.. 6 | include $(TOP)/Makefile 7 | SRC = $(TOPSRC)/tests/pp 8 | VPATH = $(SRC) 9 | 10 | files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1))) 11 | TESTS = $(call files,c) $(call files,S) 12 | 13 | all test testspp.all: $(sort $(TESTS)) 14 | 15 | DIFF_OPTS = -Nu -b -B 16 | 17 | # Filter source directory in warnings/errors (out-of-tree builds) 18 | FILTER = 2>&1 | sed 's,$(SRC)/,,g' 19 | 20 | %.test: %.c %.expect 21 | @echo PPTest $* ... 22 | -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ 23 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ 24 | && rm -f $*.output 25 | 26 | %.test: %.S %.expect 27 | @echo PPTest $* ... 28 | -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ 29 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ 30 | && rm -f $*.output 31 | 32 | testspp.%: %.test ; 33 | 34 | # automatically generate .expect files with gcc: 35 | %.expect: # %.c 36 | gcc -E -P $*.[cS] >$*.expect 2>&1 37 | 38 | # tell make not to delete 39 | .PRECIOUS: %.expect 40 | 41 | clean: 42 | rm -f *.output 43 | 44 | 02.test : DIFF_OPTS += -w 45 | # 15.test : DIFF_OPTS += -I"^XXX:" 46 | 47 | # diff options: 48 | # -b ighore space changes 49 | # -w ighore all whitespace 50 | # -B ignore blank lines 51 | # -I ignore lines matching RE 52 | -------------------------------------------------------------------------------- /tests/tests2/22_floating_point.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | // variables 7 | float a = 12.34 + 56.78; 8 | printf("%f\n", a); 9 | 10 | // infix operators 11 | printf("%f\n", 12.34 + 56.78); 12 | printf("%f\n", 12.34 - 56.78); 13 | printf("%f\n", 12.34 * 56.78); 14 | printf("%f\n", 12.34 / 56.78); 15 | 16 | // comparison operators 17 | printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78); 18 | printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34); 19 | printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34); 20 | 21 | // assignment operators 22 | a = 12.34; 23 | a += 56.78; 24 | printf("%f\n", a); 25 | 26 | a = 12.34; 27 | a -= 56.78; 28 | printf("%f\n", a); 29 | 30 | a = 12.34; 31 | a *= 56.78; 32 | printf("%f\n", a); 33 | 34 | a = 12.34; 35 | a /= 56.78; 36 | printf("%f\n", a); 37 | 38 | // prefix operators 39 | printf("%f\n", +12.34); 40 | printf("%f\n", -12.34); 41 | 42 | // type coercion 43 | a = 2; 44 | printf("%f\n", a); 45 | printf("%f\n", sin(2)); 46 | 47 | return 0; 48 | } 49 | 50 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 51 | -------------------------------------------------------------------------------- /tests/tests2/33_ternary_op.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char arr[1]; 5 | static void f (void){} 6 | void (*fp)(void) = f; 7 | void call_fp() 8 | { 9 | (fp?f:f)(); 10 | (fp?fp:fp)(); 11 | (fp?fp:&f)(); 12 | (fp?&f:fp)(); 13 | (fp?&f:&f)(); 14 | _Generic(0?arr:arr, char*: (void)0); 15 | _Generic(0?&arr[0]:arr, char*: (void)0); 16 | _Generic(0?arr:&arr[0], char*: (void)0); 17 | _Generic(1?arr:arr, char*: (void)0); 18 | _Generic(1?&arr[0]:arr, char*: (void)0); 19 | _Generic(1?arr:&arr[0], char*: (void)0); 20 | _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0); 21 | (fp?&f:f)(); 22 | (fp?f:&f)(); 23 | _Generic((__typeof(fp?0L:(void)0)*){0}, void*: (void)0); 24 | 25 | //Should cleanly fail, not segfault: 26 | /*(fp?f:1);*/ 27 | } 28 | 29 | int main() 30 | { 31 | int Count; 32 | 33 | for (Count = 0; Count < 10; Count++) 34 | { 35 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 36 | } 37 | 38 | { 39 | int c = 0; 40 | #define ASSERT(X) assert(X) 41 | static struct stru { int x; } a={'A'},b={'B'}; 42 | ASSERT('A'==(*(1?&a:&b)).x); 43 | ASSERT('A'==(1?a:b).x); 44 | ASSERT('A'==(c?b:a).x); 45 | ASSERT('A'==(0?b:a).x); 46 | c=1; 47 | ASSERT('A'==(c?a:b).x); 48 | } 49 | 50 | 51 | return 0; 52 | } 53 | 54 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 55 | -------------------------------------------------------------------------------- /win32/include/memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_MEMORY 7 | #define _INC_MEMORY 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CONST_RETURN 16 | #define _CONST_RETURN 17 | #endif 18 | 19 | #define _WConst_return _CONST_RETURN 20 | 21 | #ifndef _CRT_MEMORY_DEFINED 22 | #define _CRT_MEMORY_DEFINED 23 | _CRTIMP void *__cdecl _memccpy(void *_Dst,const void *_Src,int _Val,size_t _MaxCount); 24 | _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); 25 | _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 26 | _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); 27 | int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); 28 | void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _Size); 29 | void *__cdecl memset(void *_Dst,int _Val,size_t _Size); 30 | 31 | #ifndef NO_OLDNAMES 32 | void *__cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); 33 | int __cdecl memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 34 | #endif 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | -------------------------------------------------------------------------------- /tests/tests2/39_typedef.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int MyInt; 4 | 5 | struct FunStruct 6 | { 7 | int i; 8 | int j; 9 | }; 10 | 11 | typedef struct FunStruct MyFunStruct; 12 | 13 | typedef MyFunStruct *MoreFunThanEver; 14 | 15 | int main() 16 | { 17 | MyInt a = 1; 18 | printf("%d\n", a); 19 | 20 | MyFunStruct b; 21 | b.i = 12; 22 | b.j = 34; 23 | printf("%d,%d\n", b.i, b.j); 24 | 25 | MoreFunThanEver c = &b; 26 | printf("%d,%d\n", c->i, c->j); 27 | 28 | return 0; 29 | } 30 | 31 | /* "If the specification of an array type includes any type qualifiers, 32 | the element type is so-qualified, not the array type." */ 33 | 34 | typedef int A[3]; 35 | extern A const ca; 36 | extern const A ca; 37 | extern const int ca[3]; 38 | 39 | typedef A B[1][2]; 40 | extern B const cb; 41 | extern const B cb; 42 | extern const int cb[1][2][3]; 43 | 44 | extern B b; 45 | extern int b[1][2][3]; 46 | 47 | /* Funny but valid function declaration. */ 48 | typedef int functype (int); 49 | extern functype func; 50 | int func(int i) 51 | { 52 | return i + 1; 53 | } 54 | 55 | /* Even funnier function decl and definition using typeof. */ 56 | int set_anon_super(void); 57 | int set_anon_super(void) 58 | { 59 | return 42; 60 | } 61 | typedef int sas_type (void); 62 | extern typeof(set_anon_super) set_anon_super; 63 | extern sas_type set_anon_super; 64 | 65 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 66 | -------------------------------------------------------------------------------- /win32/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #include <_mingw.h> 7 | 8 | #include 9 | 10 | #ifndef _INC_FCNTL 11 | #define _INC_FCNTL 12 | 13 | #define _O_RDONLY 0x0000 14 | #define _O_WRONLY 0x0001 15 | #define _O_RDWR 0x0002 16 | #define _O_APPEND 0x0008 17 | #define _O_CREAT 0x0100 18 | #define _O_TRUNC 0x0200 19 | #define _O_EXCL 0x0400 20 | #define _O_TEXT 0x4000 21 | #define _O_BINARY 0x8000 22 | #define _O_WTEXT 0x10000 23 | #define _O_U16TEXT 0x20000 24 | #define _O_U8TEXT 0x40000 25 | #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) 26 | 27 | #define _O_RAW _O_BINARY 28 | #define _O_NOINHERIT 0x0080 29 | #define _O_TEMPORARY 0x0040 30 | #define _O_SHORT_LIVED 0x1000 31 | 32 | #define _O_SEQUENTIAL 0x0020 33 | #define _O_RANDOM 0x0010 34 | 35 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 36 | #define O_RDONLY _O_RDONLY 37 | #define O_WRONLY _O_WRONLY 38 | #define O_RDWR _O_RDWR 39 | #define O_APPEND _O_APPEND 40 | #define O_CREAT _O_CREAT 41 | #define O_TRUNC _O_TRUNC 42 | #define O_EXCL _O_EXCL 43 | #define O_TEXT _O_TEXT 44 | #define O_BINARY _O_BINARY 45 | #define O_RAW _O_BINARY 46 | #define O_TEMPORARY _O_TEMPORARY 47 | #define O_NOINHERIT _O_NOINHERIT 48 | #define O_SEQUENTIAL _O_SEQUENTIAL 49 | #define O_RANDOM _O_RANDOM 50 | #define O_ACCMODE _O_ACCMODE 51 | #endif 52 | #endif 53 | -------------------------------------------------------------------------------- /tests/tests2/75_array_in_struct_init.expect: -------------------------------------------------------------------------------- 1 | cases[0].c[0]=73400320 2 | cases[0].c[1]=262144 3 | cases[0].c[2]=805567999 4 | cases[0].c[3]=-1 5 | cases[0].b=1 6 | cases[0].e=2 7 | cases[0].k=1 8 | 9 | cases[1].c[0]=879754751 10 | cases[1].c[1]=262144 11 | cases[1].c[2]=262144 12 | cases[1].c[3]=805567999 13 | cases[1].b=2 14 | cases[1].e=3 15 | cases[1].k=2 16 | 17 | cases[2].c[0]=879754751 18 | cases[2].c[1]=805567999 19 | cases[2].c[2]=262144 20 | cases[2].c[3]=805567999 21 | cases[2].b=1 22 | cases[2].e=3 23 | cases[2].k=2 24 | 25 | cases[3].c[0]=879754751 26 | cases[3].c[1]=805830143 27 | cases[3].c[2]=524288 28 | cases[3].c[3]=-1 29 | cases[3].b=1 30 | cases[3].e=2 31 | cases[3].k=1 32 | 33 | cases[4].c[0]=879754751 34 | cases[4].c[1]=805830143 35 | cases[4].c[2]=1048576 36 | cases[4].c[3]=805830143 37 | cases[4].b=1 38 | cases[4].e=3 39 | cases[4].k=1 40 | 41 | cases[5].c[0]=879754751 42 | cases[5].c[1]=805830143 43 | cases[5].c[2]=262144 44 | cases[5].c[3]=262144 45 | cases[5].b=1 46 | cases[5].e=3 47 | cases[5].k=1 48 | 49 | cases[6].c[0]=73400320 50 | cases[6].c[1]=807403007 51 | cases[6].c[2]=807403007 52 | cases[6].c[3]=-1 53 | cases[6].b=1 54 | cases[6].e=2 55 | cases[6].k=1 56 | 57 | cases[7].c[0]=839122431 58 | cases[7].c[1]=2097152 59 | cases[7].c[2]=807403007 60 | cases[7].c[3]=-1 61 | cases[7].b=0 62 | cases[7].e=2 63 | cases[7].k=1 64 | 65 | cases[8].c[0]=67108864 66 | cases[8].c[1]=807403007 67 | cases[8].c[2]=134217728 68 | cases[8].c[3]=-1 69 | cases[8].b=0 70 | cases[8].e=2 71 | cases[8].k=0 72 | 73 | -------------------------------------------------------------------------------- /include/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOAT_H_ 2 | #define _FLOAT_H_ 3 | 4 | #define FLT_RADIX 2 5 | 6 | /* IEEE float */ 7 | #define FLT_MANT_DIG 24 8 | #define FLT_DIG 6 9 | #define FLT_ROUNDS 1 10 | #define FLT_EPSILON 1.19209290e-07F 11 | #define FLT_MIN_EXP (-125) 12 | #define FLT_MIN 1.17549435e-38F 13 | #define FLT_MIN_10_EXP (-37) 14 | #define FLT_MAX_EXP 128 15 | #define FLT_MAX 3.40282347e+38F 16 | #define FLT_MAX_10_EXP 38 17 | 18 | /* IEEE double */ 19 | #define DBL_MANT_DIG 53 20 | #define DBL_DIG 15 21 | #define DBL_EPSILON 2.2204460492503131e-16 22 | #define DBL_MIN_EXP (-1021) 23 | #define DBL_MIN 2.2250738585072014e-308 24 | #define DBL_MIN_10_EXP (-307) 25 | #define DBL_MAX_EXP 1024 26 | #define DBL_MAX 1.7976931348623157e+308 27 | #define DBL_MAX_10_EXP 308 28 | 29 | /* horrible intel long double */ 30 | #if defined __i386__ || defined __x86_64__ 31 | 32 | #define LDBL_MANT_DIG 64 33 | #define LDBL_DIG 18 34 | #define LDBL_EPSILON 1.08420217248550443401e-19L 35 | #define LDBL_MIN_EXP (-16381) 36 | #define LDBL_MIN 3.36210314311209350626e-4932L 37 | #define LDBL_MIN_10_EXP (-4931) 38 | #define LDBL_MAX_EXP 16384 39 | #define LDBL_MAX 1.18973149535723176502e+4932L 40 | #define LDBL_MAX_10_EXP 4932 41 | 42 | #else 43 | 44 | /* same as IEEE double */ 45 | #define LDBL_MANT_DIG 53 46 | #define LDBL_DIG 15 47 | #define LDBL_EPSILON 2.2204460492503131e-16 48 | #define LDBL_MIN_EXP (-1021) 49 | #define LDBL_MIN 2.2250738585072014e-308 50 | #define LDBL_MIN_10_EXP (-307) 51 | #define LDBL_MAX_EXP 1024 52 | #define LDBL_MAX 1.7976931348623157e+308 53 | #define LDBL_MAX_10_EXP 308 54 | 55 | #endif 56 | 57 | #endif /* _FLOAT_H_ */ 58 | -------------------------------------------------------------------------------- /tests/tests2/17_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred 4 | { 5 | a, 6 | b, 7 | c, 8 | d, 9 | e = 54, 10 | f = 73, 11 | g, 12 | h 13 | }; 14 | 15 | /* All following uses of enum efoo should compile 16 | without warning. While forward enums aren't ISO C, 17 | it's accepted by GCC also in strict mode, and only warned 18 | about with -pedantic. This happens in the real world. */ 19 | /* Strict ISO C doesn't allow this kind of forward declaration of 20 | enums, but GCC accepts it (and gives only pedantic warning), and 21 | it occurs in the wild. */ 22 | enum efoo; 23 | struct Sforward_use { 24 | int (*fmember) (enum efoo x); 25 | }; 26 | 27 | extern enum efoo it_real_fn(void); 28 | enum efoo { 29 | ONE, 30 | TWO, 31 | }; 32 | struct S2 { 33 | enum efoo (*f2) (void); 34 | }; 35 | void should_compile(struct S2 *s) 36 | { 37 | s->f2 = it_real_fn; 38 | } 39 | 40 | enum efoo it_real_fn(void) 41 | { 42 | return TWO; 43 | } 44 | 45 | static unsigned int deref_uintptr(unsigned int *p) 46 | { 47 | return *p; 48 | } 49 | 50 | enum Epositive { 51 | epos_one, epos_two 52 | }; 53 | 54 | int main() 55 | { 56 | enum fred frod; 57 | enum Epositive epos = epos_two; 58 | 59 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 60 | /* printf("%d\n", frod); */ 61 | frod = 12; 62 | printf("%d\n", frod); 63 | frod = e; 64 | printf("%d\n", frod); 65 | 66 | /* Following should compile without warning. */ 67 | printf ("enum to int: %u\n", deref_uintptr(&epos)); 68 | 69 | return 0; 70 | } 71 | 72 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 73 | -------------------------------------------------------------------------------- /tests/tests2/88_codeopt.c: -------------------------------------------------------------------------------- 1 | /* Check some way in where code suppression caused various 2 | miscompilations. */ 3 | extern int printf (const char *, ...); 4 | typedef unsigned long size_t; 5 | 6 | size_t _brk_start, _brk_end; 7 | void * extend_brk(size_t size, size_t align) 8 | { 9 | size_t mask = align - 1; 10 | void *ret = 0; 11 | 12 | do { 13 | if (__builtin_expect(!!(_brk_start == 0), 0)) 14 | do { 15 | printf("wrong1\n"); 16 | } while (0); 17 | } while (0); 18 | _brk_end = (_brk_end + mask) & ~mask; 19 | ret = (void *)_brk_end; 20 | _brk_end += size; 21 | 22 | return ret; 23 | } 24 | 25 | static void get_args (int a, int b) 26 | { 27 | if (a != 1) 28 | printf("wrong2\n"); 29 | else 30 | printf("okay\n"); 31 | } 32 | 33 | void bla(void) 34 | { 35 | int __ret = 42; 36 | ({ 37 | if (__builtin_expect(!!(0), 0)) { 38 | if (__builtin_expect(!!__ret, 0)) 39 | printf("wrong3\n"); 40 | int x = !!(__ret); 41 | } 42 | __ret; 43 | }); 44 | get_args(!!__ret, sizeof(__ret)); 45 | } 46 | 47 | _Bool chk(unsigned long addr, unsigned long limit, unsigned long size) 48 | { 49 | _Bool ret; 50 | /* This just needs to compile, no runtime test. (And it doesn't compile 51 | only with certain internal checking added that's not committed). */ 52 | if (0) 53 | ret = 0 != (!!(addr > limit - size)); 54 | return 0; 55 | } 56 | 57 | int main() 58 | { 59 | void *r; 60 | _brk_start = 1024; 61 | _brk_end = 1024; 62 | r = extend_brk (4096, 16); 63 | if (!r) 64 | printf("wrong4\n"); 65 | else 66 | printf("okay\n"); 67 | bla(); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /tests/tests2/92_enum_bitfield.c: -------------------------------------------------------------------------------- 1 | /* This checks if enums needing 8 bit but only having positive 2 | values are correctly zero extended (instead of sign extended) 3 | when stored into/loaded from a 8 bit bit-field of enum type (which 4 | itself is implementation defined, so isn't necessarily supported by all 5 | other compilers). */ 6 | enum tree_code { 7 | SOME_CODE = 148, /* has bit 7 set, and hence all further enum values as well */ 8 | LAST_AND_UNUSED_TREE_CODE 9 | }; 10 | typedef union tree_node *tree; 11 | struct tree_common 12 | { 13 | union tree_node *chain; 14 | union tree_node *type; 15 | enum tree_code code : 8; 16 | unsigned side_effects_flag : 1; 17 | }; 18 | union tree_node 19 | { 20 | struct tree_common common; 21 | }; 22 | enum c_tree_code { 23 | C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE, 24 | STMT_EXPR, 25 | LAST_C_TREE_CODE 26 | }; 27 | enum cplus_tree_code { 28 | CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE, 29 | AMBIG_CONV, 30 | LAST_CPLUS_TREE_CODE 31 | }; 32 | 33 | extern int printf(const char *, ...); 34 | int blah(){return 0;} 35 | 36 | int convert_like_real (tree convs) 37 | { 38 | switch (((enum tree_code) (convs)->common.code)) 39 | { 40 | case AMBIG_CONV: /* This has bit 7 set, which must not be the sign 41 | bit in tree_common.code, i.e. the bitfield must 42 | be somehow marked unsigned. */ 43 | return blah(); 44 | default: 45 | break; 46 | }; 47 | printf("unsigned enum bit-fields broken\n"); 48 | return 0; 49 | } 50 | 51 | int main() 52 | { 53 | union tree_node convs; 54 | 55 | convs.common.code = AMBIG_CONV; 56 | convert_like_real (&convs); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /win32/include/assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __ASSERT_H_ 7 | #define __ASSERT_H_ 8 | 9 | #include <_mingw.h> 10 | #ifdef __cplusplus 11 | #include 12 | #endif 13 | 14 | #ifdef NDEBUG 15 | #ifndef assert 16 | #define assert(_Expression) ((void)0) 17 | #endif 18 | #else 19 | 20 | #ifndef _CRT_TERMINATE_DEFINED 21 | #define _CRT_TERMINATE_DEFINED 22 | void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; 23 | _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; 24 | #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */ 25 | /* C99 function name */ 26 | void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; 27 | __CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status) 28 | { _exit(status); } 29 | #endif 30 | 31 | #pragma push_macro("abort") 32 | #undef abort 33 | void __cdecl __declspec(noreturn) abort(void); 34 | #pragma pop_macro("abort") 35 | 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | 43 | extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line); 44 | extern void __cdecl _assert(const char *, const char *, unsigned); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #ifndef assert 51 | //#define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0)) 52 | #define assert(e) ((e) ? (void)0 : _assert(#e, __FILE__, __LINE__)) 53 | #endif 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /tests/tests2/93_integer_promotion.c: -------------------------------------------------------------------------------- 1 | /* integer promotion */ 2 | 3 | int printf(const char*, ...); 4 | #define promote(s) printf(" %ssigned : %s\n", (s) - 100 < 0 ? " " : "un", #s); 5 | 6 | int main (void) 7 | { 8 | struct { 9 | unsigned ub:3; 10 | unsigned u:32; 11 | unsigned long long ullb:35; 12 | unsigned long long ull:64; 13 | unsigned char c; 14 | } s = { 1, 1, 1 }; 15 | 16 | promote(s.ub); 17 | promote(s.u); 18 | promote(s.ullb); 19 | promote(s.ull); 20 | promote(s.c); 21 | printf("\n"); 22 | 23 | promote((1 ? s.ub : 1)); 24 | promote((1 ? s.u : 1)); 25 | promote((1 ? s.ullb : 1)); 26 | promote((1 ? s.ull : 1)); 27 | promote((1 ? s.c : 1)); 28 | printf("\n"); 29 | 30 | promote(s.ub << 1); 31 | promote(s.u << 1); 32 | promote(s.ullb << 1); 33 | promote(s.ull << 1); 34 | promote(s.c << 1); 35 | printf("\n"); 36 | 37 | promote(+s.ub); 38 | promote(+s.u); 39 | promote(+s.ullb); 40 | promote(+s.ull); 41 | promote(+s.c); 42 | printf("\n"); 43 | 44 | promote(-s.ub); 45 | promote(-s.u); 46 | promote(-s.ullb); 47 | promote(-s.ull); 48 | promote(-s.c); 49 | printf("\n"); 50 | 51 | promote(~s.ub); 52 | promote(~s.u); 53 | promote(~s.ullb); 54 | promote(~s.ull); 55 | promote(~s.c); 56 | printf("\n"); 57 | 58 | promote(!s.ub); 59 | promote(!s.u); 60 | promote(!s.ullb); 61 | promote(!s.ull); 62 | promote(!s.c); 63 | printf("\n"); 64 | 65 | promote(+(unsigned)s.ub); 66 | promote(-(unsigned)s.ub); 67 | promote(~(unsigned)s.ub); 68 | promote(!(unsigned)s.ub); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /win32/include/sec_api/conio_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CONIO_S 8 | #define _INC_CONIO_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | _CRTIMP errno_t __cdecl _cgets_s(char *_Buffer,size_t _Size,size_t *_SizeRead); 19 | _CRTIMP int __cdecl _cprintf_s(const char *_Format,...); 20 | _CRTIMP int __cdecl _cscanf_s(const char *_Format,...); 21 | _CRTIMP int __cdecl _cscanf_s_l(const char *_Format,_locale_t _Locale,...); 22 | _CRTIMP int __cdecl _vcprintf_s(const char *_Format,va_list _ArgList); 23 | _CRTIMP int __cdecl _cprintf_s_l(const char *_Format,_locale_t _Locale,...); 24 | _CRTIMP int __cdecl _vcprintf_s_l(const char *_Format,_locale_t _Locale,va_list _ArgList); 25 | 26 | #ifndef _WCONIO_DEFINED_S 27 | #define _WCONIO_DEFINED_S 28 | _CRTIMP errno_t __cdecl _cgetws_s(wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); 29 | _CRTIMP int __cdecl _cwprintf_s(const wchar_t *_Format,...); 30 | _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); 31 | _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 32 | _CRTIMP int __cdecl _vcwprintf_s(const wchar_t *_Format,va_list _ArgList); 33 | _CRTIMP int __cdecl _cwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 34 | _CRTIMP int __cdecl _vcwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /win32/include/errno.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_ERRNO 7 | #define _INC_ERRNO 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CRT_ERRNO_DEFINED 16 | #define _CRT_ERRNO_DEFINED 17 | _CRTIMP extern int *__cdecl _errno(void); 18 | #define errno (*_errno()) 19 | 20 | errno_t __cdecl _set_errno(int _Value); 21 | errno_t __cdecl _get_errno(int *_Value); 22 | #endif 23 | 24 | #define EPERM 1 25 | #define ENOENT 2 26 | #define ESRCH 3 27 | #define EINTR 4 28 | #define EIO 5 29 | #define ENXIO 6 30 | #define E2BIG 7 31 | #define ENOEXEC 8 32 | #define EBADF 9 33 | #define ECHILD 10 34 | #define EAGAIN 11 35 | #define ENOMEM 12 36 | #define EACCES 13 37 | #define EFAULT 14 38 | #define EBUSY 16 39 | #define EEXIST 17 40 | #define EXDEV 18 41 | #define ENODEV 19 42 | #define ENOTDIR 20 43 | #define EISDIR 21 44 | #define ENFILE 23 45 | #define EMFILE 24 46 | #define ENOTTY 25 47 | #define EFBIG 27 48 | #define ENOSPC 28 49 | #define ESPIPE 29 50 | #define EROFS 30 51 | #define EMLINK 31 52 | #define EPIPE 32 53 | #define EDOM 33 54 | #define EDEADLK 36 55 | #define ENAMETOOLONG 38 56 | #define ENOLCK 39 57 | #define ENOSYS 40 58 | #define ENOTEMPTY 41 59 | 60 | #ifndef RC_INVOKED 61 | #if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED) 62 | #define _SECURECRT_ERRCODE_VALUES_DEFINED 63 | #define EINVAL 22 64 | #define ERANGE 34 65 | #define EILSEQ 42 66 | #define STRUNCATE 80 67 | #endif 68 | #endif 69 | 70 | #define EDEADLOCK EDEADLK 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | #endif 76 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | typedef __SIZE_TYPE__ size_t; 5 | typedef __PTRDIFF_TYPE__ ssize_t; 6 | typedef __WCHAR_TYPE__ wchar_t; 7 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 8 | typedef __PTRDIFF_TYPE__ intptr_t; 9 | typedef __SIZE_TYPE__ uintptr_t; 10 | 11 | #if __STDC_VERSION__ >= 201112L 12 | typedef union { long long __ll; long double __ld; } max_align_t; 13 | #endif 14 | 15 | #ifndef __int8_t_defined 16 | #define __int8_t_defined 17 | typedef signed char int8_t; 18 | typedef signed short int int16_t; 19 | typedef signed int int32_t; 20 | #ifdef __LP64__ 21 | typedef signed long int int64_t; 22 | #else 23 | typedef signed long long int int64_t; 24 | #endif 25 | typedef unsigned char uint8_t; 26 | typedef unsigned short int uint16_t; 27 | typedef unsigned int uint32_t; 28 | #ifdef __LP64__ 29 | typedef unsigned long int uint64_t; 30 | #else 31 | typedef unsigned long long int uint64_t; 32 | #endif 33 | #endif 34 | 35 | #ifndef NULL 36 | #define NULL ((void*)0) 37 | #endif 38 | 39 | #define offsetof(type, field) ((size_t)&((type *)0)->field) 40 | 41 | void *alloca(size_t size); 42 | 43 | #endif 44 | 45 | /* Older glibc require a wint_t from (when requested 46 | by __need_wint_t, as otherwise stddef.h isn't allowed to 47 | define this type). Note that this must be outside the normal 48 | _STDDEF_H guard, so that it works even when we've included the file 49 | already (without requiring wint_t). Some other libs define _WINT_T 50 | if they've already provided that type, so we can use that as guard. 51 | TCC defines __WINT_TYPE__ for us. */ 52 | #if defined (__need_wint_t) 53 | #ifndef _WINT_T 54 | #define _WINT_T 55 | typedef __WINT_TYPE__ wint_t; 56 | #endif 57 | #undef __need_wint_t 58 | #endif 59 | -------------------------------------------------------------------------------- /tests/tests2/25_quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int array[16]; 4 | 5 | //Swap integer values by array indexes 6 | void swap(int a, int b) 7 | { 8 | int tmp = array[a]; 9 | array[a] = array[b]; 10 | array[b] = tmp; 11 | } 12 | 13 | //Partition the array into two halves and return the 14 | //index about which the array is partitioned 15 | int partition(int left, int right) 16 | { 17 | int pivotIndex = left; 18 | int pivotValue = array[pivotIndex]; 19 | int index = left; 20 | int i; 21 | 22 | swap(pivotIndex, right); 23 | for(i = left; i < right; i++) 24 | { 25 | if(array[i] < pivotValue) 26 | { 27 | swap(i, index); 28 | index += 1; 29 | } 30 | } 31 | swap(right, index); 32 | 33 | return index; 34 | } 35 | 36 | //Quicksort the array 37 | void quicksort(int left, int right) 38 | { 39 | if(left >= right) 40 | return; 41 | 42 | int index = partition(left, right); 43 | quicksort(left, index - 1); 44 | quicksort(index + 1, right); 45 | } 46 | 47 | int main() 48 | { 49 | int i; 50 | 51 | array[0] = 62; 52 | array[1] = 83; 53 | array[2] = 4; 54 | array[3] = 89; 55 | array[4] = 36; 56 | array[5] = 21; 57 | array[6] = 74; 58 | array[7] = 37; 59 | array[8] = 65; 60 | array[9] = 33; 61 | array[10] = 96; 62 | array[11] = 38; 63 | array[12] = 53; 64 | array[13] = 16; 65 | array[14] = 74; 66 | array[15] = 55; 67 | 68 | for (i = 0; i < 16; i++) 69 | printf("%d ", array[i]); 70 | 71 | printf("\n"); 72 | 73 | quicksort(0, 15); 74 | 75 | for (i = 0; i < 16; i++) 76 | printf("%d ", array[i]); 77 | 78 | printf("\n"); 79 | 80 | return 0; 81 | } 82 | 83 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 84 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.c: -------------------------------------------------------------------------------- 1 | /* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ 2 | 3 | Tests on left-shift type, written by Vincent Lefevre . 4 | 5 | ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on 6 | each of the operands. The type of the result is that of the promoted 7 | left operand." 8 | */ 9 | 10 | #include 11 | 12 | #define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) 13 | #define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) 14 | #define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) 15 | #define TEST2(X) \ 16 | do \ 17 | { \ 18 | TEST1((X),short); \ 19 | TEST1((X),int); \ 20 | TEST1((X),long); \ 21 | TEST1((X),long long); \ 22 | } \ 23 | while (0) 24 | #define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) 25 | #define TEST4(X) \ 26 | do \ 27 | { \ 28 | TEST3((X),short); \ 29 | TEST3((X),int); \ 30 | TEST3((X),long); \ 31 | TEST3((X),long long); \ 32 | } \ 33 | while (0) 34 | 35 | static int debug, nfailed = 0; 36 | 37 | static void check (const char *s, int arg1, int shift) 38 | { 39 | int failed = arg1 != shift; 40 | if (debug || failed) 41 | printf ("%s %d %d\n", s, arg1, shift); 42 | nfailed += failed; 43 | } 44 | 45 | int main (int argc, char **argv) 46 | { 47 | debug = argc > 1; 48 | TEST4(1); 49 | TEST4(-1); 50 | printf ("%d test(s) failed\n", nfailed); 51 | return nfailed != 0; 52 | } 53 | -------------------------------------------------------------------------------- /lib/armflush.c: -------------------------------------------------------------------------------- 1 | /* armflush.c - flush the instruction cache 2 | 3 | __clear_cache is used in tccrun.c, It is a built-in 4 | intrinsic with gcc. However tcc in order to compile 5 | itself needs this function */ 6 | 7 | #ifdef __TINYC__ 8 | 9 | /* syscall wrapper */ 10 | unsigned syscall(unsigned syscall_nr, ...); 11 | 12 | /* arm-tcc supports only fake asm currently */ 13 | __asm__( 14 | ".global syscall\n" 15 | "syscall:\n" 16 | ".int 0xe92d4080\n" // push {r7, lr} 17 | ".int 0xe1a07000\n" // mov r7, r0 18 | ".int 0xe1a00001\n" // mov r0, r1 19 | ".int 0xe1a01002\n" // mov r1, r2 20 | ".int 0xe1a02003\n" // mov r2, r3 21 | ".int 0xef000000\n" // svc 0x00000000 22 | ".int 0xe8bd8080\n" // pop {r7, pc} 23 | ); 24 | 25 | /* from unistd.h: */ 26 | #if defined(__thumb__) || defined(__ARM_EABI__) 27 | # define __NR_SYSCALL_BASE 0x0 28 | #else 29 | # define __NR_SYSCALL_BASE 0x900000 30 | #endif 31 | #define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) 32 | #define __ARM_NR_cacheflush (__ARM_NR_BASE+2) 33 | 34 | #else 35 | 36 | #define _GNU_SOURCE 37 | #include 38 | #include 39 | #include 40 | 41 | #endif 42 | 43 | /* Flushing for tccrun */ 44 | void __clear_cache(void *beginning, void *end) 45 | { 46 | /* __ARM_NR_cacheflush is kernel private and should not be used in user space. 47 | * However, there is no ARM asm parser in tcc so we use it for now */ 48 | #if 1 49 | syscall(__ARM_NR_cacheflush, beginning, end, 0); 50 | #else 51 | __asm__ ("push {r7}\n\t" 52 | "mov r7, #0xf0002\n\t" 53 | "mov r2, #0\n\t" 54 | "swi 0\n\t" 55 | "pop {r7}\n\t" 56 | "ret"); 57 | #endif 58 | } 59 | -------------------------------------------------------------------------------- /tests/tests2/104+_inline.c: -------------------------------------------------------------------------------- 1 | 2 | #define GOT(f) \ 3 | __attribute__((weak)) void f(void); \ 4 | printf("%d %s\n", !!f, #f); 5 | 6 | int printf(const char*, ...); 7 | 8 | void check_exports() 9 | { 10 | // 0 11 | GOT(inline_inline_2decl_only) 12 | GOT(inline_inline_undeclared) 13 | GOT(inline_inline_predeclared) 14 | GOT(inline_inline_postdeclared) 15 | GOT(inline_inline_prepostdeclared) 16 | GOT(inline_inline_undeclared2) 17 | GOT(inline_inline_predeclared2) 18 | GOT(inline_inline_postdeclared2) 19 | GOT(inline_inline_prepostdeclared2) 20 | 21 | // 1 22 | GOT(extern_extern_postdeclared) 23 | GOT(extern_extern_postdeclared2) 24 | GOT(extern_extern_predeclared) 25 | GOT(extern_extern_predeclared2) 26 | GOT(extern_extern_prepostdeclared) 27 | GOT(extern_extern_prepostdeclared2) 28 | GOT(extern_extern_undeclared) 29 | GOT(extern_extern_undeclared2) 30 | GOT(extern_postdeclared) 31 | GOT(extern_postdeclared2) 32 | GOT(extern_predeclared) 33 | GOT(extern_predeclared2) 34 | GOT(extern_prepostdeclared) 35 | GOT(extern_undeclared) 36 | GOT(extern_undeclared2) 37 | GOT(inst2_extern_inline_postdeclared) 38 | GOT(inst2_extern_inline_predeclared) 39 | GOT(inst3_extern_inline_predeclared) 40 | GOT(inst_extern_inline_postdeclared) 41 | GOT(inst_extern_inline_predeclared) 42 | GOT(main) 43 | GOT(noinst_extern_inline_func) 44 | GOT(noinst_extern_inline_postdeclared) 45 | GOT(noinst_extern_inline_postdeclared2) 46 | GOT(noinst_extern_inline_undeclared) 47 | 48 | // 0 49 | GOT(noinst_static_inline_postdeclared) 50 | GOT(noinst2_static_inline_postdeclared) 51 | GOT(noinst_static_inline_predeclared) 52 | GOT(noinst2_static_inline_predeclared) 53 | GOT(static_func) 54 | } 55 | -------------------------------------------------------------------------------- /tests/tests2/90_struct-init.expect: -------------------------------------------------------------------------------- 1 | ce: 1 12 2 | gs: 1 2 3 4 3 | gs2: 1 2 3 4 4 | gt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a 5 | gu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 6 | gu2: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 7 | gu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 8 | gu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c 9 | gs3: 1 2 3 4 10 | gv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e 11 | gv2: 7 8 9 a 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 12 | gv3: 7 8 9 a 68 6f 68 6f 0 0 0 0 0 0 0 0 0 0 0 0 31 32 13 | sinit16: 1 0 0 0 2 0 0 0 14 | gw: 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 | gsu: 5 6 16 | guv: 6 5 0 0 17 | guv.b: 5 18 | guv2: 8 7 0 0 19 | guv3: 7 8 0 0 20 | gssu1: 5 0 0 0 3 0 0 0 21 | gssu2: 5 0 0 0 3 0 0 0 22 | phdr: 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 23 | ls: 1 2 3 4 24 | ls2: 1 2 3 4 25 | lt: 68 65 6c 6c 6f 0 0 0 0 0 0 0 0 0 0 0 2a 26 | lu: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 27 | lu1: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 28 | lu2: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 29 | ls21: 1 2 3 4 30 | lu21: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 31 | lu22: 3 1 2 3 4 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 32 | lu3: 3 5 6 7 8 4 68 75 68 75 0 0 0 0 0 0 0 0 0 0 0 0 2b 33 | lu4: 3 5 6 7 0 5 62 6c 61 0 0 0 0 0 0 0 0 0 0 0 0 0 2c 34 | ls3: 1 2 3 4 35 | lv: 3 4 5 6 68 61 68 61 0 0 0 0 0 0 0 0 0 0 0 0 2d 2e 36 | lv2: 1 2 3 4 68 69 68 69 0 0 0 0 0 0 0 0 0 0 0 0 2f 30 37 | lv3: 7 8 9 a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 38 | lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1 39 | lssu1: 5 0 0 0 3 0 0 0 40 | lssu2: 5 0 0 0 3 0 0 0 41 | flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 42 | ls4: 1 2 3 4 43 | one 44 | two 45 | three 46 | sea_fill0: okay 47 | sea_fill1: okay 48 | sea_fill2: okay 49 | -------------------------------------------------------------------------------- /win32/include/signal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SIGNAL 7 | #define _INC_SIGNAL 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _SIG_ATOMIC_T_DEFINED 16 | #define _SIG_ATOMIC_T_DEFINED 17 | typedef int sig_atomic_t; 18 | #endif 19 | 20 | #define NSIG 23 21 | 22 | #define SIGHUP 1 /* hangup */ 23 | #define SIGINT 2 24 | #define SIGQUIT 3 /* quit */ 25 | #define SIGILL 4 26 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 27 | #define SIGIOT 6 /* IOT instruction */ 28 | #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ 29 | #define SIGEMT 7 /* EMT instruction */ 30 | #define SIGFPE 8 31 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 32 | #define SIGBUS 10 /* bus error */ 33 | #define SIGSEGV 11 34 | #define SIGSYS 12 /* bad argument to system call */ 35 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 36 | #ifdef __USE_MINGW_ALARM 37 | #define SIGALRM 14 /* alarm clock */ 38 | #endif 39 | #define SIGTERM 15 40 | #define SIGBREAK 21 41 | #define SIGABRT2 22 42 | 43 | #define SIGABRT_COMPAT 6 44 | 45 | typedef void (*__p_sig_fn_t)(int); 46 | 47 | #define SIG_DFL (__p_sig_fn_t)0 48 | #define SIG_IGN (__p_sig_fn_t)1 49 | #define SIG_GET (__p_sig_fn_t)2 50 | #define SIG_SGE (__p_sig_fn_t)3 51 | #define SIG_ACK (__p_sig_fn_t)4 52 | #define SIG_ERR (__p_sig_fn_t)-1 53 | 54 | extern void **__cdecl __pxcptinfoptrs(void); 55 | #define _pxcptinfoptrs (*__pxcptinfoptrs()) 56 | 57 | __p_sig_fn_t __cdecl signal(int _SigNum,__p_sig_fn_t _Func); 58 | int __cdecl raise(int _SigNum); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /tests/tests2/30_hanoi.expect: -------------------------------------------------------------------------------- 1 | Solution of Tower of Hanoi Problem with 4 Disks 2 | 3 | Starting state: 4 | A: 1 2 3 4 5 | B: 0 0 0 0 6 | C: 0 0 0 0 7 | ------------------------------------------ 8 | 9 | 10 | Subsequent states: 11 | 12 | A: 0 2 3 4 13 | B: 0 0 0 0 14 | C: 0 0 0 1 15 | ------------------------------------------ 16 | A: 0 0 3 4 17 | B: 0 0 0 2 18 | C: 0 0 0 1 19 | ------------------------------------------ 20 | A: 0 0 3 4 21 | B: 0 0 1 2 22 | C: 0 0 0 0 23 | ------------------------------------------ 24 | A: 0 0 0 4 25 | B: 0 0 1 2 26 | C: 0 0 0 3 27 | ------------------------------------------ 28 | A: 0 0 1 4 29 | B: 0 0 0 2 30 | C: 0 0 0 3 31 | ------------------------------------------ 32 | A: 0 0 1 4 33 | B: 0 0 0 0 34 | C: 0 0 2 3 35 | ------------------------------------------ 36 | A: 0 0 0 4 37 | B: 0 0 0 0 38 | C: 0 1 2 3 39 | ------------------------------------------ 40 | A: 0 0 0 0 41 | B: 0 0 0 4 42 | C: 0 1 2 3 43 | ------------------------------------------ 44 | A: 0 0 0 0 45 | B: 0 0 1 4 46 | C: 0 0 2 3 47 | ------------------------------------------ 48 | A: 0 0 0 2 49 | B: 0 0 1 4 50 | C: 0 0 0 3 51 | ------------------------------------------ 52 | A: 0 0 1 2 53 | B: 0 0 0 4 54 | C: 0 0 0 3 55 | ------------------------------------------ 56 | A: 0 0 1 2 57 | B: 0 0 3 4 58 | C: 0 0 0 0 59 | ------------------------------------------ 60 | A: 0 0 0 2 61 | B: 0 0 3 4 62 | C: 0 0 0 1 63 | ------------------------------------------ 64 | A: 0 0 0 0 65 | B: 0 2 3 4 66 | C: 0 0 0 1 67 | ------------------------------------------ 68 | A: 0 0 0 0 69 | B: 1 2 3 4 70 | C: 0 0 0 0 71 | ------------------------------------------ 72 | -------------------------------------------------------------------------------- /win32/lib/chkstk.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* chkstk86.s */ 3 | 4 | /* ---------------------------------------------- */ 5 | #ifndef __x86_64__ 6 | /* ---------------------------------------------- */ 7 | 8 | .globl __chkstk 9 | 10 | __chkstk: 11 | xchg (%esp),%ebp /* store ebp, get ret.addr */ 12 | push %ebp /* push ret.addr */ 13 | lea 4(%esp),%ebp /* setup frame ptr */ 14 | push %ecx /* save ecx */ 15 | mov %ebp,%ecx 16 | P0: 17 | sub $4096,%ecx 18 | test %eax,(%ecx) 19 | sub $4096,%eax 20 | cmp $4096,%eax 21 | jge P0 22 | sub %eax,%ecx 23 | test %eax,(%ecx) 24 | 25 | mov %esp,%eax 26 | mov %ecx,%esp 27 | mov (%eax),%ecx /* restore ecx */ 28 | jmp *4(%eax) 29 | 30 | /* ---------------------------------------------- */ 31 | #else 32 | /* ---------------------------------------------- */ 33 | 34 | .globl __chkstk 35 | 36 | __chkstk: 37 | xchg (%rsp),%rbp /* store ebp, get ret.addr */ 38 | push %rbp /* push ret.addr */ 39 | lea 8(%rsp),%rbp /* setup frame ptr */ 40 | push %rcx /* save ecx */ 41 | mov %rbp,%rcx 42 | movslq %eax,%rax 43 | P0: 44 | sub $4096,%rcx 45 | test %rax,(%rcx) 46 | sub $4096,%rax 47 | cmp $4096,%rax 48 | jge P0 49 | sub %rax,%rcx 50 | test %rax,(%rcx) 51 | 52 | mov %rsp,%rax 53 | mov %rcx,%rsp 54 | mov (%rax),%rcx /* restore ecx */ 55 | jmp *8(%rax) 56 | 57 | /* ---------------------------------------------- */ 58 | /* setjmp/longjmp support */ 59 | 60 | .globl tinyc_getbp 61 | tinyc_getbp: 62 | mov %rbp,%rax 63 | ret 64 | 65 | /* ---------------------------------------------- */ 66 | #endif 67 | /* ---------------------------------------------- */ 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/tests2/79_vla_continue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(void) 4 | { 5 | return 5; 6 | } 7 | 8 | void test1() 9 | { 10 | int count = 10; 11 | void *addr[10]; 12 | for(;count--;) { 13 | int a[f()]; 14 | 15 | addr[count] = a; 16 | 17 | continue; 18 | } 19 | 20 | if(addr[9] == addr[0]) { 21 | printf("OK\n"); 22 | } else { 23 | printf("NOT OK\n"); 24 | } 25 | } 26 | 27 | void test2() 28 | { 29 | int count = 10; 30 | void *addr[count]; 31 | for(;count--;) { 32 | int a[f()]; 33 | 34 | addr[count] = a; 35 | 36 | continue; 37 | } 38 | 39 | if(addr[9] == addr[0]) { 40 | printf("OK\n"); 41 | } else { 42 | printf("NOT OK\n"); 43 | } 44 | } 45 | 46 | void test3() 47 | { 48 | int count = 10; 49 | void *addr[count]; 50 | while(count--) { 51 | int a[f()]; 52 | 53 | addr[count] = a; 54 | 55 | continue; 56 | } 57 | 58 | if(addr[9] == addr[0]) { 59 | printf("OK\n"); 60 | } else { 61 | printf("NOT OK\n"); 62 | } 63 | } 64 | 65 | void test4() 66 | { 67 | int count = 10; 68 | void *addr[count]; 69 | do { 70 | int a[f()]; 71 | 72 | addr[--count] = a; 73 | 74 | continue; 75 | } while (count); 76 | 77 | if(addr[9] == addr[0]) { 78 | printf("OK\n"); 79 | } else { 80 | printf("NOT OK\n"); 81 | } 82 | } 83 | 84 | void test5() 85 | { 86 | int count = 10; 87 | int a[f()]; 88 | int c[f()]; 89 | 90 | c[0] = 42; 91 | 92 | for(;count--;) { 93 | int b[f()]; 94 | int i; 95 | for (i=0; i 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _strset_s(char *_Dst,size_t _DstSize,int _Value); 18 | _CRTIMP errno_t __cdecl _strerror_s(char *_Buf,size_t _SizeInBytes,const char *_ErrMsg); 19 | _CRTIMP errno_t __cdecl _strlwr_s(char *_Str,size_t _Size); 20 | _CRTIMP errno_t __cdecl _strlwr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 21 | _CRTIMP errno_t __cdecl _strnset_s(char *_Str,size_t _Size,int _Val,size_t _MaxCount); 22 | _CRTIMP errno_t __cdecl _strupr_s(char *_Str,size_t _Size); 23 | _CRTIMP errno_t __cdecl _strupr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 24 | #ifndef _WSTRING_S_DEFINED 25 | #define _WSTRING_S_DEFINED 26 | _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context); 27 | _CRTIMP errno_t __cdecl _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum); 28 | _CRTIMP errno_t __cdecl __wcserror_s(wchar_t *_Buffer,size_t _SizeInWords,const wchar_t *_ErrMsg); 29 | _CRTIMP errno_t __cdecl _wcsnset_s(wchar_t *_Dst,size_t _DstSizeInWords,wchar_t _Val,size_t _MaxCount); 30 | _CRTIMP errno_t __cdecl _wcsset_s(wchar_t *_Str,size_t _SizeInWords,wchar_t _Val); 31 | _CRTIMP errno_t __cdecl _wcslwr_s(wchar_t *_Str,size_t _SizeInWords); 32 | _CRTIMP errno_t __cdecl _wcslwr_s_l(wchar_t *_Str,size_t _SizeInWords,_locale_t _Locale); 33 | _CRTIMP errno_t __cdecl _wcsupr_s(wchar_t *_Str,size_t _Size); 34 | _CRTIMP errno_t __cdecl _wcsupr_s_l(wchar_t *_Str,size_t _Size,_locale_t _Locale); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /tests/tests2/LICENSE: -------------------------------------------------------------------------------- 1 | The tests in this directory are either directly copied from the picoc project or 2 | are subsequently modified and added to for the purpose of TinyCC project. All 3 | these modifications are licensed under the same terms as TinyCC as specified in 4 | the file COPYING. 5 | 6 | === picoc license === 7 | 8 | Copyright (c) 2009-2011, Zik Saleeba 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in 20 | the documentation and/or other materials provided with the 21 | distribution. 22 | 23 | * Neither the name of the Zik Saleeba nor the names of its 24 | contributors may be used to endorse or promote products derived 25 | from this software without specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /tests/vla_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test that allocating a variable length array in a loop 3 | * does not use up a linear amount of memory 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define LOOP_COUNT 1000 11 | #define ARRAY_SIZE 100 12 | 13 | /* Overwrite a VLA. This will overwrite the return address if SP is incorrect */ 14 | void smash(char *p, int n) { 15 | memset(p, 0, n); 16 | } 17 | 18 | int test1(int n) { 19 | int i; 20 | char *array_ptrs[LOOP_COUNT]; 21 | 22 | for (i = 0; i < LOOP_COUNT; ++i) { 23 | char test[n]; 24 | smash(test, n); 25 | array_ptrs[i] = test; 26 | } 27 | 28 | return (array_ptrs[0]-array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; 29 | } 30 | 31 | /* ensure goto does not circumvent array free */ 32 | int test2(int n) { 33 | char *array_ptrs[LOOP_COUNT]; 34 | 35 | int i = 0; 36 | loop:; 37 | char test[n]; 38 | smash(test, n); 39 | if (i >= LOOP_COUNT) 40 | goto end; 41 | array_ptrs[i] = test; 42 | ++i; 43 | goto loop; 44 | 45 | end: 46 | smash(test, n); 47 | char test2[n]; 48 | smash(test2, n); 49 | return (array_ptrs[0] - array_ptrs[LOOP_COUNT-1] < n) ? 0 : 1; 50 | } 51 | 52 | int test3(int n) { 53 | char test[n]; 54 | smash(test, n); 55 | goto label; 56 | label: 57 | smash(test, n); 58 | char test2[n]; 59 | smash(test2, n); 60 | return (test-test2 >= n) ? 0 : 1; 61 | } 62 | 63 | #define RUN_TEST(t) \ 64 | if (!testname || (strcmp(#t, testname) == 0)) { \ 65 | fputs(#t "... ", stdout); \ 66 | fflush(stdout); \ 67 | if (t(ARRAY_SIZE) == 0) { \ 68 | fputs("success\n", stdout); \ 69 | } else { \ 70 | fputs("failure\n", stdout); \ 71 | retval = EXIT_FAILURE; \ 72 | } \ 73 | } 74 | 75 | int main(int argc, char **argv) { 76 | const char *testname = NULL; 77 | int retval = EXIT_SUCCESS; 78 | if (argc > 1) 79 | testname = argv[1]; 80 | RUN_TEST(test1) 81 | RUN_TEST(test2) 82 | RUN_TEST(test3) 83 | return retval; 84 | } 85 | -------------------------------------------------------------------------------- /win32/include/sys/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _SYS_TIME_H_ 8 | #define _SYS_TIME_H_ 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifndef __STRICT_ANSI__ 17 | #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ 18 | #define _TIMEVAL_DEFINED 19 | struct timeval { 20 | long tv_sec; 21 | long tv_usec; 22 | }; 23 | #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 24 | #define timercmp(tvp, uvp, cmp) \ 25 | (((tvp)->tv_sec != (uvp)->tv_sec) ? \ 26 | ((tvp)->tv_sec cmp (uvp)->tv_sec) : \ 27 | ((tvp)->tv_usec cmp (uvp)->tv_usec)) 28 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 29 | #endif /* _TIMEVAL_DEFINED */ 30 | 31 | #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ 32 | #define _TIMEZONE_DEFINED 33 | /* Provided for compatibility with code that assumes that 34 | the presence of gettimeofday function implies a definition 35 | of struct timezone. */ 36 | struct timezone 37 | { 38 | int tz_minuteswest; /* of Greenwich */ 39 | int tz_dsttime; /* type of dst correction to apply */ 40 | }; 41 | 42 | extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); 43 | 44 | #endif 45 | 46 | /* 47 | Implementation as per: 48 | The Open Group Base Specifications, Issue 6 49 | IEEE Std 1003.1, 2004 Edition 50 | 51 | The timezone pointer arg is ignored. Errors are ignored. 52 | */ 53 | #ifndef _GETTIMEOFDAY_DEFINED 54 | #define _GETTIMEOFDAY_DEFINED 55 | int __cdecl gettimeofday(struct timeval *__restrict__, 56 | void *__restrict__ /* tzp (unused) */); 57 | #endif 58 | 59 | #endif /* __STRICT_ANSI__ */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /* Adding timespec definition. */ 66 | #include 67 | 68 | 69 | #endif /* _SYS_TIME_H_ */ 70 | -------------------------------------------------------------------------------- /lib/va_list.c: -------------------------------------------------------------------------------- 1 | /* va_list.c - tinycc support for va_list on X86_64 */ 2 | 3 | #if defined __x86_64__ 4 | 5 | /* Avoid include files, they may not be available when cross compiling */ 6 | extern void *memset(void *s, int c, __SIZE_TYPE__ n); 7 | extern void abort(void); 8 | 9 | /* This should be in sync with our include/stdarg.h */ 10 | enum __va_arg_type { 11 | __va_gen_reg, __va_float_reg, __va_stack 12 | }; 13 | 14 | /* GCC compatible definition of va_list. */ 15 | typedef struct { 16 | unsigned int gp_offset; 17 | unsigned int fp_offset; 18 | union { 19 | unsigned int overflow_offset; 20 | char *overflow_arg_area; 21 | }; 22 | char *reg_save_area; 23 | } __va_list_struct; 24 | 25 | void __va_start(__va_list_struct *ap, void *fp) 26 | { 27 | memset(ap, 0, sizeof(__va_list_struct)); 28 | *ap = *(__va_list_struct *)((char *)fp - 16); 29 | ap->overflow_arg_area = (char *)fp + ap->overflow_offset; 30 | ap->reg_save_area = (char *)fp - 176 - 16; 31 | } 32 | 33 | void *__va_arg(__va_list_struct *ap, 34 | enum __va_arg_type arg_type, 35 | int size, int align) 36 | { 37 | size = (size + 7) & ~7; 38 | align = (align + 7) & ~7; 39 | switch (arg_type) { 40 | case __va_gen_reg: 41 | if (ap->gp_offset + size <= 48) { 42 | ap->gp_offset += size; 43 | return ap->reg_save_area + ap->gp_offset - size; 44 | } 45 | goto use_overflow_area; 46 | 47 | case __va_float_reg: 48 | if (ap->fp_offset < 128 + 48) { 49 | ap->fp_offset += 16; 50 | return ap->reg_save_area + ap->fp_offset - 16; 51 | } 52 | size = 8; 53 | goto use_overflow_area; 54 | 55 | case __va_stack: 56 | use_overflow_area: 57 | ap->overflow_arg_area += size; 58 | ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); 59 | return ap->overflow_arg_area - size; 60 | 61 | default: /* should never happen */ 62 | abort(); 63 | return 0; 64 | } 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Tiny C Compiler Makefile for libtcc1.a 3 | # 4 | 5 | TOP = .. 6 | include $(TOP)/Makefile 7 | VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib 8 | T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) 9 | X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) 10 | BIN = $(TOP)/$(X)libtcc1.a 11 | 12 | XTCC ?= $(TOP)/$(X)tcc$(EXESUF) 13 | XCC = $(XTCC) 14 | XAR = $(XTCC) -ar 15 | XFLAGS-unx = -B$(TOPSRC) 16 | XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include 17 | XFLAGS = $(XFLAGS$(XCFG)) 18 | XCFG = $(or $(findstring -win,$T),-unx) 19 | 20 | # in order to use gcc, tyoe: make -libtcc1-usegcc=yes 21 | arm-libtcc1-usegcc ?= no 22 | 23 | ifeq "$($(T)-libtcc1-usegcc)" "yes" 24 | XCC = $(CC) 25 | XAR = $(AR) 26 | XFLAGS = $(CFLAGS) -fPIC 27 | endif 28 | 29 | # only for native compiler 30 | $(X)BCHECK_O = bcheck.o 31 | 32 | ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes) 33 | BCHECK_O = 34 | else 35 | DSO_O = dsohandle.o 36 | endif 37 | 38 | ifdef CONFIG_OSX 39 | XFLAGS += -D_ANSI_SOURCE 40 | endif 41 | 42 | I386_O = libtcc1.o alloca86.o alloca86-bt.o 43 | X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o 44 | ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o 45 | ARM64_O = lib-arm64.o 46 | RISCV64_O = lib-arm64.o 47 | WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o 48 | 49 | OBJ-i386 = $(I386_O) $(BCHECK_O) $(DSO_O) 50 | OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O) $(DSO_O) 51 | OBJ-x86_64-osx = $(X86_64_O) va_list.o 52 | OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O) 53 | OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O) 54 | OBJ-arm64 = $(ARM64_O) $(DSO_O) 55 | OBJ-arm = $(ARM_O) $(DSO_O) 56 | OBJ-arm-fpa = $(ARM_O) $(DSO_O) 57 | OBJ-arm-fpa-ld = $(ARM_O) $(DSO_O) 58 | OBJ-arm-vfp = $(ARM_O) $(DSO_O) 59 | OBJ-arm-eabi = $(ARM_O) $(DSO_O) 60 | OBJ-arm-eabihf = $(ARM_O) $(DSO_O) 61 | OBJ-arm-wince = $(ARM_O) $(WIN_O) 62 | OBJ-riscv64 = $(RISCV64_O) $(DSO_O) 63 | 64 | $(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T)) 65 | $(XAR) rcs $@ $^ 66 | 67 | $(X)%.o : %.c 68 | $(XCC) -c $< -o $@ $(XFLAGS) 69 | 70 | $(X)%.o : %.S 71 | $(XCC) -c $< -o $@ $(XFLAGS) 72 | 73 | $(X)crt1w.o : crt1.c 74 | $(X)wincrt1w.o : wincrt1.c 75 | 76 | clean : 77 | rm -f *.a *.o $(BIN) 78 | -------------------------------------------------------------------------------- /tests/tests2/82_attribs_position.c: -------------------------------------------------------------------------------- 1 | typedef unsigned short uint16_t; 2 | typedef unsigned char uint8_t; 3 | 4 | typedef union Unaligned16a { 5 | uint16_t u; 6 | uint8_t b[2]; 7 | } __attribute__((packed)) Unaligned16a; 8 | 9 | typedef union __attribute__((packed)) Unaligned16b { 10 | uint16_t u; 11 | uint8_t b[2]; 12 | } Unaligned16b; 13 | 14 | extern void foo (void) __attribute__((stdcall)); 15 | void __attribute__((stdcall)) foo (void) 16 | { 17 | } 18 | 19 | #define __stdcall __attribute__((stdcall)) 20 | extern int some_stdcall_func (int, int, int) __stdcall; 21 | __stdcall int __stdcall some_stdcall_func(int foo, int bar, int baz) { 22 | //printf("Hello from stdcall: %i %i %i\n", foo, bar, baz); 23 | return 43; 24 | } 25 | 26 | /* The actual attribute isn't important, must just be 27 | parsable. */ 28 | #define ATTR __attribute__((__noinline__)) 29 | int ATTR actual_function() { 30 | return 42; 31 | } 32 | 33 | extern int printf (const char *, ...); 34 | static int globalvar; 35 | int main() 36 | { 37 | void *function_pointer = &actual_function; 38 | int localvar = 42, i; 39 | 40 | int a = ((ATTR int(*) (void)) function_pointer)(); 41 | printf("%i\n", a); 42 | 43 | /* In the following we once misparsed 'ATTR *' is a btype 44 | and hence the whole type was garbled. */ 45 | int b = ( (int(ATTR *)(void)) function_pointer)(); 46 | printf("%i\n", b); 47 | 48 | /* All these should work and leave the stack pointer in its original 49 | position. */ 50 | some_stdcall_func(1, 10, 100); 51 | ((int __stdcall (*)(int, int, int))some_stdcall_func) (2, 20, 200); 52 | ((int(*__stdcall)(int, int, int))some_stdcall_func) (3, 30, 300); 53 | for (i = 0; i < 1024; i++) { 54 | globalvar = i; 55 | /* This was once misparsed at <= gitrev 325241c0, forgetting 56 | the stdcall attribute on the function pointer leading to 57 | stack increment being done twice (in callee and caller). 58 | This will clobber 'i' and 'localvar' which is how we detect 59 | this. */ 60 | ((int(__stdcall*)(int, int, int))some_stdcall_func) (4, 40, 400); 61 | if (localvar != 42 || globalvar != i) 62 | printf("error, localvar=%d i=%d globalvar=%d\n", localvar, i, globalvar); 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /win32/include/direct.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DIRECT 7 | #define _INC_DIRECT 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | struct _diskfree_t { 21 | unsigned total_clusters; 22 | unsigned avail_clusters; 23 | unsigned sectors_per_cluster; 24 | unsigned bytes_per_sector; 25 | }; 26 | #endif 27 | 28 | _CRTIMP char *__cdecl _getcwd(char *_DstBuf,int _SizeInBytes); 29 | _CRTIMP char *__cdecl _getdcwd(int _Drive,char *_DstBuf,int _SizeInBytes); 30 | char *__cdecl _getdcwd_nolock(int _Drive,char *_DstBuf,int _SizeInBytes); 31 | _CRTIMP int __cdecl _chdir(const char *_Path); 32 | _CRTIMP int __cdecl _mkdir(const char *_Path); 33 | _CRTIMP int __cdecl _rmdir(const char *_Path); 34 | _CRTIMP int __cdecl _chdrive(int _Drive); 35 | _CRTIMP int __cdecl _getdrive(void); 36 | _CRTIMP unsigned long __cdecl _getdrives(void); 37 | 38 | #ifndef _GETDISKFREE_DEFINED 39 | #define _GETDISKFREE_DEFINED 40 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 41 | #endif 42 | 43 | #ifndef _WDIRECT_DEFINED 44 | #define _WDIRECT_DEFINED 45 | _CRTIMP wchar_t *__cdecl _wgetcwd(wchar_t *_DstBuf,int _SizeInWords); 46 | _CRTIMP wchar_t *__cdecl _wgetdcwd(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 47 | wchar_t *__cdecl _wgetdcwd_nolock(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 48 | _CRTIMP int __cdecl _wchdir(const wchar_t *_Path); 49 | _CRTIMP int __cdecl _wmkdir(const wchar_t *_Path); 50 | _CRTIMP int __cdecl _wrmdir(const wchar_t *_Path); 51 | #endif 52 | 53 | #ifndef NO_OLDNAMES 54 | 55 | #define diskfree_t _diskfree_t 56 | 57 | char *__cdecl getcwd(char *_DstBuf,int _SizeInBytes); 58 | int __cdecl chdir(const char *_Path); 59 | int __cdecl mkdir(const char *_Path); 60 | int __cdecl rmdir(const char *_Path); 61 | #endif 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #pragma pack(pop) 68 | #endif 69 | -------------------------------------------------------------------------------- /arm-asm.c: -------------------------------------------------------------------------------- 1 | /*************************************************************/ 2 | /* 3 | * ARM dummy assembler for TCC 4 | * 5 | */ 6 | 7 | #ifdef TARGET_DEFS_ONLY 8 | 9 | #define CONFIG_TCC_ASM 10 | #define NB_ASM_REGS 16 11 | 12 | ST_FUNC void g(int c); 13 | ST_FUNC void gen_le16(int c); 14 | ST_FUNC void gen_le32(int c); 15 | 16 | /*************************************************************/ 17 | #else 18 | /*************************************************************/ 19 | 20 | #include "tcc.h" 21 | 22 | static void asm_error(void) 23 | { 24 | tcc_error("ARM asm not implemented."); 25 | } 26 | 27 | /* XXX: make it faster ? */ 28 | ST_FUNC void g(int c) 29 | { 30 | int ind1; 31 | if (nocode_wanted) 32 | return; 33 | ind1 = ind + 1; 34 | if (ind1 > cur_text_section->data_allocated) 35 | section_realloc(cur_text_section, ind1); 36 | cur_text_section->data[ind] = c; 37 | ind = ind1; 38 | } 39 | 40 | ST_FUNC void gen_le16 (int i) 41 | { 42 | g(i); 43 | g(i>>8); 44 | } 45 | 46 | ST_FUNC void gen_le32 (int i) 47 | { 48 | gen_le16(i); 49 | gen_le16(i>>16); 50 | } 51 | 52 | ST_FUNC void gen_expr32(ExprValue *pe) 53 | { 54 | gen_le32(pe->v); 55 | } 56 | 57 | ST_FUNC void asm_opcode(TCCState *s1, int opcode) 58 | { 59 | asm_error(); 60 | } 61 | 62 | ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier) 63 | { 64 | asm_error(); 65 | } 66 | 67 | /* generate prolog and epilog code for asm statement */ 68 | ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, 69 | int nb_outputs, int is_output, 70 | uint8_t *clobber_regs, 71 | int out_reg) 72 | { 73 | } 74 | 75 | ST_FUNC void asm_compute_constraints(ASMOperand *operands, 76 | int nb_operands, int nb_outputs, 77 | const uint8_t *clobber_regs, 78 | int *pout_reg) 79 | { 80 | } 81 | 82 | ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) 83 | { 84 | asm_error(); 85 | } 86 | 87 | ST_FUNC int asm_parse_regvar (int t) 88 | { 89 | asm_error(); 90 | return -1; 91 | } 92 | 93 | /*************************************************************/ 94 | #endif /* ndef TARGET_DEFS_ONLY */ 95 | -------------------------------------------------------------------------------- /win32/include/winapi/qos.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __QOS_H_ 7 | #define __QOS_H_ 8 | 9 | typedef ULONG SERVICETYPE; 10 | 11 | #define SERVICETYPE_NOTRAFFIC 0x00000000 12 | #define SERVICETYPE_BESTEFFORT 0x00000001 13 | #define SERVICETYPE_CONTROLLEDLOAD 0x00000002 14 | #define SERVICETYPE_GUARANTEED 0x00000003 15 | 16 | #define SERVICETYPE_NETWORK_UNAVAILABLE 0x00000004 17 | #define SERVICETYPE_GENERAL_INFORMATION 0x00000005 18 | #define SERVICETYPE_NOCHANGE 0x00000006 19 | #define SERVICETYPE_NONCONFORMING 0x00000009 20 | #define SERVICETYPE_NETWORK_CONTROL 0x0000000A 21 | #define SERVICETYPE_QUALITATIVE 0x0000000D 22 | 23 | #define SERVICE_BESTEFFORT 0x80010000 24 | #define SERVICE_CONTROLLEDLOAD 0x80020000 25 | #define SERVICE_GUARANTEED 0x80040000 26 | #define SERVICE_QUALITATIVE 0x80200000 27 | 28 | #define SERVICE_NO_TRAFFIC_CONTROL 0x81000000 29 | 30 | #define SERVICE_NO_QOS_SIGNALING 0x40000000 31 | 32 | typedef struct _flowspec { 33 | ULONG TokenRate; 34 | ULONG TokenBucketSize; 35 | ULONG PeakBandwidth; 36 | ULONG Latency; 37 | ULONG DelayVariation; 38 | SERVICETYPE ServiceType; 39 | ULONG MaxSduSize; 40 | ULONG MinimumPolicedSize; 41 | } FLOWSPEC,*PFLOWSPEC,*LPFLOWSPEC; 42 | 43 | #define QOS_NOT_SPECIFIED 0xFFFFFFFF 44 | #define POSITIVE_INFINITY_RATE 0xFFFFFFFE 45 | 46 | typedef struct { 47 | ULONG ObjectType; 48 | ULONG ObjectLength; 49 | } QOS_OBJECT_HDR,*LPQOS_OBJECT_HDR; 50 | 51 | #define QOS_GENERAL_ID_BASE 2000 52 | #define QOS_OBJECT_END_OF_LIST (0x00000001 + QOS_GENERAL_ID_BASE) 53 | #define QOS_OBJECT_SD_MODE (0x00000002 + QOS_GENERAL_ID_BASE) 54 | #define QOS_OBJECT_SHAPING_RATE (0x00000003 + QOS_GENERAL_ID_BASE) 55 | #define QOS_OBJECT_DESTADDR (0x00000004 + QOS_GENERAL_ID_BASE) 56 | 57 | typedef struct _QOS_SD_MODE { 58 | QOS_OBJECT_HDR ObjectHdr; 59 | ULONG ShapeDiscardMode; 60 | } QOS_SD_MODE,*LPQOS_SD_MODE; 61 | 62 | #define TC_NONCONF_BORROW 0 63 | #define TC_NONCONF_SHAPE 1 64 | #define TC_NONCONF_DISCARD 2 65 | #define TC_NONCONF_BORROW_PLUS 3 66 | 67 | typedef struct _QOS_SHAPING_RATE { 68 | QOS_OBJECT_HDR ObjectHdr; 69 | ULONG ShapingRate; 70 | } QOS_SHAPING_RATE,*LPQOS_SHAPING_RATE; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /CodingStyle: -------------------------------------------------------------------------------- 1 | 2 | In general, use the same coding style as the surrounding code. 3 | 4 | However, do not make any unnecessary changes as that complicates 5 | the VCS (git) history and makes it harder to merge patches. So 6 | do not modify code just to make it conform to a coding style. 7 | 8 | Indentation 9 | 10 | Turn on a "fill tabs with spaces" option in your editor. 11 | 12 | Remove tabs and trailing spaces from any lines that are modified. 13 | 14 | Note that some files are indented with 2 spaces (when they 15 | have large indentation) while most are indented with 4 spaces. 16 | 17 | Language 18 | 19 | TCC is mostly implemented in C90. Do not use any non-C90 features 20 | that are not already in use. 21 | 22 | Non-C90 features currently in use, as revealed by 23 | ./configure --extra-cflags="-std=c90 -Wpedantic": 24 | 25 | - long long (including "LL" constants) 26 | - inline 27 | - very long string constants 28 | - assignment between function pointer and 'void *' 29 | - "//" comments 30 | - empty macro arguments (DEF_ASMTEST in i386-tok.h) 31 | - unnamed struct and union fields (in struct Sym), a C11 feature 32 | 33 | Testing 34 | 35 | A simple "make test" is sufficient for some simple changes. However, 36 | before committing a change consider performing some of the following 37 | additional tests: 38 | 39 | - Build and run "make test" on several architectures. 40 | 41 | - Build with ./configure --enable-cross. 42 | 43 | - If the generation of relocations has been changed, try compiling 44 | with TCC and linking with GCC/Clang. If the linker has been 45 | modified, try compiling with GCC/Clang and linking with TCC. 46 | 47 | - Test with ASan/UBSan to detect memory corruption and undefined behaviour: 48 | 49 | make clean 50 | ./configure 51 | make 52 | make test 53 | cp libtcc.a libtcc.a.hide 54 | 55 | make clean 56 | ./configure --extra-cflags="-fsanitize=address,undefined -g" 57 | make 58 | cp libtcc.a.hide libtcc.a 59 | make test 60 | 61 | - Test with Valgrind to detect some uses of uninitialised values: 62 | 63 | make clean 64 | ./configure 65 | make 66 | # On Intel, because Valgrind does floating-point arithmetic differently: 67 | ( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref ) 68 | make test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`" 69 | 70 | (Because of how VLAs are implemented, invalid reads are expected 71 | with 79_vla_continue.) 72 | -------------------------------------------------------------------------------- /tests/tests2/70_floating_point_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | /* decimal floating constant */ 6 | float fa0 = .123f; 7 | float fa1 = .123E12F; 8 | float fa2 = .123e-12f; 9 | float fa3 = .123e+12f; 10 | printf("%f\n%f\n%f\n%f\n\n", fa0, fa1, fa2, fa3); 11 | 12 | float fb0 = 123.123f; 13 | float fb1 = 123.123E12F; 14 | float fb2 = 123.123e-12f; 15 | float fb3 = 123.123e+12f; 16 | printf("%f\n%f\n%f\n%f\n\n", fb0, fb1, fb2, fb3); 17 | 18 | float fc0 = 123.f; 19 | float fc1 = 123.E12F; 20 | float fc2 = 123.e-12f; 21 | float fc3 = 123.e+12f; 22 | printf("%f\n%f\n%f\n%f\n\n", fc0, fc1, fc2, fc3); 23 | 24 | float fd0 = 123E12F; 25 | float fd1 = 123e-12f; 26 | float fd2 = 123e+12f; 27 | printf("%f\n%f\n%f\n\n", fd0, fd1, fd2); 28 | printf("\n"); 29 | 30 | /* hexadecimal floating constant */ 31 | double da0 = 0X.1ACP12; 32 | double da1 = 0x.1acp-12; 33 | double da2 = 0x.1acp+12; 34 | printf("%f\n%f\n%f\n\n", da0, da1, da2); 35 | 36 | double db0 = 0X1AC.BDP12; 37 | double db1 = 0x1ac.bdp-12; 38 | double db2 = 0x1ac.dbp+12; 39 | printf("%f\n%f\n%f\n\n", db0, db1, db2); 40 | 41 | double dc0 = 0X1AC.P12; 42 | double dc1 = 0x1ac.p-12; 43 | double dc2 = 0x1ac.p+12; 44 | printf("%f\n%f\n%f\n\n", dc0, dc1, dc2); 45 | 46 | double dd0 = 0X1ACP12; 47 | double dd1 = 0x1acp-12; 48 | double dd2 = 0x1acp+12; 49 | printf("%f\n%f\n%f\n\n", dd0, dd1, dd2); 50 | printf("\n"); 51 | 52 | #ifdef __TINYC__ 53 | /* TCC extension 54 | binary floating constant */ 55 | long double la0 = 0B.110101100P12L; 56 | long double la1 = 0b.110101100p-12l; 57 | long double la2 = 0b.110101100p+12l; 58 | printf("%Lf\n%Lf\n%Lf\n\n", la0, la1, la2); 59 | 60 | long double lb0 = 0B110101100.10111101P12L; 61 | long double lb1 = 0b110101100.10111101p-12l; 62 | long double lb2 = 0b110101100.10111101p+12l; 63 | printf("%Lf\n%Lf\n%Lf\n\n", lb0, lb1, lb2); 64 | 65 | long double lc0 = 0B110101100.P12L; 66 | long double lc1 = 0b110101100.p-12l; 67 | long double lc2 = 0b110101100.p+12l; 68 | printf("%Lf\n%Lf\n%Lf\n\n", lc0, lc1, lc2); 69 | 70 | long double ld0 = 0B110101100P12L; 71 | long double ld1 = 0b110101100p-12l; 72 | long double ld2 = 0b110101100p+12l; 73 | printf("%Lf\n%Lf\n%Lf\n\n", ld0, ld1, ld2); 74 | #endif 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /win32/lib/wincrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | // _UNICODE for tchar.h, UNICODE for API 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #define __UNKNOWN_APP 0 10 | #define __CONSOLE_APP 1 11 | #define __GUI_APP 2 12 | void __set_app_type(int); 13 | void _controlfp(unsigned a, unsigned b); 14 | 15 | #ifdef _UNICODE 16 | #define __tgetmainargs __wgetmainargs 17 | #define _twinstart _wwinstart 18 | #define _runtwinmain _runwwinmain 19 | int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); 20 | #else 21 | #define __tgetmainargs __getmainargs 22 | #define _twinstart _winstart 23 | #define _runtwinmain _runwinmain 24 | #endif 25 | 26 | typedef struct { int newmode; } _startupinfo; 27 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); 28 | 29 | static int go_winmain(TCHAR *arg1) 30 | { 31 | STARTUPINFO si; 32 | _TCHAR *szCmd, *p; 33 | int fShow; 34 | 35 | GetStartupInfo(&si); 36 | if (si.dwFlags & STARTF_USESHOWWINDOW) 37 | fShow = si.wShowWindow; 38 | else 39 | fShow = SW_SHOWDEFAULT; 40 | 41 | szCmd = NULL, p = GetCommandLine(); 42 | if (arg1) 43 | szCmd = _tcsstr(p, arg1); 44 | if (NULL == szCmd) 45 | szCmd = _tcsdup(__T("")); 46 | else if (szCmd > p && szCmd[-1] == __T('"')) 47 | --szCmd; 48 | #if defined __i386__ || defined __x86_64__ 49 | _controlfp(0x10000, 0x30000); 50 | #endif 51 | return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); 52 | } 53 | 54 | static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) 55 | { 56 | return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); 57 | } 58 | 59 | int _twinstart(void) 60 | { 61 | _startupinfo start_info_con = {0}; 62 | SetUnhandledExceptionFilter(catch_sig); 63 | __set_app_type(__GUI_APP); 64 | __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con); 65 | exit(go_winmain(__argc > 1 ? __targv[1] : NULL)); 66 | } 67 | 68 | int _runtwinmain(int argc, /* as tcc passed in */ char **argv) 69 | { 70 | #ifdef UNICODE 71 | _startupinfo start_info = {0}; 72 | __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info); 73 | /* may be wrong when tcc has received wildcards (*.c) */ 74 | if (argc < __argc) 75 | __targv += __argc - argc, __argc = argc; 76 | #else 77 | __argc = argc, __targv = argv; 78 | #endif 79 | return go_winmain(__argc > 1 ? __targv[1] : NULL); 80 | } 81 | -------------------------------------------------------------------------------- /conftest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(_WIN32) 4 | #include 5 | #endif 6 | 7 | /* Define architecture */ 8 | #if defined(__i386__) || defined _M_IX86 9 | # define TRIPLET_ARCH "i386" 10 | #elif defined(__x86_64__) || defined _M_AMD64 11 | # define TRIPLET_ARCH "x86_64" 12 | #elif defined(__arm__) 13 | # define TRIPLET_ARCH "arm" 14 | #elif defined(__aarch64__) 15 | # define TRIPLET_ARCH "aarch64" 16 | #elif defined(__riscv) && defined(__LP64__) 17 | # define TRIPLET_ARCH "riscv64" 18 | #else 19 | # define TRIPLET_ARCH "unknown" 20 | #endif 21 | 22 | /* Define OS */ 23 | #if defined (__linux__) 24 | # define TRIPLET_OS "linux" 25 | #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) 26 | # define TRIPLET_OS "kfreebsd" 27 | #elif defined _WIN32 28 | # define TRIPLET_OS "win32" 29 | #elif !defined (__GNU__) 30 | # define TRIPLET_OS "unknown" 31 | #endif 32 | 33 | /* Define calling convention and ABI */ 34 | #if defined (__ARM_EABI__) 35 | # if defined (__ARM_PCS_VFP) 36 | # define TRIPLET_ABI "gnueabihf" 37 | # else 38 | # define TRIPLET_ABI "gnueabi" 39 | # endif 40 | #else 41 | # define TRIPLET_ABI "gnu" 42 | #endif 43 | 44 | #if defined _WIN32 45 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS 46 | #elif defined __GNU__ 47 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI 48 | #else 49 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI 50 | #endif 51 | 52 | #if defined(_WIN32) 53 | int _CRT_glob = 0; 54 | #endif 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | #if defined(_WIN32) 59 | _setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */ 60 | #endif 61 | switch(argc == 2 ? argv[1][0] : 0) { 62 | case 'b': 63 | { 64 | volatile unsigned foo = 0x01234567; 65 | puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); 66 | break; 67 | } 68 | #ifdef __GNUC__ 69 | case 'm': 70 | printf("%d\n", __GNUC_MINOR__); 71 | break; 72 | case 'v': 73 | printf("%d\n", __GNUC__); 74 | break; 75 | #elif defined __TINYC__ 76 | case 'v': 77 | puts("0"); 78 | break; 79 | case 'm': 80 | printf("%d\n", __TINYC__); 81 | break; 82 | #else 83 | case 'm': 84 | case 'v': 85 | puts("0"); 86 | break; 87 | #endif 88 | case 't': 89 | puts(TRIPLET); 90 | break; 91 | 92 | default: 93 | break; 94 | } 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /win32/include/locale.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCALE 7 | #define _INC_LOCALE 8 | 9 | #include <_mingw.h> 10 | 11 | #pragma pack(push,_CRT_PACKING) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifndef NULL 18 | #ifdef __cplusplus 19 | #define NULL 0 20 | #else 21 | #define NULL ((void *)0) 22 | #endif 23 | #endif 24 | 25 | #define LC_ALL 0 26 | #define LC_COLLATE 1 27 | #define LC_CTYPE 2 28 | #define LC_MONETARY 3 29 | #define LC_NUMERIC 4 30 | #define LC_TIME 5 31 | 32 | #define LC_MIN LC_ALL 33 | #define LC_MAX LC_TIME 34 | 35 | #ifndef _LCONV_DEFINED 36 | #define _LCONV_DEFINED 37 | struct lconv { 38 | char *decimal_point; 39 | char *thousands_sep; 40 | char *grouping; 41 | char *int_curr_symbol; 42 | char *currency_symbol; 43 | char *mon_decimal_point; 44 | char *mon_thousands_sep; 45 | char *mon_grouping; 46 | char *positive_sign; 47 | char *negative_sign; 48 | char int_frac_digits; 49 | char frac_digits; 50 | char p_cs_precedes; 51 | char p_sep_by_space; 52 | char n_cs_precedes; 53 | char n_sep_by_space; 54 | char p_sign_posn; 55 | char n_sign_posn; 56 | }; 57 | #endif 58 | 59 | #ifndef _CONFIG_LOCALE_SWT 60 | #define _CONFIG_LOCALE_SWT 61 | 62 | #define _ENABLE_PER_THREAD_LOCALE 0x1 63 | #define _DISABLE_PER_THREAD_LOCALE 0x2 64 | #define _ENABLE_PER_THREAD_LOCALE_GLOBAL 0x10 65 | #define _DISABLE_PER_THREAD_LOCALE_GLOBAL 0x20 66 | #define _ENABLE_PER_THREAD_LOCALE_NEW 0x100 67 | #define _DISABLE_PER_THREAD_LOCALE_NEW 0x200 68 | 69 | #endif 70 | 71 | int __cdecl _configthreadlocale(int _Flag); 72 | char *__cdecl setlocale(int _Category,const char *_Locale); 73 | _CRTIMP struct lconv *__cdecl localeconv(void); 74 | _locale_t __cdecl _get_current_locale(void); 75 | _locale_t __cdecl _create_locale(int _Category,const char *_Locale); 76 | void __cdecl _free_locale(_locale_t _Locale); 77 | _locale_t __cdecl __get_current_locale(void); 78 | _locale_t __cdecl __create_locale(int _Category,const char *_Locale); 79 | void __cdecl __free_locale(_locale_t _Locale); 80 | 81 | #ifndef _WLOCALE_DEFINED 82 | #define _WLOCALE_DEFINED 83 | _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale); 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #pragma pack(pop) 91 | #endif 92 | -------------------------------------------------------------------------------- /win32/include/sec_api/time_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _TIME_H__S 7 | #define _TIME_H__S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _ctime32_s(char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); 18 | _CRTIMP errno_t __cdecl _gmtime32_s(struct tm *_Tm,const __time32_t *_Time); 19 | _CRTIMP errno_t __cdecl _localtime32_s(struct tm *_Tm,const __time32_t *_Time); 20 | _CRTIMP errno_t __cdecl _strdate_s(char *_Buf,size_t _SizeInBytes); 21 | _CRTIMP errno_t __cdecl _strtime_s(char *_Buf ,size_t _SizeInBytes); 22 | #if _INTEGRAL_MAX_BITS >= 64 23 | _CRTIMP errno_t __cdecl _ctime64_s(char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); 24 | _CRTIMP errno_t __cdecl _gmtime64_s(struct tm *_Tm,const __time64_t *_Time); 25 | _CRTIMP errno_t __cdecl _localtime64_s(struct tm *_Tm,const __time64_t *_Time); 26 | #endif 27 | 28 | #ifndef _WTIME_S_DEFINED 29 | #define _WTIME_S_DEFINED 30 | _CRTIMP errno_t __cdecl _wasctime_s(wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); 31 | _CRTIMP errno_t __cdecl _wctime32_s(wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); 32 | _CRTIMP errno_t __cdecl _wstrdate_s(wchar_t *_Buf,size_t _SizeInWords); 33 | _CRTIMP errno_t __cdecl _wstrtime_s(wchar_t *_Buf,size_t _SizeInWords); 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | _CRTIMP errno_t __cdecl _wctime64_s(wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); 36 | #endif 37 | 38 | #if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) 39 | #define _INC_WTIME_S_INL 40 | #ifdef _USE_32BIT_TIME_T 41 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s(_Buffer,_SizeInWords,_Time); } 42 | #else 43 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s(_Buffer,_SizeInWords,_Time); } 44 | #endif 45 | #endif 46 | #endif 47 | 48 | #ifndef RC_INVOKED 49 | #ifdef _USE_32BIT_TIME_T 50 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); } 51 | #else 52 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime64_s(_Tm,_Time); } 53 | #endif 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /examples/ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N 20 5 | 6 | int nb_num; 7 | int tab[N]; 8 | int stack_ptr; 9 | int stack_op[N]; 10 | int stack_res[60]; 11 | int result; 12 | 13 | int find(int n, int i1, int a, int b, int op) 14 | { 15 | int i, j; 16 | int c; 17 | 18 | if (stack_ptr >= 0) { 19 | stack_res[3*stack_ptr] = a; 20 | stack_op[stack_ptr] = op; 21 | stack_res[3*stack_ptr+1] = b; 22 | stack_res[3*stack_ptr+2] = n; 23 | if (n == result) 24 | return 1; 25 | tab[i1] = n; 26 | } 27 | 28 | for(i=0;i 37 | /* some gcc headers #define __attribute__ to empty if it's not gcc */ 38 | #undef __attribute__ 39 | 40 | int main() 41 | { 42 | __label__ ts0, te0, ts1, te1; 43 | int tl, dl; 44 | 45 | static char ds0 = 0; 46 | static char de0 = 0; 47 | /* get reference size of empty jmp */ 48 | ts0:; 49 | if (!SKIP) {} 50 | te0:; 51 | dl = -(&de0 - &ds0); 52 | tl = -(&&te0 - &&ts0); 53 | 54 | /* test data and code suppression */ 55 | static char ds1 = 0; 56 | ts1:; 57 | if (!SKIP) { 58 | void *p = (void*)&main; 59 | char cc[] = "static string"; 60 | double d = 8.0; 61 | struct __attribute__((packed)) { 62 | unsigned x : 12; 63 | unsigned char y : 7; 64 | unsigned z : 28, a: 4, b: 5; 65 | } s = { 0x333,0x44,0x555555,6,7 }; 66 | 67 | printf("data:\n"); 68 | printf(" %d - %.1f - %.1f - %s - %s\n", 69 | sizeof 8.0, 8.0, d, __FUNCTION__, cc); 70 | printf(" %x %x %x %x %x\n", 71 | s.x, s.y, s.z, s.a, s.b); 72 | } 73 | te1:; 74 | static char de1 = 0; 75 | 76 | dl += &de1 - &ds1; 77 | tl += &&te1 - &&ts1; 78 | printf("size of data/text:\n %s/%s\n", 79 | dl ? "non-zero":"zero", tl ? "non-zero":"zero"); 80 | /*printf("# %d/%d\n", dl, tl);*/ 81 | } 82 | 83 | #elif defined test_static_data 84 | 85 | #include 86 | int main(int argc, char **argv) 87 | { 88 | goto there; 89 | if (0) { 90 | static int a = 1; 91 | printf("hello\n"); /* the "hello\n" string is still suppressed */ 92 | there: 93 | printf("a = %d\n", a); 94 | } 95 | return 0; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /win32/lib/crt1.c: -------------------------------------------------------------------------------- 1 | // ============================================= 2 | // crt1.c 3 | 4 | // _UNICODE for tchar.h, UNICODE for API 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #define _UNKNOWN_APP 0 12 | #define _CONSOLE_APP 1 13 | #define _GUI_APP 2 14 | 15 | #define _MCW_PC 0x00030000 // Precision Control 16 | #define _PC_24 0x00020000 // 24 bits 17 | #define _PC_53 0x00010000 // 53 bits 18 | #define _PC_64 0x00000000 // 64 bits 19 | 20 | #ifdef _UNICODE 21 | #define __tgetmainargs __wgetmainargs 22 | #define _tstart _wstart 23 | #define _tmain wmain 24 | #define _runtmain _runwmain 25 | #else 26 | #define __tgetmainargs __getmainargs 27 | #define _tstart _start 28 | #define _tmain main 29 | #define _runtmain _runmain 30 | #endif 31 | 32 | typedef struct { int newmode; } _startupinfo; 33 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); 34 | void __cdecl __set_app_type(int apptype); 35 | unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask); 36 | extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); 37 | 38 | /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ 39 | int _dowildcard; 40 | 41 | static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) 42 | { 43 | return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); 44 | } 45 | 46 | void _tstart(void) 47 | { 48 | _startupinfo start_info = {0}; 49 | SetUnhandledExceptionFilter(catch_sig); 50 | // Sets the current application type 51 | __set_app_type(_CONSOLE_APP); 52 | 53 | // Set default FP precision to 53 bits (8-byte double) 54 | // _MCW_PC (Precision control) is not supported on ARM 55 | #if defined __i386__ || defined __x86_64__ 56 | _controlfp(_PC_53, _MCW_PC); 57 | #endif 58 | 59 | __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info); 60 | exit(_tmain(__argc, __targv, _tenviron)); 61 | } 62 | 63 | int _runtmain(int argc, /* as tcc passed in */ char **argv) 64 | { 65 | #ifdef UNICODE 66 | _startupinfo start_info = {0}; 67 | 68 | __tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info); 69 | /* may be wrong when tcc has received wildcards (*.c) */ 70 | if (argc < __argc) { 71 | __targv += __argc - argc; 72 | __argc = argc; 73 | } 74 | #else 75 | __argc = argc; 76 | __targv = argv; 77 | #endif 78 | #if defined __i386__ || defined __x86_64__ 79 | _controlfp(_PC_53, _MCW_PC); 80 | #endif 81 | return _tmain(__argc, __targv, _tenviron); 82 | } 83 | 84 | // ============================================= 85 | -------------------------------------------------------------------------------- /tests/libtcc_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Test program for libtcc 3 | * 4 | * libtcc can be useful to use tcc as a "backend" for a code generator. 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | #include "libtcc.h" 11 | 12 | /* this function is called by the generated code */ 13 | int add(int a, int b) 14 | { 15 | return a + b; 16 | } 17 | 18 | /* this strinc is referenced by the generated code */ 19 | const char hello[] = "Hello World!"; 20 | 21 | char my_program[] = 22 | "#include \n" /* include the "Simple libc header for TCC" */ 23 | "extern int add(int a, int b);\n" 24 | "#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */ 25 | " __attribute__((dllimport))\n" 26 | "#endif\n" 27 | "extern const char hello[];\n" 28 | "int fib(int n)\n" 29 | "{\n" 30 | " if (n <= 2)\n" 31 | " return 1;\n" 32 | " else\n" 33 | " return fib(n-1) + fib(n-2);\n" 34 | "}\n" 35 | "\n" 36 | "int foo(int n)\n" 37 | "{\n" 38 | " printf(\"%s\\n\", hello);\n" 39 | " printf(\"fib(%d) = %d\\n\", n, fib(n));\n" 40 | " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" 41 | " return 0;\n" 42 | "}\n"; 43 | 44 | int main(int argc, char **argv) 45 | { 46 | TCCState *s; 47 | int i; 48 | int (*func)(int); 49 | 50 | s = tcc_new(); 51 | if (!s) { 52 | fprintf(stderr, "Could not create tcc state\n"); 53 | exit(1); 54 | } 55 | 56 | /* if tcclib.h and libtcc1.a are not installed, where can we find them */ 57 | for (i = 1; i < argc; ++i) { 58 | char *a = argv[i]; 59 | if (a[0] == '-') { 60 | if (a[1] == 'B') 61 | tcc_set_lib_path(s, a+2); 62 | else if (a[1] == 'I') 63 | tcc_add_include_path(s, a+2); 64 | else if (a[1] == 'L') 65 | tcc_add_library_path(s, a+2); 66 | } 67 | } 68 | 69 | /* MUST BE CALLED before any compilation */ 70 | tcc_set_output_type(s, TCC_OUTPUT_MEMORY); 71 | 72 | if (tcc_compile_string(s, my_program) == -1) 73 | return 1; 74 | 75 | /* as a test, we add symbols that the compiled program can use. 76 | You may also open a dll with tcc_add_dll() and use symbols from that */ 77 | tcc_add_symbol(s, "add", add); 78 | tcc_add_symbol(s, "hello", hello); 79 | 80 | /* relocate the code */ 81 | if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) 82 | return 1; 83 | 84 | /* get entry symbol */ 85 | func = tcc_get_symbol(s, "foo"); 86 | if (!func) 87 | return 1; 88 | 89 | /* run the code */ 90 | func(32); 91 | 92 | /* delete the state */ 93 | tcc_delete(s); 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /win32/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_TYPES 7 | #define _INC_TYPES 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #include <_mingw.h> 14 | 15 | #ifndef __TINYC__ /* gr */ 16 | #ifdef _USE_32BIT_TIME_T 17 | #ifdef _WIN64 18 | #undef _USE_32BIT_TIME_T 19 | #endif 20 | #else 21 | #if _INTEGRAL_MAX_BITS < 64 22 | #define _USE_32BIT_TIME_T 23 | #endif 24 | #endif 25 | #endif 26 | 27 | #ifndef _TIME32_T_DEFINED 28 | #define _TIME32_T_DEFINED 29 | typedef long __time32_t; 30 | #endif 31 | 32 | #ifndef _TIME64_T_DEFINED 33 | #define _TIME64_T_DEFINED 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | typedef __int64 __time64_t; 36 | #endif 37 | #endif 38 | 39 | #ifndef _TIME_T_DEFINED 40 | #define _TIME_T_DEFINED 41 | #ifdef _USE_32BIT_TIME_T 42 | typedef __time32_t time_t; 43 | #else 44 | typedef __time64_t time_t; 45 | #endif 46 | #endif 47 | 48 | #ifndef _INO_T_DEFINED 49 | #define _INO_T_DEFINED 50 | typedef unsigned short _ino_t; 51 | #ifndef NO_OLDNAMES 52 | typedef unsigned short ino_t; 53 | #endif 54 | #endif 55 | 56 | #ifndef _DEV_T_DEFINED 57 | #define _DEV_T_DEFINED 58 | typedef unsigned int _dev_t; 59 | #ifndef NO_OLDNAMES 60 | typedef unsigned int dev_t; 61 | #endif 62 | #endif 63 | 64 | #ifndef _PID_T_ 65 | #define _PID_T_ 66 | #ifndef _WIN64 67 | typedef int _pid_t; 68 | #else 69 | typedef __int64 _pid_t; 70 | #endif 71 | 72 | #ifndef NO_OLDNAMES 73 | typedef _pid_t pid_t; 74 | #endif 75 | #endif /* Not _PID_T_ */ 76 | 77 | #ifndef _MODE_T_ 78 | #define _MODE_T_ 79 | typedef unsigned short _mode_t; 80 | 81 | #ifndef NO_OLDNAMES 82 | typedef _mode_t mode_t; 83 | #endif 84 | #endif /* Not _MODE_T_ */ 85 | 86 | #ifndef _OFF_T_DEFINED 87 | #define _OFF_T_DEFINED 88 | #ifndef _OFF_T_ 89 | #define _OFF_T_ 90 | typedef long _off_t; 91 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 92 | typedef long off_t; 93 | #endif 94 | #endif 95 | #endif 96 | 97 | #ifndef _OFF64_T_DEFINED 98 | #define _OFF64_T_DEFINED 99 | typedef long long _off64_t; 100 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 101 | typedef long long off64_t; 102 | #endif 103 | #endif 104 | 105 | #ifndef _TIMESPEC_DEFINED 106 | #define _TIMESPEC_DEFINED 107 | struct timespec { 108 | time_t tv_sec; /* Seconds */ 109 | long tv_nsec; /* Nanoseconds */ 110 | }; 111 | 112 | struct itimerspec { 113 | struct timespec it_interval; /* Timer period */ 114 | struct timespec it_value; /* Timer expiration */ 115 | }; 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /win32/include/winapi/basetyps.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !defined(_BASETYPS_H_) 7 | #define _BASETYPS_H_ 8 | 9 | #ifdef __cplusplus 10 | #define EXTERN_C extern "C" 11 | #else 12 | #define EXTERN_C extern 13 | #endif 14 | 15 | #define STDMETHODCALLTYPE WINAPI 16 | #define STDMETHODVCALLTYPE __cdecl 17 | 18 | #define STDAPICALLTYPE WINAPI 19 | #define STDAPIVCALLTYPE __cdecl 20 | 21 | #define STDAPI EXTERN_C HRESULT WINAPI 22 | #define STDAPI_(type) EXTERN_C type WINAPI 23 | 24 | #define STDMETHODIMP HRESULT WINAPI 25 | #define STDMETHODIMP_(type) type WINAPI 26 | 27 | #define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE 28 | #define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE 29 | 30 | #define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE 31 | #define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE 32 | 33 | #if defined(__cplusplus) && !defined(CINTERFACE) 34 | 35 | #define __STRUCT__ struct 36 | #define STDMETHOD(method) virtual HRESULT WINAPI method 37 | #define STDMETHOD_(type,method) virtual type WINAPI method 38 | #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method 39 | #define STDMETHODV_(type,method) virtual type STDMETHODVCALLTYPE method 40 | #define PURE = 0 41 | #define THIS_ 42 | #define THIS void 43 | #define DECLARE_INTERFACE(iface) __STRUCT__ iface 44 | #define DECLARE_INTERFACE_(iface,baseiface) __STRUCT__ iface : public baseiface 45 | #else 46 | 47 | #ifndef __OBJC__ 48 | #define interface struct 49 | #endif 50 | 51 | #define STDMETHOD(method) HRESULT (WINAPI *method) 52 | #define STDMETHOD_(type,method) type (WINAPI *method) 53 | #define STDMETHODV(method) HRESULT (STDMETHODVCALLTYPE *method) 54 | #define STDMETHODV_(type,method) type (STDMETHODVCALLTYPE *method) 55 | 56 | #define PURE 57 | #define THIS_ INTERFACE *This, 58 | #define THIS INTERFACE *This 59 | #ifdef CONST_VTABLE 60 | #define DECLARE_INTERFACE(iface) typedef struct iface { \ 61 | const struct iface##Vtbl *lpVtbl; } iface; \ 62 | typedef const struct iface##Vtbl iface##Vtbl; \ 63 | const struct iface##Vtbl 64 | #else 65 | #define DECLARE_INTERFACE(iface) typedef struct iface { \ 66 | struct iface##Vtbl *lpVtbl; \ 67 | } iface; \ 68 | typedef struct iface##Vtbl iface##Vtbl; \ 69 | struct iface##Vtbl 70 | #endif 71 | #define DECLARE_INTERFACE_(iface,baseiface) DECLARE_INTERFACE(iface) 72 | #endif 73 | 74 | #include 75 | 76 | #ifndef _ERROR_STATUS_T_DEFINED 77 | #define _ERROR_STATUS_T_DEFINED 78 | typedef unsigned long error_status_t; 79 | #endif 80 | 81 | #ifndef _WCHAR_T_DEFINED 82 | typedef unsigned short wchar_t; 83 | #define _WCHAR_T_DEFINED 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /win32/include/winapi/windows.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _WINDOWS_ 7 | #define _WINDOWS_ 8 | 9 | #ifndef WIN32_LEAN_AND_MEAN 10 | #define WIN32_LEAN_AND_MEAN 1 11 | #endif 12 | 13 | #ifndef WINVER 14 | #define WINVER 0x0502 15 | #endif 16 | 17 | #include <_mingw.h> 18 | 19 | #ifndef _INC_WINDOWS 20 | #define _INC_WINDOWS 21 | 22 | #if defined(RC_INVOKED) && !defined(NOWINRES) 23 | 24 | #include 25 | #else 26 | 27 | #ifdef RC_INVOKED 28 | #define NOATOM 29 | #define NOGDI 30 | #define NOGDICAPMASKS 31 | #define NOMETAFILE 32 | #define NOMINMAX 33 | #define NOMSG 34 | #define NOOPENFILE 35 | #define NORASTEROPS 36 | #define NOSCROLL 37 | #define NOSOUND 38 | #define NOSYSMETRICS 39 | #define NOTEXTMETRIC 40 | #define NOWH 41 | #define NOCOMM 42 | #define NOKANJI 43 | #define NOCRYPT 44 | #define NOMCX 45 | #endif 46 | 47 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) 48 | #define I_X86_ 49 | #endif 50 | 51 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) 52 | #define _AMD64_ 53 | #endif 54 | 55 | #if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) 56 | #if !defined(_IA64_) 57 | #define _IA64_ 58 | #endif 59 | #endif 60 | 61 | #ifndef RC_INVOKED 62 | #include 63 | #include 64 | #endif 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | //gr #include 75 | 76 | #ifndef WIN32_LEAN_AND_MEAN 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #ifndef NOCRYPT 89 | #include 90 | #include 91 | #include 92 | #endif 93 | 94 | #ifndef NOUSER 95 | #ifndef NOGDI 96 | #include 97 | #ifdef INC_OLE1 98 | #include 99 | #else 100 | #include 101 | #endif 102 | #include 103 | #endif 104 | #endif 105 | #endif 106 | 107 | //gr #include 108 | 109 | #ifdef INC_OLE2 110 | #include 111 | #endif 112 | 113 | #ifndef NOSERVICE 114 | #include 115 | #endif 116 | 117 | #ifndef NOMCX 118 | #include 119 | #endif 120 | 121 | #ifndef NOIME 122 | #include 123 | #endif 124 | 125 | #endif 126 | #endif 127 | #endif 128 | -------------------------------------------------------------------------------- /RELICENSING: -------------------------------------------------------------------------------- 1 | 2 | Relicensing TinyCC 3 | ------------------ 4 | 5 | The authors listed below hereby confirm their agreement to relicense TinyCC 6 | including their past contributions under the following terms: 7 | 8 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | 27 | 28 | Author (name) I agree (YES/NO) Files/Features (optional) 29 | ------------------------------------------------------------------------------ 30 | Adam Sampson YES makefiles 31 | Daniel Glöckner NO arm-gen.c 32 | Daniel Glöckner YES not arm-gen.c 33 | Edmund Grimley Evans YES arm64 34 | Fabrice Bellard YES original author 35 | Frédéric Féret YES x86 64/16 bit asm 36 | grischka YES tccpe.c 37 | Henry Kroll YES 38 | Joe Soroka YES 39 | Kirill Smelkov YES 40 | mingodad YES 41 | Pip Cet YES 42 | Shinichiro Hamaji YES x86_64-gen.c 43 | Vincent Lefèvre YES 44 | Thomas Preud'homme YES arm-gen.c 45 | Timo VJ Lähde (Timppa) ? tiny_libmaker.c 46 | TK ? tcccoff.c c67-gen.c 47 | Urs Janssen YES 48 | waddlesplash YES 49 | Christian Jullien YES Windows Cygwin build and tests 50 | 51 | 52 | ------------------------------------------------------------------------------ 53 | 54 | Please add yourself to the list above (rsp. replace the question mark) 55 | and (after fetching the latest version) commit to the "mob" branch with 56 | commit message: 57 | 58 | Relicensing TinyCC 59 | 60 | Thanks. 61 | --------------------------------------------------------------------------------