├── .github └── workflows │ └── build.yml ├── .gitignore ├── COPYING ├── Changelog ├── CodingStyle ├── Makefile ├── README ├── RELICENSING ├── TODO ├── USES ├── VERSION ├── arm-asm.c ├── arm-gen.c ├── arm-link.c ├── arm-tok.h ├── arm64-asm.c ├── arm64-gen.c ├── arm64-link.c ├── c67-gen.c ├── c67-link.c ├── coff.h ├── configure ├── conftest.c ├── dwarf.h ├── elf.h ├── examples ├── ex1.c ├── ex2.c ├── ex3.c ├── ex4.c └── ex5.c ├── i386-asm.c ├── i386-asm.h ├── i386-gen.c ├── i386-link.c ├── i386-tok.h ├── il-gen.c ├── il-opcodes.h ├── include ├── float.h ├── stdalign.h ├── stdarg.h ├── stdatomic.h ├── stdbool.h ├── stddef.h ├── stdnoreturn.h ├── tccdefs.h ├── tgmath.h └── varargs.h ├── lib ├── Makefile ├── alloca-bt.S ├── alloca.S ├── armeabi.c ├── armflush.c ├── atomic.S ├── bcheck.c ├── bt-dll.c ├── bt-exe.c ├── bt-log.c ├── builtin.c ├── dsohandle.c ├── lib-arm64.c ├── libtcc1.c ├── stdatomic.c ├── tcov.c └── va_list.c ├── libtcc.c ├── libtcc.h ├── riscv64-asm.c ├── riscv64-gen.c ├── riscv64-link.c ├── riscv64-tok.h ├── stab.def ├── stab.h ├── tcc-doc.texi ├── tcc.c ├── tcc.h ├── tccasm.c ├── tcccoff.c ├── tccdbg.c ├── tccelf.c ├── tccgen.c ├── tcclib.h ├── tccmacho.c ├── tccpe.c ├── tccpp.c ├── tccrun.c ├── tcctok.h ├── tcctools.c ├── tests ├── 42test.h ├── Makefile ├── abitest.c ├── arm-asm-testsuite.sh ├── asm-c-connect-1.c ├── asm-c-connect-2.c ├── asmtest.S ├── boundtest.c ├── bug.c ├── gcctestsuite.sh ├── libtcc_test.c ├── libtcc_test_mt.c ├── pp │ ├── 01.c │ ├── 01.expect │ ├── 02.c │ ├── 02.expect │ ├── 03.c │ ├── 03.expect │ ├── 04.c │ ├── 04.expect │ ├── 05.c │ ├── 05.expect │ ├── 06.c │ ├── 06.expect │ ├── 07.c │ ├── 07.expect │ ├── 08.c │ ├── 08.expect │ ├── 09.c │ ├── 09.expect │ ├── 10.c │ ├── 10.expect │ ├── 11.c │ ├── 11.expect │ ├── 12.S │ ├── 12.expect │ ├── 13.S │ ├── 13.expect │ ├── 14.c │ ├── 14.expect │ ├── 15.c │ ├── 15.expect │ ├── 16.c │ ├── 16.expect │ ├── 17.c │ ├── 17.expect │ ├── 18.c │ ├── 18.expect │ ├── 19.c │ ├── 19.expect │ ├── 20.c │ ├── 20.expect │ ├── 21.c │ ├── 21.expect │ ├── 22.c │ ├── 22.expect │ ├── Makefile │ ├── pp-counter.c │ └── pp-counter.expect ├── tcctest.c ├── tcctest.h ├── testfp.c ├── tests2 │ ├── 00_assignment.c │ ├── 00_assignment.expect │ ├── 01_comment.c │ ├── 01_comment.expect │ ├── 02_printf.c │ ├── 02_printf.expect │ ├── 03_struct.c │ ├── 03_struct.expect │ ├── 04_for.c │ ├── 04_for.expect │ ├── 05_array.c │ ├── 05_array.expect │ ├── 06_case.c │ ├── 06_case.expect │ ├── 07_function.c │ ├── 07_function.expect │ ├── 08_while.c │ ├── 08_while.expect │ ├── 09_do_while.c │ ├── 09_do_while.expect │ ├── 100_c99array-decls.c │ ├── 100_c99array-decls.expect │ ├── 101_cleanup.c │ ├── 101_cleanup.expect │ ├── 102_alignas.c │ ├── 102_alignas.expect │ ├── 103_implicit_memmove.c │ ├── 103_implicit_memmove.expect │ ├── 104+_inline.c │ ├── 104_inline.c │ ├── 104_inline.expect │ ├── 105_local_extern.c │ ├── 105_local_extern.expect │ ├── 106_versym.c │ ├── 106_versym.expect │ ├── 107_stack_safe.c │ ├── 107_stack_safe.expect │ ├── 108_constructor.c │ ├── 108_constructor.expect │ ├── 109_float_struct_calling.c │ ├── 109_float_struct_calling.expect │ ├── 10_pointer.c │ ├── 10_pointer.expect │ ├── 110_average.c │ ├── 110_average.expect │ ├── 111_conversion.c │ ├── 111_conversion.expect │ ├── 112_backtrace.c │ ├── 112_backtrace.expect │ ├── 113_btdll.c │ ├── 113_btdll.expect │ ├── 114_bound_signal.c │ ├── 114_bound_signal.expect │ ├── 115_bound_setjmp.c │ ├── 115_bound_setjmp.expect │ ├── 116_bound_setjmp2.c │ ├── 116_bound_setjmp2.expect │ ├── 117_builtins.c │ ├── 117_builtins.expect │ ├── 118_switch.c │ ├── 118_switch.expect │ ├── 119_random_stuff.c │ ├── 119_random_stuff.expect │ ├── 11_precedence.c │ ├── 11_precedence.expect │ ├── 120+_alias.c │ ├── 120_alias.c │ ├── 120_alias.expect │ ├── 121_struct_return.c │ ├── 121_struct_return.expect │ ├── 122_vla_reuse.c │ ├── 122_vla_reuse.expect │ ├── 123_vla_bug.c │ ├── 123_vla_bug.expect │ ├── 124_atomic_counter.c │ ├── 124_atomic_counter.expect │ ├── 125_atomic_misc.c │ ├── 125_atomic_misc.expect │ ├── 126_bound_global.c │ ├── 126_bound_global.expect │ ├── 127_asm_goto.c │ ├── 127_asm_goto.expect │ ├── 128_run_atexit.c │ ├── 128_run_atexit.expect │ ├── 129_scopes.c │ ├── 129_scopes.expect │ ├── 12_hashdefine.c │ ├── 12_hashdefine.expect │ ├── 130_large_argument.c │ ├── 130_large_argument.expect │ ├── 131_return_struct_in_reg.c │ ├── 131_return_struct_in_reg.expect │ ├── 132_bound_test.c │ ├── 132_bound_test.expect │ ├── 13_integer_literals.c │ ├── 13_integer_literals.expect │ ├── 14_if.c │ ├── 14_if.expect │ ├── 15_recursion.c │ ├── 15_recursion.expect │ ├── 16_nesting.c │ ├── 16_nesting.expect │ ├── 17_enum.c │ ├── 17_enum.expect │ ├── 18_include.c │ ├── 18_include.expect │ ├── 18_include.h │ ├── 18_include2.h │ ├── 19_pointer_arithmetic.c │ ├── 19_pointer_arithmetic.expect │ ├── 20_pointer_comparison.c │ ├── 20_pointer_comparison.expect │ ├── 21_char_array.c │ ├── 21_char_array.expect │ ├── 22_floating_point.c │ ├── 22_floating_point.expect │ ├── 23_type_coercion.c │ ├── 23_type_coercion.expect │ ├── 24_math_library.c │ ├── 24_math_library.expect │ ├── 25_quicksort.c │ ├── 25_quicksort.expect │ ├── 26_character_constants.c │ ├── 26_character_constants.expect │ ├── 27_sizeof.c │ ├── 27_sizeof.expect │ ├── 28_strings.c │ ├── 28_strings.expect │ ├── 29_array_address.c │ ├── 29_array_address.expect │ ├── 30_hanoi.c │ ├── 30_hanoi.expect │ ├── 31_args.c │ ├── 31_args.expect │ ├── 32_led.c │ ├── 32_led.expect │ ├── 33_ternary_op.c │ ├── 33_ternary_op.expect │ ├── 34_array_assignment.c │ ├── 34_array_assignment.expect │ ├── 35_sizeof.c │ ├── 35_sizeof.expect │ ├── 36_array_initialisers.c │ ├── 36_array_initialisers.expect │ ├── 37_sprintf.c │ ├── 37_sprintf.expect │ ├── 38_multiple_array_index.c │ ├── 38_multiple_array_index.expect │ ├── 39_typedef.c │ ├── 39_typedef.expect │ ├── 40_stdio.c │ ├── 40_stdio.expect │ ├── 41_hashif.c │ ├── 41_hashif.expect │ ├── 42_function_pointer.c │ ├── 42_function_pointer.expect │ ├── 43_void_param.c │ ├── 43_void_param.expect │ ├── 44_scoped_declarations.c │ ├── 44_scoped_declarations.expect │ ├── 45_empty_for.c │ ├── 45_empty_for.expect │ ├── 46_grep.c │ ├── 46_grep.expect │ ├── 47_switch_return.c │ ├── 47_switch_return.expect │ ├── 48_nested_break.c │ ├── 48_nested_break.expect │ ├── 49_bracket_evaluation.c │ ├── 49_bracket_evaluation.expect │ ├── 50_logical_second_arg.c │ ├── 50_logical_second_arg.expect │ ├── 51_static.c │ ├── 51_static.expect │ ├── 52_unnamed_enum.c │ ├── 52_unnamed_enum.expect │ ├── 54_goto.c │ ├── 54_goto.expect │ ├── 55_lshift_type.c │ ├── 55_lshift_type.expect │ ├── 60_errors_and_warnings.c │ ├── 60_errors_and_warnings.expect │ ├── 61_integers.c │ ├── 61_integers.expect │ ├── 64_macro_nesting.c │ ├── 64_macro_nesting.expect │ ├── 67_macro_concat.c │ ├── 67_macro_concat.expect │ ├── 70_floating_point_literals.c │ ├── 70_floating_point_literals.expect │ ├── 71_macro_empty_arg.c │ ├── 71_macro_empty_arg.expect │ ├── 72_long_long_constant.c │ ├── 72_long_long_constant.expect │ ├── 73_arm64.c │ ├── 73_arm64.expect │ ├── 75_array_in_struct_init.c │ ├── 75_array_in_struct_init.expect │ ├── 76_dollars_in_identifiers.c │ ├── 76_dollars_in_identifiers.expect │ ├── 77_push_pop_macro.c │ ├── 77_push_pop_macro.expect │ ├── 78_vla_label.c │ ├── 78_vla_label.expect │ ├── 79_vla_continue.c │ ├── 79_vla_continue.expect │ ├── 80_flexarray.c │ ├── 80_flexarray.expect │ ├── 81_types.c │ ├── 81_types.expect │ ├── 82_attribs_position.c │ ├── 82_attribs_position.expect │ ├── 83_utf8_in_identifiers.c │ ├── 83_utf8_in_identifiers.expect │ ├── 84_hex-float.c │ ├── 84_hex-float.expect │ ├── 85_asm-outside-function.c │ ├── 85_asm-outside-function.expect │ ├── 86_memory-model.c │ ├── 86_memory-model.expect │ ├── 87_dead_code.c │ ├── 87_dead_code.expect │ ├── 88_codeopt.c │ ├── 88_codeopt.expect │ ├── 89_nocode_wanted.c │ ├── 89_nocode_wanted.expect │ ├── 90_struct-init.c │ ├── 90_struct-init.expect │ ├── 91_ptr_longlong_arith32.c │ ├── 91_ptr_longlong_arith32.expect │ ├── 92_enum_bitfield.c │ ├── 92_enum_bitfield.expect │ ├── 93_integer_promotion.c │ ├── 93_integer_promotion.expect │ ├── 94_generic.c │ ├── 94_generic.expect │ ├── 95_bitfields.c │ ├── 95_bitfields.expect │ ├── 95_bitfields_ms.c │ ├── 95_bitfields_ms.expect │ ├── 96_nodata_wanted.c │ ├── 96_nodata_wanted.expect │ ├── 97_utf8_string_literal.c │ ├── 97_utf8_string_literal.expect │ ├── 98_al_ax_extend.c │ ├── 98_al_ax_extend.expect │ ├── 99_fastcall.c │ ├── 99_fastcall.expect │ ├── LICENSE │ └── Makefile └── vla_test.c ├── texi2pod.pl ├── win32 ├── build-tcc.bat ├── examples │ ├── dll.c │ ├── fib.c │ ├── hello_dll.c │ └── hello_win.c ├── include │ ├── _mingw.h │ ├── assert.h │ ├── conio.h │ ├── ctype.h │ ├── dir.h │ ├── direct.h │ ├── dirent.h │ ├── dos.h │ ├── errno.h │ ├── excpt.h │ ├── fcntl.h │ ├── fenv.h │ ├── inttypes.h │ ├── io.h │ ├── iso646.h │ ├── limits.h │ ├── locale.h │ ├── malloc.h │ ├── math.h │ ├── mem.h │ ├── memory.h │ ├── process.h │ ├── sec_api │ │ ├── conio_s.h │ │ ├── crtdbg_s.h │ │ ├── io_s.h │ │ ├── mbstring_s.h │ │ ├── search_s.h │ │ ├── stdio_s.h │ │ ├── stdlib_s.h │ │ ├── stralign_s.h │ │ ├── string_s.h │ │ ├── sys │ │ │ └── timeb_s.h │ │ ├── tchar_s.h │ │ ├── time_s.h │ │ └── wchar_s.h │ ├── setjmp.h │ ├── share.h │ ├── signal.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── sys │ │ ├── fcntl.h │ │ ├── file.h │ │ ├── locking.h │ │ ├── stat.h │ │ ├── time.h │ │ ├── timeb.h │ │ ├── types.h │ │ ├── unistd.h │ │ └── utime.h │ ├── tcc │ │ └── tcc_libm.h │ ├── tchar.h │ ├── time.h │ ├── uchar.h │ ├── vadefs.h │ ├── values.h │ ├── wchar.h │ ├── wctype.h │ └── winapi │ │ ├── basetsd.h │ │ ├── basetyps.h │ │ ├── guiddef.h │ │ ├── poppack.h │ │ ├── pshpack1.h │ │ ├── pshpack2.h │ │ ├── pshpack4.h │ │ ├── pshpack8.h │ │ ├── qos.h │ │ ├── winbase.h │ │ ├── wincon.h │ │ ├── windef.h │ │ ├── windows.h │ │ ├── winerror.h │ │ ├── wingdi.h │ │ ├── winnls.h │ │ ├── winnt.h │ │ ├── winreg.h │ │ ├── winsock2.h │ │ ├── winuser.h │ │ ├── winver.h │ │ ├── ws2ipdef.h │ │ └── ws2tcpip.h ├── lib │ ├── chkstk.S │ ├── crt1.c │ ├── crt1w.c │ ├── crtinit.c │ ├── dllcrt1.c │ ├── dllmain.c │ ├── gdi32.def │ ├── kernel32.def │ ├── msvcrt.def │ ├── user32.def │ ├── wincrt1.c │ ├── wincrt1w.c │ └── ws2_32.def └── tcc-win32.txt ├── x86_64-asm.h ├── x86_64-gen.c └── x86_64-link.c /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build and run tests 2 | 3 | on: 4 | push: 5 | branches: [ mob ] 6 | 7 | jobs: 8 | test-x86_64-linux: 9 | runs-on: ubuntu-20.04 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: make & test tcc 13 | run: ./configure && make && make test -k 14 | 15 | test-x86_64-osx: 16 | runs-on: macos-11 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: make & test tcc 20 | run: ./configure && make && make test -k 21 | 22 | test-x86_64-win32: 23 | runs-on: windows-2019 24 | steps: 25 | - uses: actions/checkout@v3 26 | - name: make & test tcc 27 | shell: cmd 28 | run: | 29 | set MSYS2_PATH_TYPE=inherit 30 | set MSYSTEM=MINGW64 31 | set CHERE_INVOKING=yes 32 | C:\msys64\usr\bin\bash -l -c "./configure && make && make test -k" 33 | -------------------------------------------------------------------------------- /.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_c 20 | tcc_p 21 | *-tcc 22 | libtcc*.def 23 | 24 | config*.h 25 | *_.h 26 | config*.mak 27 | config.texi 28 | conftest* 29 | c2str 30 | tags 31 | TAGS 32 | tcc.1 33 | *.pod 34 | *.tcov 35 | tcc-doc.html 36 | tcc-doc.info 37 | 38 | win32/doc 39 | win32/examples/libtcc_test.c 40 | win32/libtcc 41 | win32/lib/32 42 | win32/lib/64 43 | win32/include/float.h 44 | win32/include/stdalign.h 45 | win32/include/stdarg.h 46 | win32/include/stdbool.h 47 | win32/include/stddef.h 48 | win32/include/stdnoreturn.h 49 | win32/include/varargs.h 50 | win32/include/tcclib.h 51 | 52 | tests/tcctest[1234] 53 | tests/tcctest.gcc 54 | tests/*.out* 55 | tests/*.ref 56 | tests/*.txt 57 | tests/*.gcc 58 | tests/*-cc* 59 | tests/*-tcc* 60 | tests/libtcc_test 61 | tests/libtcc_test_mt 62 | tests/asm-c-connect 63 | tests/asm-c-connect-sep 64 | tests/vla_test 65 | tests/hello 66 | tests/tests2/fred.txt 67 | libtcc.dylib 68 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.9.28rc -------------------------------------------------------------------------------- /arm64-asm.c: -------------------------------------------------------------------------------- 1 | /*************************************************************/ 2 | /* 3 | * ARM64 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 | #define USING_GLOBALS 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /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 | #define DECIMAL_DIG 21 42 | 43 | #elif defined __aarch64__ || defined __riscv 44 | /* 45 | * Use values from: 46 | * gcc -dM -E -xc /dev/null | grep LDBL | sed -e "s/__//g" 47 | */ 48 | #define LDBL_MANT_DIG 113 49 | #define LDBL_DIG 33 50 | #define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L 51 | #define LDBL_MIN_EXP (-16381) 52 | #define LDBL_MIN 3.36210314311209350626267781732175260e-4932L 53 | #define LDBL_MIN_10_EXP (-4931) 54 | #define LDBL_MAX_EXP 16384 55 | #define LDBL_MAX 1.18973149535723176508575932662800702e+4932L 56 | #define LDBL_MAX_EXP 16384 57 | #define DECIMAL_DIG 36 58 | 59 | #else 60 | 61 | /* same as IEEE double */ 62 | #define LDBL_MANT_DIG 53 63 | #define LDBL_DIG 15 64 | #define LDBL_EPSILON 2.2204460492503131e-16L 65 | #define LDBL_MIN_EXP (-1021) 66 | #define LDBL_MIN 2.2250738585072014e-308L 67 | #define LDBL_MIN_10_EXP (-307) 68 | #define LDBL_MAX_EXP 1024 69 | #define LDBL_MAX 1.7976931348623157e+308L 70 | #define LDBL_MAX_10_EXP 308 71 | #define DECIMAL_DIG 17 72 | 73 | #endif 74 | 75 | #endif /* _FLOAT_H_ */ 76 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | typedef __builtin_va_list va_list; 5 | #define va_start __builtin_va_start 6 | #define va_arg __builtin_va_arg 7 | #define va_copy __builtin_va_copy 8 | #define va_end __builtin_va_end 9 | 10 | /* fix a buggy dependency on GCC in libio.h */ 11 | typedef va_list __gnuc_va_list; 12 | #define _VA_LIST_DEFINED 13 | 14 | #endif /* _STDARG_H */ 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 | -------------------------------------------------------------------------------- /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 NULL 16 | #define NULL ((void*)0) 17 | #endif 18 | 19 | #undef offsetof 20 | #define offsetof(type, field) ((size_t)&((type *)0)->field) 21 | 22 | #if defined __i386__ || defined __x86_64__ 23 | void *alloca(size_t size); 24 | #endif 25 | 26 | #endif 27 | 28 | /* Older glibc require a wint_t from (when requested 29 | by __need_wint_t, as otherwise stddef.h isn't allowed to 30 | define this type). Note that this must be outside the normal 31 | _STDDEF_H guard, so that it works even when we've included the file 32 | already (without requiring wint_t). Some other libs define _WINT_T 33 | if they've already provided that type, so we can use that as guard. 34 | TCC defines __WINT_TYPE__ for us. */ 35 | #if defined (__need_wint_t) 36 | #ifndef _WINT_T 37 | #define _WINT_T 38 | typedef __WINT_TYPE__ wint_t; 39 | #endif 40 | #undef __need_wint_t 41 | #endif 42 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/alloca-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca-bt.S */ 3 | 4 | #ifdef __leading_underscore 5 | # define _(s) _##s 6 | #else 7 | # define _(s) s 8 | #endif 9 | 10 | /* ---------------------------------------------- */ 11 | #if defined __i386__ 12 | 13 | .globl _(__bound_alloca) 14 | _(__bound_alloca): 15 | pop %edx 16 | pop %eax 17 | mov %eax, %ecx 18 | add $3+1,%eax 19 | and $-4,%eax 20 | jz p6 21 | 22 | #ifdef _WIN32 23 | p4: 24 | cmp $4096,%eax 25 | jbe p5 26 | test %eax,-4096(%esp) 27 | sub $4096,%esp 28 | sub $4096,%eax 29 | jmp p4 30 | 31 | p5: 32 | #endif 33 | 34 | sub %eax,%esp 35 | mov %esp,%eax 36 | 37 | push %edx 38 | push %eax 39 | push %ecx 40 | push %eax 41 | call _(__bound_new_region) 42 | add $8, %esp 43 | pop %eax 44 | pop %edx 45 | 46 | p6: 47 | push %edx 48 | push %edx 49 | ret 50 | 51 | /* ---------------------------------------------- */ 52 | #elif defined __x86_64__ 53 | 54 | .globl _(__bound_alloca) 55 | _(__bound_alloca): 56 | #ifdef _WIN32 57 | inc %rcx # add one extra to separate regions 58 | jmp _(alloca) 59 | .globl _(__bound_alloca_nr) 60 | _(__bound_alloca_nr): 61 | dec %rcx 62 | push %rax 63 | mov %rcx,%rdx 64 | mov %rax,%rcx 65 | sub $32,%rsp 66 | call _(__bound_new_region) 67 | add $32,%rsp 68 | pop %rax 69 | ret 70 | #else 71 | pop %rdx 72 | mov %rdi,%rax 73 | mov %rax,%rsi # size, a second parm to the __bound_new_region 74 | 75 | add $15 + 1,%rax # add one extra to separate regions 76 | and $-16,%rax 77 | jz p3 78 | 79 | 80 | sub %rax,%rsp 81 | mov %rsp,%rdi # pointer, a first parm to the __bound_new_region 82 | mov %rsp,%rax 83 | 84 | push %rdx 85 | push %rax 86 | call _(__bound_new_region) 87 | pop %rax 88 | pop %rdx 89 | 90 | p3: 91 | push %rdx 92 | ret 93 | #endif 94 | 95 | /* ---------------------------------------------- */ 96 | #endif 97 | -------------------------------------------------------------------------------- /lib/alloca.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca.S */ 3 | 4 | #ifdef __leading_underscore 5 | # define _(s) _##s 6 | #else 7 | # define _(s) s 8 | #endif 9 | 10 | /* ---------------------------------------------- */ 11 | #if defined __i386__ 12 | 13 | .globl _(alloca), _(__alloca) 14 | _(alloca): 15 | _(__alloca): 16 | push %ebp 17 | mov %esp,%ebp 18 | mov 8(%ebp),%eax 19 | add $3,%eax 20 | and $-4,%eax 21 | #ifdef _WIN32 22 | jmp .+16 #p2 23 | p1: 24 | sub $4096,%esp 25 | sub $4096,%eax 26 | test %eax,(%esp) 27 | p2: 28 | cmp $4096,%eax 29 | jae p1 30 | #endif 31 | sub %eax,%esp 32 | mov 4(%ebp),%eax 33 | mov 0(%ebp),%ebp 34 | add $8,%esp 35 | push %eax 36 | lea 8(%esp),%eax 37 | ret 38 | 39 | /* ---------------------------------------------- */ 40 | #elif defined __x86_64__ 41 | 42 | .globl _(alloca) 43 | _(alloca): 44 | pop %rdx 45 | #ifdef _WIN32 46 | mov %rcx,%rax 47 | #else 48 | mov %rdi,%rax 49 | #endif 50 | add $15,%rax 51 | and $-16,%rax 52 | jz p3 53 | 54 | #ifdef _WIN32 55 | p1: 56 | cmp $4096,%rax 57 | jbe p2 58 | test %rax,-4096(%rsp) 59 | sub $4096,%rsp 60 | sub $4096,%rax 61 | jmp p1 62 | p2: 63 | #endif 64 | sub %rax,%rsp 65 | mov %rsp,%rax 66 | p3: 67 | push %rdx 68 | ret 69 | 70 | /* ---------------------------------------------- */ 71 | #elif defined __arm__ 72 | 73 | .text 74 | .align 2 75 | .global alloca 76 | .type alloca, %function 77 | alloca: 78 | rsb sp, r0, sp 79 | bic sp, sp, #7 80 | mov r0, sp 81 | mov pc, lr 82 | .size alloca, .-alloca 83 | 84 | /* ---------------------------------------------- */ 85 | #endif 86 | -------------------------------------------------------------------------------- /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 _tccsyscall(unsigned syscall_nr, ...); 11 | 12 | /* arm-tcc supports only fake asm currently */ 13 | __asm__( 14 | ".global _tccsyscall\n" 15 | "_tccsyscall:\n" 16 | "push {r7, lr}\n\t" 17 | "mov r7, r0\n\t" 18 | "mov r0, r1\n\t" 19 | "mov r1, r2\n\t" 20 | "mov r2, r3\n\t" 21 | "svc #0\n\t" 22 | "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 | #define syscall _tccsyscall 35 | 36 | #else 37 | 38 | #define _GNU_SOURCE 39 | #include 40 | #include 41 | #include 42 | 43 | #endif 44 | 45 | /* Flushing for tccrun */ 46 | void __clear_cache(void *beginning, void *end) 47 | { 48 | /* __ARM_NR_cacheflush is kernel private and should not be used in user space. 49 | * However, there is no ARM asm parser in tcc so we use it for now */ 50 | syscall(__ARM_NR_cacheflush, beginning, end, 0); 51 | } 52 | -------------------------------------------------------------------------------- /lib/bt-dll.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------- */ 2 | /* stubs for calling bcheck functions from a dll. */ 3 | 4 | #include 5 | #include 6 | 7 | #define REDIR_ALL \ 8 | REDIR(__bt_init) \ 9 | REDIR(__bt_exit) \ 10 | REDIR(tcc_backtrace) \ 11 | \ 12 | REDIR(__bound_ptr_add) \ 13 | REDIR(__bound_ptr_indir1) \ 14 | REDIR(__bound_ptr_indir2) \ 15 | REDIR(__bound_ptr_indir4) \ 16 | REDIR(__bound_ptr_indir8) \ 17 | REDIR(__bound_ptr_indir12) \ 18 | REDIR(__bound_ptr_indir16) \ 19 | REDIR(__bound_local_new) \ 20 | REDIR(__bound_local_delete) \ 21 | REDIR(__bound_new_region) \ 22 | \ 23 | REDIR(__bound_free) \ 24 | REDIR(__bound_malloc) \ 25 | REDIR(__bound_realloc) \ 26 | REDIR(__bound_memcpy) \ 27 | REDIR(__bound_memcmp) \ 28 | REDIR(__bound_memmove) \ 29 | REDIR(__bound_memset) \ 30 | REDIR(__bound_strlen) \ 31 | REDIR(__bound_strcpy) \ 32 | REDIR(__bound_strncpy) \ 33 | REDIR(__bound_strcmp) \ 34 | REDIR(__bound_strncmp) \ 35 | REDIR(__bound_strcat) \ 36 | REDIR(__bound_strchr) \ 37 | REDIR(__bound_strdup) 38 | 39 | #ifdef __leading_underscore 40 | #define _(s) "_"#s 41 | #else 42 | #define _(s) #s 43 | #endif 44 | 45 | #define REDIR(s) void *s; 46 | static struct { REDIR_ALL } all_ptrs; 47 | #undef REDIR 48 | #define REDIR(s) #s"\0" 49 | static const char all_names[] = REDIR_ALL; 50 | #undef REDIR 51 | #define REDIR(s) __asm__(".global " _(s) ";" _(s) ": jmp *%0" : : "m" (all_ptrs.s) ); 52 | static void all_jmps() { REDIR_ALL } 53 | #undef REDIR 54 | 55 | void __bt_init_dll(int bcheck) 56 | { 57 | const char *s = all_names; 58 | void **p = (void**)&all_ptrs; 59 | do { 60 | *p = (void*)GetProcAddress(GetModuleHandle(NULL), (char*)s); 61 | if (NULL == *p) { 62 | char buf[100]; 63 | sprintf(buf, 64 | "Error: function '%s()' not found in executable. " 65 | "(Need -bt or -b for linking the exe.)", s); 66 | if (GetStdHandle(STD_ERROR_HANDLE)) 67 | fprintf(stderr, "TCC/BCHECK: %s\n", buf), fflush(stderr); 68 | else 69 | MessageBox(NULL, buf, "TCC/BCHECK", MB_ICONERROR); 70 | ExitProcess(1); 71 | } 72 | s = strchr(s,'\0') + 1, ++p; 73 | } while (*s && (bcheck || p < &all_ptrs.__bound_ptr_add)); 74 | } 75 | -------------------------------------------------------------------------------- /lib/bt-exe.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------- */ 2 | /* for linking rt_printline and the signal/exception handler 3 | from tccrun.c into executables. */ 4 | 5 | #define CONFIG_TCC_BACKTRACE_ONLY 6 | #define ONE_SOURCE 1 7 | #define pstrcpy tcc_pstrcpy 8 | #include "../tccrun.c" 9 | 10 | int (*__rt_error)(void*, void*, const char *, va_list); 11 | __attribute__((weak)) void __bound_checking_lock(void); 12 | __attribute__((weak)) void __bound_checking_unlock(void); 13 | 14 | #ifndef _WIN32 15 | # define __declspec(n) 16 | #endif 17 | 18 | __declspec(dllexport) 19 | void __bt_init(rt_context *p, int num_callers) 20 | { 21 | __attribute__((weak)) int main(); 22 | __attribute__((weak)) void __bound_init(void*, int); 23 | struct rt_context *rc = &g_rtctxt; 24 | //fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr); 25 | /* call __bound_init here due to redirection of sigaction */ 26 | /* needed to add global symbols */ 27 | if (p->bounds_start) { 28 | __bound_init(p->bounds_start, -1); 29 | __bound_checking_lock(); 30 | } 31 | if (num_callers) { 32 | memcpy(rc, p, offsetof(rt_context, next)); 33 | rc->num_callers = num_callers - 1; 34 | rc->top_func = main; 35 | __rt_error = _rt_error; 36 | set_exception_handler(); 37 | } else { 38 | p->next = rc->next, rc->next = p; 39 | } 40 | if (p->bounds_start) 41 | __bound_checking_unlock(); 42 | } 43 | 44 | __declspec(dllexport) 45 | void __bt_exit(rt_context *p) 46 | { 47 | __attribute__((weak)) void __bound_exit_dll(void*); 48 | struct rt_context *rc = &g_rtctxt; 49 | 50 | if (p->bounds_start) { 51 | __bound_exit_dll(p->bounds_start); 52 | __bound_checking_lock(); 53 | } 54 | while (rc) { 55 | if (rc->next == p) { 56 | rc->next = rc->next->next; 57 | break; 58 | } 59 | rc = rc->next; 60 | } 61 | if (p->bounds_start) 62 | __bound_checking_unlock(); 63 | } 64 | 65 | /* copy a string and truncate it. */ 66 | ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) 67 | { 68 | int l = strlen(s); 69 | if (l >= buf_size) 70 | l = buf_size - 1; 71 | memcpy(buf, s, l); 72 | buf[l] = 0; 73 | return buf; 74 | } 75 | -------------------------------------------------------------------------------- /lib/bt-log.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------- */ 2 | /* function to get a stack backtrace on demand with a message */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int (*__rt_error)(void*, void*, const char *, va_list); 9 | 10 | #ifdef _WIN32 11 | # define DLL_EXPORT __declspec(dllexport) 12 | #else 13 | # define DLL_EXPORT 14 | #endif 15 | 16 | /* Needed when using ...libtcc1-usegcc=yes in lib/Makefile */ 17 | #if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__) 18 | #pragma GCC diagnostic push 19 | #pragma GCC diagnostic ignored "-Wframe-address" 20 | #endif 21 | 22 | DLL_EXPORT int tcc_backtrace(const char *fmt, ...) 23 | { 24 | va_list ap; 25 | int ret; 26 | 27 | if (__rt_error) { 28 | void *fp = __builtin_frame_address(1); 29 | void *ip = __builtin_return_address(0); 30 | va_start(ap, fmt); 31 | ret = __rt_error(fp, ip, fmt, ap); 32 | va_end(ap); 33 | } else { 34 | const char *p, *nl = "\n"; 35 | if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0]))) 36 | fmt = p + 1; 37 | if (fmt[0] == '\001') 38 | ++fmt, nl = ""; 39 | va_start(ap, fmt); 40 | ret = vfprintf(stderr, fmt, ap); 41 | va_end(ap); 42 | fprintf(stderr, nl), fflush(stderr); 43 | } 44 | return ret; 45 | } 46 | 47 | #if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__) 48 | #pragma GCC diagnostic pop 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/dsohandle.c: -------------------------------------------------------------------------------- 1 | void * __dso_handle __attribute((visibility("hidden"))) = &__dso_handle; 2 | -------------------------------------------------------------------------------- /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 abort(void); 7 | 8 | /* This should be in sync with our include/stdarg.h */ 9 | enum __va_arg_type { 10 | __va_gen_reg, __va_float_reg, __va_stack 11 | }; 12 | 13 | /* GCC compatible definition of va_list. */ 14 | /*predefined by TCC (tcc_predefs.h): 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 | } __builtin_va_list[1]; 24 | */ 25 | 26 | extern void *memcpy(void *dest, const void *src, unsigned long n); 27 | 28 | void *__va_arg(__builtin_va_list ap, 29 | int arg_type, 30 | int size, int align) 31 | { 32 | size = (size + 7) & ~7; 33 | align = (align + 7) & ~7; 34 | switch ((enum __va_arg_type)arg_type) { 35 | case __va_gen_reg: 36 | if (ap->gp_offset + size <= 48) { 37 | ap->gp_offset += size; 38 | return ap->reg_save_area + ap->gp_offset - size; 39 | } 40 | goto use_overflow_area; 41 | 42 | case __va_float_reg: 43 | if (ap->fp_offset < 128 + 48) { 44 | ap->fp_offset += 16; 45 | if (size == 8) 46 | return ap->reg_save_area + ap->fp_offset - 16; 47 | if (ap->fp_offset < 128 + 48) { 48 | memcpy(ap->reg_save_area + ap->fp_offset - 8, 49 | ap->reg_save_area + ap->fp_offset, 8); 50 | ap->fp_offset += 16; 51 | return ap->reg_save_area + ap->fp_offset - 32; 52 | } 53 | } 54 | goto use_overflow_area; 55 | 56 | case __va_stack: 57 | use_overflow_area: 58 | ap->overflow_arg_area += size; 59 | ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); 60 | return ap->overflow_arg_area - size; 61 | 62 | default: /* should never happen */ 63 | abort(); 64 | return 0; 65 | } 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/asm-c-connect-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if (defined _WIN32 || defined __APPLE__) && (!defined __TINYC__ || defined __leading_underscore) 4 | # define _ "_" 5 | #else 6 | # define _ 7 | #endif 8 | 9 | #ifdef __clang__ 10 | /* clang needs some help tp not throw functions away even at -O0 */ 11 | #define __USED __attribute__((__used__)) 12 | #else 13 | #define __USED 14 | #endif 15 | 16 | static int __USED x1_c (void) 17 | { 18 | printf(" x1"); 19 | return 1; 20 | } 21 | 22 | #if __i386__ 23 | asm(".text;"_"x1: call "_"x1_c; ret"); 24 | #else 25 | /* Keep stack aligned */ 26 | asm(".text;"_"x1: sub $8,%rsp; call "_"x1_c; add $8,%rsp; ret"); 27 | #endif 28 | 29 | void callx4(void); 30 | void callx5_again(void); 31 | 32 | void x6() 33 | { 34 | printf(" x6-1"); 35 | } 36 | 37 | int main(int argc, char *argv[]) 38 | { 39 | printf("*"); 40 | asm("call "_"x1"); 41 | asm("call "_"x2"); 42 | asm("call "_"x3"); 43 | callx4(); 44 | asm("call "_"x5"); 45 | callx5_again(); 46 | x6(); 47 | printf(" *\n"); 48 | return 0; 49 | } 50 | 51 | static 52 | int __USED x2(void) 53 | { 54 | printf(" x2"); 55 | return 2; 56 | } 57 | 58 | extern int x3(void); 59 | 60 | void x4(void) 61 | { 62 | printf(" x4"); 63 | } 64 | 65 | void x5(void); 66 | void x5(void) 67 | { 68 | printf(" x5"); 69 | } 70 | -------------------------------------------------------------------------------- /tests/asm-c-connect-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if (defined _WIN32 || defined __APPLE__) && (!defined __TINYC__ || defined __leading_underscore) 4 | # define _ "_" 5 | #else 6 | # define _ 7 | #endif 8 | 9 | #ifdef __clang__ 10 | /* clang needs some help tp not throw functions away even at -O0 */ 11 | #define __USED __attribute__((__used__)) 12 | #else 13 | #define __USED 14 | #endif 15 | 16 | int x3(void) 17 | { 18 | printf(" x3"); 19 | return 3; 20 | } 21 | 22 | /* That callx4 is defined globally (as if ".globl callx4") 23 | is a TCC extension. GCC doesn't behave like this. */ 24 | void callx4(void); 25 | #if __i386__ 26 | __asm__(_"callx4: call "_"x4; ret;" 27 | #else 28 | /* Keep stack aligned */ 29 | __asm__(_"callx4: sub $8,%rsp; call "_"x4; add $8,%rsp; ret;" 30 | #endif 31 | #ifndef __TINYC__ 32 | " .global "_"callx4" 33 | #endif 34 | ); 35 | 36 | extern void x5(void); 37 | 38 | void callx5_again(void); 39 | void callx5_again(void) 40 | { 41 | x5(); 42 | asm("call "_"x6"); 43 | } 44 | 45 | static void __USED x6() 46 | { 47 | printf(" x6-2"); 48 | } 49 | -------------------------------------------------------------------------------- /tests/bug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int compile_errors(void) 5 | { 6 | #if TEST == 1 7 | { 8 | /* Not constant */ 9 | static int i = (&"Foobar"[1] - &"Foobar"[0]); 10 | } 11 | #endif 12 | #if TEST == 2 13 | { 14 | /* Not constant */ 15 | struct{int c;}v; 16 | static long i=((char*)&(v.c)-(char*)&v); 17 | } 18 | #endif 19 | #if TEST == 3 20 | { 21 | /* Not constant */ 22 | static const short ar[] = { &&l1 - &&l1, &&l2 - &&l1 }; 23 | void *p = &&l1 + ar[0]; 24 | goto *p; 25 | l1: return 1; 26 | l2: return 2; 27 | } 28 | #endif 29 | return 0; 30 | } 31 | 32 | int 33 | main(void) 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /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/01.expect: -------------------------------------------------------------------------------- 1 | char p[] = "x ## y"; 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/pp/04.expect: -------------------------------------------------------------------------------- 1 | (1) 2 | -------------------------------------------------------------------------------- /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/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/06.c: -------------------------------------------------------------------------------- 1 | #define X(a,b, \ 2 | c,d) \ 3 | foo 4 | 5 | X(1,2,3,4) 6 | -------------------------------------------------------------------------------- /tests/pp/06.expect: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/pp/07.c: -------------------------------------------------------------------------------- 1 | #define a() YES 2 | #define b() a 3 | b() 4 | b()() 5 | -------------------------------------------------------------------------------- /tests/pp/07.expect: -------------------------------------------------------------------------------- 1 | a 2 | YES 3 | -------------------------------------------------------------------------------- /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/pp/08.expect: -------------------------------------------------------------------------------- 1 | (hej.s_s.s_pos) 2 | -------------------------------------------------------------------------------- /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/pp/09.expect: -------------------------------------------------------------------------------- 1 | aaaaoooo 2 | -------------------------------------------------------------------------------- /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/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/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 | 33 | #define DDD(A, B) D_ ## B ## _D_ ## A 34 | #define CCC(X, ...) DDD(X, ##__VA_ARGS__) 35 | /* must be D_B_D_A (not D_B _D_A) */ 36 | CCC(A,B) 37 | -------------------------------------------------------------------------------- /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 | D_B_D_A 17 | -------------------------------------------------------------------------------- /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/pp/12.expect: -------------------------------------------------------------------------------- 1 | 9999: 1: movw (%esi), %bx; .section __ex_table, "a"; .long 9999b, 6001f ; 2 | 6001: 3 | -------------------------------------------------------------------------------- /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/pp/13.expect: -------------------------------------------------------------------------------- 1 | .text 2 | endtext: 3 | -------------------------------------------------------------------------------- /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/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/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/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/16.c: -------------------------------------------------------------------------------- 1 | /* The following should warn */ 2 | #define A ... 3 | #define A <<= 4 | -------------------------------------------------------------------------------- /tests/pp/16.expect: -------------------------------------------------------------------------------- 1 | 2 | 16.c:3: warning: A redefined 3 | -------------------------------------------------------------------------------- /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/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/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/pp/18.expect: -------------------------------------------------------------------------------- 1 | X181 1 2 | X182 0 3 | X183 yeah 4 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/pp/21.expect: -------------------------------------------------------------------------------- 1 | ----- 1 ------ 2 | OK 3 | ----- 2 ------ 4 | OK 5 | ----- 3 ------ 6 | OK 7 | ----- 4 ------ 8 | OK 9 | -------------------------------------------------------------------------------- /tests/pp/22.c: -------------------------------------------------------------------------------- 1 | #define TRACE(a,b,c) X a X b X c X 2 | #define rettrue(x) 1 3 | A rettrue(bla) B 4 | TRACE( 5 | ARG_1, 6 | #if rettrue(bla) 7 | ARG_2, 8 | #else 9 | ARG_2_wrong, 10 | #endif 11 | ARG_3 12 | ); 13 | -------------------------------------------------------------------------------- /tests/pp/22.expect: -------------------------------------------------------------------------------- 1 | A 1 B 2 | X ARG_1 X ARG_2 X ARG_3 X; 3 | -------------------------------------------------------------------------------- /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 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/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/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/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/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/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /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/tests2/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /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/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/03_struct.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char*, ...); 2 | 3 | struct fred; 4 | 5 | void fred$(struct fred* this) 6 | { 7 | printf("~fred()\n"); 8 | } 9 | 10 | struct __attribute__((__cleanup__(fred$))) fred 11 | { 12 | int boris; 13 | int natasha; 14 | }; 15 | 16 | int main() 17 | { 18 | struct fred __attribute__((__cleanup__(fred$))) bloggs; 19 | 20 | bloggs.boris = 12; 21 | bloggs.natasha = 34; 22 | 23 | printf("%d\n", bloggs.boris); 24 | printf("%d\n", bloggs.natasha); 25 | 26 | struct fred jones[2]; 27 | jones[0].boris = 12; 28 | jones[0].natasha = 34; 29 | jones[1].boris = 56; 30 | jones[1].natasha = 78; 31 | 32 | printf("%d\n", jones[0].boris); 33 | printf("%d\n", jones[0].natasha); 34 | printf("%d\n", jones[1].boris); 35 | printf("%d\n", jones[1].natasha); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /tests/tests2/03_struct.expect: -------------------------------------------------------------------------------- 1 | 03_struct.c:14: warning: attribute '__cleanup__' ignored on type 2 | 12 3 | 34 4 | 12 5 | 34 6 | 56 7 | 78 8 | ~fred() 9 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/tests2/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /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/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /tests/tests2/100_c99array-decls.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/100_c99array-decls.expect -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/102_alignas.expect: -------------------------------------------------------------------------------- 1 | 102_alignas.c:4: warning: type defaults to int 2 | 1 1 1 1 3 | -------------------------------------------------------------------------------- /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*,const void*,__SIZE_TYPE__); 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/103_implicit_memmove.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/103_implicit_memmove.expect -------------------------------------------------------------------------------- /tests/tests2/104+_inline.c: -------------------------------------------------------------------------------- 1 | 2 | #define GOT(f) \ 3 | __attribute__((weak)) void f(void); \ 4 | printf("%d %s\n", !!((__SIZE_TYPE__)f & ~0u), #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/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/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/105_local_extern.expect: -------------------------------------------------------------------------------- 1 | f 2 | f 3 | -------------------------------------------------------------------------------- /tests/tests2/106_versym.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | int ret; 9 | pthread_condattr_t attr; 10 | pthread_cond_t condition; 11 | 12 | /* This test fails if symbol versioning does not work */ 13 | pthread_condattr_init (&attr); 14 | pthread_condattr_setpshared (&attr, PTHREAD_PROCESS_SHARED); 15 | printf ("%s\n", pthread_cond_init (&condition, &attr) ? "fail":"ok"); 16 | pthread_condattr_destroy (&attr); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/tests2/106_versym.expect: -------------------------------------------------------------------------------- 1 | ok 2 | -------------------------------------------------------------------------------- /tests/tests2/107_stack_safe.c: -------------------------------------------------------------------------------- 1 | extern int printf(const char *, ...); 2 | 3 | static void func_ull_ull(unsigned long long l1,unsigned long long l2){ 4 | } 5 | 6 | int main() 7 | { 8 | int a,b,c,d; 9 | a=1;b=2;c=3;d=4; 10 | func_ull_ull((unsigned long long)a/1.0,(unsigned long long)b/1.0); 11 | printf("%d %d %d %d",a,b,c,d); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/tests2/107_stack_safe.expect: -------------------------------------------------------------------------------- 1 | 1 2 3 4 -------------------------------------------------------------------------------- /tests/tests2/108_constructor.c: -------------------------------------------------------------------------------- 1 | extern int write (int fd, void *buf, int len); 2 | 3 | static void __attribute__ ((constructor)) 4 | testc (void) 5 | { 6 | write (1, "constructor\n", 12); 7 | } 8 | 9 | static void __attribute__ ((destructor)) 10 | testd (void) 11 | { 12 | write (1, "destructor\n", 11); 13 | } 14 | 15 | int 16 | main (void) 17 | { 18 | write (1, "main\n", 5); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/tests2/108_constructor.expect: -------------------------------------------------------------------------------- 1 | constructor 2 | main 3 | destructor 4 | -------------------------------------------------------------------------------- /tests/tests2/109_float_struct_calling.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* This test used to fail on x86_64 on linux with sse registers */ 4 | 5 | struct Point { 6 | float x; 7 | float y; 8 | }; 9 | 10 | struct Rect { 11 | struct Point top_left; 12 | struct Point size; 13 | }; 14 | 15 | float foo(struct Point p, struct Rect r) { 16 | return r.size.x; 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | struct Point p = {1, 2}; 21 | struct Rect r = {{3, 4}, {5, 6}}; 22 | printf("%f\n", foo(p, r)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/tests2/109_float_struct_calling.expect: -------------------------------------------------------------------------------- 1 | 5.000000 2 | -------------------------------------------------------------------------------- /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/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/tests2/110_average.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct 4 | { 5 | double average; 6 | int count; 7 | } 8 | stats_type; 9 | 10 | static void 11 | testc (stats_type *s, long long data) 12 | { 13 | s->average = (s->average * s->count + data) / (s->count + 1); 14 | s->count++; 15 | } 16 | 17 | int main (void) 18 | { 19 | stats_type s; 20 | 21 | s.average = 0; 22 | s.count = 0; 23 | testc (&s, 10); 24 | testc (&s, 20); 25 | printf ("%g %d\n", s.average, s.count); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/tests2/110_average.expect: -------------------------------------------------------------------------------- 1 | 15 2 2 | -------------------------------------------------------------------------------- /tests/tests2/111_conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | union u { 4 | unsigned long ul; 5 | long double ld; 6 | }; 7 | 8 | void 9 | conv (union u *p) 10 | { 11 | p->ul = (unsigned int) p->ld; 12 | } 13 | 14 | int main (void) 15 | { 16 | union u v; 17 | 18 | v.ld = 42; 19 | conv (&v); 20 | printf ("%lu\n", v.ul); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/tests2/111_conversion.expect: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /tests/tests2/113_btdll.c: -------------------------------------------------------------------------------- 1 | int tcc_backtrace(const char*, ...); 2 | #define hello() \ 3 | tcc_backtrace("hello from %s() / %s:%d",__FUNCTION__,__FILE__,__LINE__) 4 | 5 | #ifndef _WIN32 6 | # define __declspec(n) 7 | #endif 8 | 9 | #if DLL==1 10 | __declspec(dllexport) int f_1() 11 | { 12 | hello(); 13 | return 0; 14 | } 15 | 16 | 17 | #elif DLL==2 18 | __declspec(dllexport) int f_2() 19 | { 20 | hello(); 21 | return 0; 22 | } 23 | 24 | 25 | #else 26 | 27 | int f_1(); 28 | int f_2(); 29 | int f_main() 30 | { 31 | hello(); 32 | return 0; 33 | } 34 | 35 | int main () 36 | { 37 | f_1(); 38 | f_2(); 39 | f_main(); 40 | return 0; 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /tests/tests2/113_btdll.expect: -------------------------------------------------------------------------------- 1 | 113_btdll.c:12: at f_1: hello from f_1() / 113_btdll.c:12 2 | 113_btdll.c:37: by main 3 | 113_btdll.c:20: at f_2: hello from f_2() / 113_btdll.c:20 4 | 113_btdll.c:38: by main 5 | 113_btdll.c:31: at f_main: hello from f_main() / 113_btdll.c:31 6 | 113_btdll.c:39: by main 7 | -------------------------------------------------------------------------------- /tests/tests2/114_bound_signal.expect: -------------------------------------------------------------------------------- 1 | start 2 | end 3 | -------------------------------------------------------------------------------- /tests/tests2/115_bound_setjmp.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/115_bound_setjmp.expect -------------------------------------------------------------------------------- /tests/tests2/116_bound_setjmp2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #if !defined(_WIN32) 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #define SIZE 10 11 | #define COUNT 10 12 | 13 | #define TST int i, a[2], b[2]; \ 14 | for (i = 0; i < 2; i++) a[i] = 0; \ 15 | for (i = 0; i < 2; i++) b[i] = 0 16 | 17 | static int count[SIZE]; 18 | 19 | static void tst1 (jmp_buf loc) 20 | { 21 | TST; 22 | longjmp(loc, 1); 23 | } 24 | 25 | static void tst2(jmp_buf loc) 26 | { 27 | jmp_buf jmp; 28 | 29 | setjmp (jmp); 30 | TST; 31 | tst1(loc); 32 | } 33 | 34 | static void *tst (void * index) 35 | { 36 | jmp_buf loc; 37 | int i = *(int *) index; 38 | static int v[SIZE]; 39 | 40 | for (v[i] = 0; v[i] < COUNT; v[i]++) { 41 | if (setjmp (loc) == 0) { 42 | TST; 43 | tst2(loc); 44 | } 45 | else { 46 | count[i]++; 47 | } 48 | i = *(int *) index; 49 | } 50 | return NULL; 51 | } 52 | 53 | int 54 | main (void) 55 | { 56 | int i; 57 | #if !defined(_WIN32) 58 | pthread_t id[SIZE]; 59 | #else 60 | HANDLE id[SIZE]; 61 | #endif 62 | int index[SIZE]; 63 | 64 | for (i = 0; i < SIZE; i++) { 65 | index[i] = i; 66 | #if !defined(_WIN32) 67 | pthread_create (&id[i], NULL, tst, (void *) &index[i]); 68 | #else 69 | id[i] = CreateThread(NULL, 8192, (LPTHREAD_START_ROUTINE) tst, (void *) &index[i], 0, NULL); 70 | #endif 71 | } 72 | for (i = 0; i < SIZE; i++) { 73 | #if !defined(_WIN32) 74 | pthread_join (id[i], NULL); 75 | #else 76 | WaitForSingleObject(id[i], INFINITE); 77 | #endif 78 | } 79 | for (i = 0; i < SIZE; i++) { 80 | if (count[i] != COUNT) 81 | printf ("error: %d %d\n", i, count[i]); 82 | } 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /tests/tests2/116_bound_setjmp2.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/116_bound_setjmp2.expect -------------------------------------------------------------------------------- /tests/tests2/117_builtins.expect: -------------------------------------------------------------------------------- 1 | BOUNDS OFF: 2 | 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:1 3 | BOUNDS ON: 4 | 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:1 5 | -------------------------------------------------------------------------------- /tests/tests2/118_switch.expect: -------------------------------------------------------------------------------- 1 | 1 : 1 2 | 10 : 2 3 | 100 : 3 4 | 1000 : 4 5 | 10000 : 5 6 | 100000 : 6 7 | 1000000 : 7 8 | 10000000 : 8 9 | 100000000 : 9 10 | 1000000000 : 10 11 | 10000000000 : 11 12 | 100000000000 : 12 13 | 1000000000000 : 13 14 | 10000000000000 : 14 15 | 100000000000000 : 15 16 | 1000000000000000 : 16 17 | 10000000000000000 : 17 18 | 100000000000000000 : 18 19 | 1000000000000000000 : 19 20 | -8446744073709551616 : 20 21 | 1 : 1 22 | 10 : 2 23 | 100 : 3 24 | 1000 : 4 25 | 10000 : 5 26 | 100000 : 6 27 | 1000000 : 7 28 | 10000000 : 8 29 | 100000000 : 9 30 | 1000000000 : 10 31 | 10000000000 : 11 32 | 100000000000 : 12 33 | 1000000000000 : 13 34 | 10000000000000 : 14 35 | 100000000000000 : 15 36 | 1000000000000000 : 16 37 | 10000000000000000 : 17 38 | 100000000000000000 : 18 39 | 1000000000000000000 : 19 40 | 10000000000000000000 : 20 41 | -------------------------------------------------------------------------------- /tests/tests2/119_random_stuff.expect: -------------------------------------------------------------------------------- 1 | tst_branch -- -- 2 | tst_adr 5 3 | tst_compare: ok 4 | tst_pack: j.f = 5, i.f = 5 5 | schar to ushort cast: ffff0033 6 | tst_indir_func 10 7 | 5 8 | -------------------------------------------------------------------------------- /tests/tests2/11_precedence.c: -------------------------------------------------------------------------------- 1 | //#include 2 | extern int printf(const char *, ...); 3 | 4 | int main() 5 | { 6 | int a; 7 | int b; 8 | int c; 9 | int d; 10 | int e; 11 | int f; 12 | int x; 13 | int y; 14 | 15 | a = 12; 16 | b = 34; 17 | c = 56; 18 | d = 78; 19 | e = 0; 20 | f = 1; 21 | 22 | printf("%d\n", c + d); 23 | printf("%d\n", (y = c + d)); 24 | printf("%d\n", e || e && f); 25 | printf("%d\n", e || f && f); 26 | printf("%d\n", e && e || f); 27 | printf("%d\n", e && f || f); 28 | printf("%d\n", a && f | f); 29 | printf("%d\n", a | b ^ c & d); 30 | printf("%d, %d\n", a == a, a == b); 31 | printf("%d, %d\n", a != a, a != b); 32 | printf("%d\n", a != b && c != d); 33 | printf("%d\n", a + b * c / f); 34 | printf("%d\n", a + b * c / f); 35 | printf("%d\n", (4 << 4)); 36 | printf("%d\n", (64 >> 4)); 37 | 38 | return 0; 39 | } 40 | 41 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 42 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/120+_alias.c: -------------------------------------------------------------------------------- 1 | extern int printf (const char *, ...); 2 | extern void target(void); 3 | extern void alias_for_target(void); 4 | extern void asm_for_target(void); 5 | 6 | void inunit2(void); 7 | 8 | void inunit2(void) 9 | { 10 | target(); 11 | alias_for_target(); 12 | /* This symbol is not supposed to be available in this unit: 13 | asm_for_target(); 14 | */ 15 | } 16 | -------------------------------------------------------------------------------- /tests/tests2/120_alias.c: -------------------------------------------------------------------------------- 1 | /* Check semantics of various constructs to generate renamed symbols. */ 2 | extern int printf (const char *, ...); 3 | void target(void); 4 | void target(void) { 5 | printf("in target function\n"); 6 | } 7 | 8 | void alias_for_target(void) __attribute__((alias("target"))); 9 | #ifdef __leading_underscore 10 | void asm_for_target(void) __asm__("_target"); 11 | #else 12 | void asm_for_target(void) __asm__("target"); 13 | #endif 14 | 15 | /* This is not supposed to compile, alias targets must be defined in the 16 | same unit. In TCC they even must be defined before the reference 17 | void alias_for_undef(void) __attribute__((alias("undefined"))); 18 | */ 19 | 20 | extern void inunit2(void); 21 | 22 | int main(void) 23 | { 24 | target(); 25 | alias_for_target(); 26 | asm_for_target(); 27 | inunit2(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/tests2/120_alias.expect: -------------------------------------------------------------------------------- 1 | in target function 2 | in target function 3 | in target function 4 | in target function 5 | in target function 6 | -------------------------------------------------------------------------------- /tests/tests2/121_struct_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | int data[4]; 5 | double d1; 6 | double d2; 7 | } Node; 8 | 9 | Node init(Node self) { 10 | self.data[0] = 0; 11 | self.data[1] = 1; 12 | self.data[2] = 2; 13 | self.data[3] = 3; 14 | self.d1 = 1234; 15 | self.d2 = 2345; 16 | return self; 17 | } 18 | 19 | void dummy(Node self) { 20 | } 21 | 22 | void print_data(Node data) { 23 | printf ("%d %d %d %d %g %g\n", 24 | data.data[0], data.data[1], data.data[2], data.data[3], 25 | data.d1, data.d2); 26 | } 27 | 28 | int main(void) { 29 | /* This code resulted in a bounds checking error */ 30 | Node data; 31 | dummy (data); 32 | char val; 33 | data = init (data); 34 | print_data(data); 35 | } 36 | -------------------------------------------------------------------------------- /tests/tests2/121_struct_return.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 1234 2345 2 | -------------------------------------------------------------------------------- /tests/tests2/122_vla_reuse.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main (void) 5 | { 6 | int n = 0; 7 | int first=1; 8 | int *p[101]; 9 | if (0) { 10 | lab:; 11 | } 12 | int x[n % 100 + 1]; 13 | if (first == 0) { 14 | if (&x[0] != p[n % 100 + 1]) { 15 | printf ("ERROR: %p %p\n", &x[0], p[n % 100 + 1]); 16 | return(1); 17 | } 18 | } 19 | else { 20 | p[n % 100 + 1] = &x[0]; 21 | first = n < 100; 22 | } 23 | x[0] = 1; 24 | x[n % 100] = 2; 25 | n++; 26 | if (n < 100000) 27 | goto lab; 28 | printf ("OK\n"); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /tests/tests2/122_vla_reuse.expect: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /tests/tests2/123_vla_bug.c: -------------------------------------------------------------------------------- 1 | typedef __SIZE_TYPE__ size_t; 2 | extern int printf(const char*, ...); 3 | extern size_t strlen(const char*); 4 | char str[] = "blabla"; 5 | int g; 6 | int main() 7 | { 8 | //char helpme[strlen(str) + 1]; 9 | int i = 0; 10 | #if 0 11 | if (g) { 12 | char buf[strlen(str) + 10]; 13 | buf[0] = 0; 14 | } 15 | alabel: 16 | printf("default: i = %d\n", i); 17 | #else 18 | for (i = 0; i < 5; i++) { 19 | switch (i) { 20 | case 10: 21 | if (g) { 22 | char buf[strlen(str) + 10]; 23 | buf[0] = 0; 24 | goto do_cmd; 25 | } 26 | break; 27 | case 1: 28 | printf("reached 3\n"); 29 | do_cmd: 30 | printf("after do_cmd"); 31 | break; 32 | default: 33 | g++; 34 | printf("default: i = %d\n", i); 35 | break; 36 | } 37 | } 38 | #endif 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /tests/tests2/123_vla_bug.expect: -------------------------------------------------------------------------------- 1 | default: i = 0 2 | reached 3 3 | after do_cmddefault: i = 2 4 | default: i = 3 5 | default: i = 4 6 | -------------------------------------------------------------------------------- /tests/tests2/124_atomic_counter.expect: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | -------------------------------------------------------------------------------- /tests/tests2/125_atomic_misc.expect: -------------------------------------------------------------------------------- 1 | [test_atomic_compare_exchange] 2 | 1 99 77 3 | 0 80 80 4 | 85 33 80 5 | 90 66 80 6 | 7 | [test_atomic_store] 8 | r = 12, i = 24 9 | 10 | [test_atomic_store_pointer] 11 | *p = 2 12 | 13 | [test_atomic_store_struct] 14 | 1 2 3 4 15 | 16 | [test_atomic_op] 17 | fetch_add: SUCCESS 18 | fetch_sub: SUCCESS 19 | fetch_or: SUCCESS 20 | fetch_xor: SUCCESS 21 | fetch_and: SUCCESS 22 | 23 | [test_atomic_op2] 24 | fetch_add: SUCCESS 25 | fetch_sub: SUCCESS 26 | fetch_or: SUCCESS 27 | fetch_xor: SUCCESS 28 | fetch_and: SUCCESS 29 | fetch_nand: SUCCESS 30 | add_fetch: SUCCESS 31 | sub_fetch: SUCCESS 32 | or_fetch: SUCCESS 33 | xor_fetch: SUCCESS 34 | and_fetch: SUCCESS 35 | nand_fetch: SUCCESS 36 | 37 | [test_atomic_thread_signal] 38 | 1 39 | 40 | [test_atomic_error_1] 41 | 125_atomic_misc.c:176: error: pointer expected 42 | 43 | [test_atomic_error_2] 44 | 125_atomic_misc.c:183: error: integral or integer-sized pointer target type expected 45 | 46 | [test_atomic_error_3] 47 | 125_atomic_misc.c:190: error: integral or integer-sized pointer target type expected 48 | 49 | [test_atomic_error_4] 50 | 125_atomic_misc.c:198: error: pointer target type mismatch in argument 2 51 | 52 | [test_atomic_warn_1] 53 | 125_atomic_misc.c:206: warning: assignment makes integer from pointer without a cast 54 | 55 | [test_atomic_warn_2] 56 | 125_atomic_misc.c:216: warning: assignment from incompatible pointer type 57 | 58 | [test_atomic_warn_3] 59 | 125_atomic_misc.c:224: warning: assignment of read-only location 60 | -------------------------------------------------------------------------------- /tests/tests2/126_bound_global.c: -------------------------------------------------------------------------------- 1 | /* test bound checking code without -run */ 2 | 3 | int arr[10]; 4 | 5 | int 6 | main(int argc, char **argv) 7 | { 8 | int i; 9 | 10 | for (i = 0; i <= sizeof(arr)/sizeof(arr[0]); i++) 11 | arr[i] = 0; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/tests2/126_bound_global.expect: -------------------------------------------------------------------------------- 1 | 126_bound_global.c:11: at main: BCHECK: ........ is outside of the region 2 | 126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access 3 | -------------------------------------------------------------------------------- /tests/tests2/127_asm_goto.c: -------------------------------------------------------------------------------- 1 | static int simple_jump(void) 2 | { 3 | asm goto ("jmp %l[label]" : : : : label); 4 | return 0; 5 | label: 6 | return 1; 7 | } 8 | 9 | static int three_way_jump(int val, int *addr) 10 | { 11 | *addr = 42; 12 | asm goto ("cmp $0, %1\n\t" 13 | "jg %l[larger]\n\t" 14 | "jl %l[smaller]\n\t" 15 | "incl %0\n\t" 16 | : "=m" (*addr) 17 | : "r" (val) 18 | : 19 | : smaller, larger); 20 | return 1; 21 | smaller: 22 | return 2; 23 | larger: 24 | return 3; 25 | } 26 | 27 | static int another_jump(void) 28 | { 29 | asm goto ("jmp %l[label]" : : : : label); 30 | return 70; 31 | /* Use the same label name as in simple_jump to check that 32 | that doesn't confuse our C/ASM symbol tables */ 33 | label: 34 | return 71; 35 | } 36 | 37 | extern int printf (const char *, ...); 38 | int main(void) 39 | { 40 | int i; 41 | if (simple_jump () == 1) 42 | printf ("simple_jump: okay\n"); 43 | else 44 | printf ("simple_jump: wrong\n"); 45 | if (another_jump () == 71) 46 | printf ("another_jump: okay\n"); 47 | else 48 | printf ("another_jump: wrong\n"); 49 | if (three_way_jump(0, &i) == 1 && i == 43) 50 | printf ("three_way_jump(0): okay\n"); 51 | else 52 | printf ("three_way_jump(0): wrong (i=%d)\n", i); 53 | if (three_way_jump(1, &i) == 3 && i == 42) 54 | printf ("three_way_jump(1): okay\n"); 55 | else 56 | printf ("three_way_jump(1): wrong (i=%d)\n", i); 57 | if (three_way_jump(-1, &i) == 2 && i == 42) 58 | printf ("three_way_jump(-1): okay\n"); 59 | else 60 | printf ("three_way_jump(-1): wrong (i=%d)\n", i); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /tests/tests2/127_asm_goto.expect: -------------------------------------------------------------------------------- 1 | simple_jump: okay 2 | another_jump: okay 3 | three_way_jump(0): okay 4 | three_way_jump(1): okay 5 | three_way_jump(-1): okay 6 | -------------------------------------------------------------------------------- /tests/tests2/128_run_atexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int atexit(void (*function)(void)); 4 | int on_exit(void (*function)(int, void *), void *arg); 5 | void exit(int status); 6 | 7 | void cleanup1(void) 8 | { 9 | printf ("cleanup1\n"); 10 | fflush(stdout); 11 | } 12 | 13 | void cleanup2(void) 14 | { 15 | printf ("cleanup2\n"); 16 | } 17 | 18 | void cleanup3(int ret, void *arg) 19 | { 20 | printf ("%d %s\n", ret, (char *) arg); 21 | } 22 | 23 | void cleanup4(int ret, void *arg) 24 | { 25 | printf ("%d %s\n", ret, (char *) arg); 26 | } 27 | 28 | void __attribute((destructor)) cleanup5(void) 29 | { 30 | printf ("cleanup5\n"); 31 | } 32 | 33 | void test(void) 34 | { 35 | atexit(cleanup1); 36 | atexit(cleanup2); 37 | on_exit(cleanup3, "cleanup3"); 38 | on_exit(cleanup4, "cleanup4"); 39 | } 40 | 41 | #if defined test_128_return 42 | int main(int argc, char **argv) 43 | { 44 | test(); 45 | return 1; 46 | } 47 | 48 | #elif defined test_128_exit 49 | int main(int argc, char **argv) 50 | { 51 | test(); 52 | exit(2); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /tests/tests2/128_run_atexit.expect: -------------------------------------------------------------------------------- 1 | [test_128_return] 2 | cleanup5 3 | 1 cleanup4 4 | 1 cleanup3 5 | cleanup2 6 | cleanup1 7 | [returns 1] 8 | 9 | [test_128_exit] 10 | cleanup5 11 | 2 cleanup4 12 | 2 cleanup3 13 | cleanup2 14 | cleanup1 15 | [returns 2] 16 | -------------------------------------------------------------------------------- /tests/tests2/129_scopes.c: -------------------------------------------------------------------------------- 1 | #include 2 | enum{ in = 0}; 3 | #define myassert(X) do{ if(!X) printf("%d: assertion failed\n", __LINE__); }while(0) 4 | int main(){ 5 | { 6 | myassert(!in); 7 | if(sizeof(enum{in=1})) myassert(in); 8 | myassert(!in); //OOPS 9 | } 10 | { 11 | myassert(!in); 12 | switch(sizeof(enum{in=1})) { default: myassert(in); } 13 | myassert(!in); //OOPS 14 | } 15 | { 16 | myassert(!in); 17 | while(sizeof(enum{in=1})) { myassert(in); break; } 18 | myassert(!in); //OOPS 19 | } 20 | { 21 | myassert(!in); 22 | do{ myassert(!in);}while(0*sizeof(enum{in=1})); 23 | myassert(!in); //OOPS 24 | } 25 | 26 | { 27 | myassert(!in); 28 | for(sizeof(enum{in=1});;){ myassert(in); break; } 29 | myassert(!in); //OK 30 | } 31 | { 32 | myassert(!in); 33 | for(;;sizeof(enum{in=1})){ myassert(in); break; } 34 | myassert(!in); //OK 35 | } 36 | { 37 | myassert(!in); 38 | for(;sizeof(enum{in=1});){ myassert(in); break; } 39 | myassert(!in); //OK 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /tests/tests2/129_scopes.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/129_scopes.expect -------------------------------------------------------------------------------- /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/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tests/tests2/130_large_argument.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct large1 { 4 | int a[768]; 5 | }; 6 | 7 | struct large2 { 8 | int a[1920]; 9 | }; 10 | 11 | void pass_large_struct1(struct large1 in) 12 | { 13 | printf("%d %d\n", in.a[200], in.a[767]); 14 | return; 15 | } 16 | 17 | void pass_large_struct2(struct large2 in) 18 | { 19 | printf("%d %d %d\n", in.a[200], in.a[1023], in.a[1919]); 20 | return; 21 | } 22 | 23 | void pass_many_args(int a, int b, int c, int d, int e, int f, int g, int h, int i, 24 | int j, int k, int l, int m) 25 | { 26 | printf("%d %d %d %d %d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i, 27 | j, k, l, m); 28 | return; 29 | } 30 | 31 | struct large1 l1 = { .a = { [200] = 1, [767] = 2 } }; 32 | struct large2 l2 = { .a = { [200] = 3, [1023] = 4, [1919] = 5} }; 33 | 34 | int main(void) 35 | { 36 | pass_large_struct1(l1); 37 | pass_large_struct2(l2); 38 | pass_many_args(13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/tests2/130_large_argument.expect: -------------------------------------------------------------------------------- 1 | 1 2 2 | 3 4 5 3 | 13 12 11 10 9 8 7 6 5 4 3 2 1 4 | -------------------------------------------------------------------------------- /tests/tests2/131_return_struct_in_reg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct s1 { 4 | unsigned char a:4, b:4; 5 | } g1 = { 0x05, 0x0a }; 6 | 7 | struct s2 { 8 | unsigned char a, b; 9 | } g2 = { 0x12, 0x34 }; 10 | 11 | struct s4 { 12 | unsigned short a, b; 13 | } g4 = { 0x1245, 0x5678 }; 14 | 15 | struct s8 { 16 | unsigned a, b; 17 | } g8 = { 0x12345678, 0x9abcdef0 }; 18 | 19 | /* returned in 2 registers on riscv64 */ 20 | struct s16 { 21 | unsigned long long a, b; 22 | } g16 = { 0x123456789abcdef0ULL, 0xfedcba9876543210ULL }; 23 | 24 | /* Homogeneous float aggregate on ARM hard-float */ 25 | struct s_f4 { 26 | double a, b, c, d; 27 | } g_f4 = { 1,2,3,4 }; 28 | 29 | #define def(S) \ 30 | struct s##S f##S(int x) \ 31 | { \ 32 | struct s##S l##S = g##S, *p##S = &l##S; \ 33 | if (x == 0) \ 34 | return g##S; \ 35 | else if (x == 1) \ 36 | return l##S; \ 37 | else \ 38 | return *p##S; \ 39 | } 40 | 41 | def(1) 42 | def(2) 43 | def(4) 44 | def(8) 45 | def(16) 46 | def(_f4) 47 | 48 | #define chk(S,x) \ 49 | struct s##S l##S = f##S(x); \ 50 | printf("%02llx %02llx\n", \ 51 | (unsigned long long)l##S.a, \ 52 | (unsigned long long)l##S.b \ 53 | ); 54 | 55 | int main() 56 | { 57 | for (int x = 0;;) { 58 | chk(1,x); 59 | chk(2,x); 60 | chk(4,x); 61 | chk(8,x); 62 | chk(16,x); 63 | struct s_f4 l_f4 = f_f4(x); 64 | printf("%.1f %.1f %.1f %.1f\n", l_f4.a, l_f4.b, l_f4.c, l_f4.d); 65 | if (++x > 2) 66 | break; 67 | printf("\n"); 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /tests/tests2/131_return_struct_in_reg.expect: -------------------------------------------------------------------------------- 1 | 05 0a 2 | 12 34 3 | 1245 5678 4 | 12345678 9abcdef0 5 | 123456789abcdef0 fedcba9876543210 6 | 1.0 2.0 3.0 4.0 7 | 8 | 05 0a 9 | 12 34 10 | 1245 5678 11 | 12345678 9abcdef0 12 | 123456789abcdef0 fedcba9876543210 13 | 1.0 2.0 3.0 4.0 14 | 15 | 05 0a 16 | 12 34 17 | 1245 5678 18 | 12345678 9abcdef0 19 | 123456789abcdef0 fedcba9876543210 20 | 1.0 2.0 3.0 4.0 21 | -------------------------------------------------------------------------------- /tests/tests2/132_bound_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | union ieee_double_extract 5 | { 6 | struct { 7 | unsigned int manl:32; 8 | unsigned int manh:20; 9 | unsigned int exp:11; 10 | unsigned int sig:1; 11 | } s; 12 | double d; 13 | }; 14 | 15 | double scale(double d) 16 | { 17 | union ieee_double_extract x; 18 | 19 | x.d = d; 20 | x.d *= 1000; 21 | return x.d; 22 | } 23 | 24 | int 25 | main(void) 26 | { 27 | printf("%g\n", scale(42)); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/tests2/132_bound_test.expect: -------------------------------------------------------------------------------- 1 | 42000 2 | -------------------------------------------------------------------------------- /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/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | enum to int: 1 5 | -------------------------------------------------------------------------------- /tests/tests2/18_include.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("including\n"); 6 | #include "18_include.h" 7 | #define test_missing_nl 8 | printf("done\n"); 9 | 10 | #define INC "18_include.h" 11 | 12 | #ifdef __has_include 13 | #if defined __has_include 14 | #if __has_include("18_include.h") 15 | printf("has_include\n"); 16 | #endif 17 | #if __has_include(INC) 18 | printf("has_include\n"); 19 | #endif 20 | #if __has_include("not_found_18_include.h") 21 | printf("has_include not found\n"); 22 | #endif 23 | #endif 24 | #endif 25 | 26 | #ifdef __has_include_next 27 | #if defined __has_include_next 28 | #if __has_include_next("18_include.h") 29 | printf("has_include_next\n"); 30 | #endif 31 | #if __has_include_next(INC) 32 | printf("has_include_next\n"); 33 | #endif 34 | #if __has_include_next("not_found_18_include.h") 35 | printf("has_include_next not found\n"); 36 | #endif 37 | #endif 38 | #endif 39 | 40 | #include "18_include2.h" 41 | #include "./18_include2.h" 42 | #include "../tests2/18_include2.h" 43 | 44 | return 0; 45 | } 46 | 47 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 48 | -------------------------------------------------------------------------------- /tests/tests2/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | has_include 5 | has_include 6 | has_include_next 7 | has_include_next 8 | counter 0 9 | -------------------------------------------------------------------------------- /tests/tests2/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | /* test file with missing newline */ 3 | #ifndef INCLUDE 4 | #define INCLUDE 5 | #endif /* INCLUDE */ -------------------------------------------------------------------------------- /tests/tests2/18_include2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | printf ("counter %d\n", __COUNTER__); 3 | -------------------------------------------------------------------------------- /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/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /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/tests2/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /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/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/22_floating_point.expect: -------------------------------------------------------------------------------- 1 | 69.119995 -631.327881 2 | 69.12 -631.328 3 | 69.120000 -631.327870 4 | 69.119995 -44.439999 700.665222 0.217330 5 | 69.12 -44.44 700.665 0.21733 6 | 69.120000 -44.440000 700.665200 0.217330 7 | 69.119995 -44.439999 700.665222 0.217330 8 | 69.12 -44.44 700.665 0.21733 9 | 69.120000 -44.440000 700.665200 0.217330 10 | 1 1 0 0 0 1 11 | 0 1 1 1 0 0 12 | 0 0 0 1 1 1 13 | 1 1 0 0 0 1 14 | 0 1 1 1 0 0 15 | 0 0 0 1 1 1 16 | 1 1 0 0 0 1 17 | 0 1 1 1 0 0 18 | 0 0 0 1 1 1 19 | 1 1 0 0 0 1 20 | 0 1 1 1 0 0 21 | 0 0 0 1 1 1 22 | 1 1 0 0 0 1 23 | 0 1 1 1 0 0 24 | 0 0 0 1 1 1 25 | 1 1 0 0 0 1 26 | 0 1 1 1 0 0 27 | 0 0 0 1 1 1 28 | 0 1 1 0 1 0 29 | 69.119995 69.12 69.120000 30 | 69.119995 69.12 69.120000 31 | -44.439999 -44.44 -44.440000 32 | -44.439999 -44.44 -44.440000 33 | 700.665222 700.665 700.665200 34 | 700.665222 700.665 700.665200 35 | 0.217330 0.21733 0.217330 36 | 0.217330 0.21733 0.217330 37 | 12.340000 12.34 12.340000 38 | -12.340000 -12.34 -12.340000 39 | 2.000000 40 | 0.909297 41 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/tests2/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | 4 5 | -------------------------------------------------------------------------------- /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/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/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/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tests/tests2/33_ternary_op.expect: -------------------------------------------------------------------------------- 1 | 33_ternary_op.c:26: warning: pointer/integer mismatch in conditional expression 2 | 0 3 | 1 4 | 4 5 | 9 6 | 16 7 | 15 8 | 18 9 | 21 10 | 24 11 | 27 12 | 152 13 | okay 14 | 1 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /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/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tests/tests2/36_array_initialisers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern int Array3[10]; 4 | int Array3[] = { 12, 34, }; 5 | int main() 6 | { 7 | int Count; 8 | 9 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 10 | 11 | for (Count = 0; Count < 10; Count++) 12 | printf("%d: %d\n", Count, Array[Count]); 13 | 14 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 15 | 16 | for (Count = 0; Count < 10; Count++) 17 | printf("%d: %d\n", Count, Array2[Count]); 18 | 19 | for (Count = 0; Count < 10; Count++) 20 | printf("%d: %d\n", Count, Array3[Count]); 21 | 22 | return 0; 23 | } 24 | 25 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 26 | -------------------------------------------------------------------------------- /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 | 0: 12 22 | 1: 34 23 | 2: 0 24 | 3: 0 25 | 4: 0 26 | 5: 0 27 | 6: 0 28 | 7: 0 29 | 8: 0 30 | 9: 0 31 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/tests2/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /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/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /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/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /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/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/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/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /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/tests2/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/tests2/55_lshift_type.expect: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tests/tests2/61_integers.expect: -------------------------------------------------------------------------------- 1 | 18/21=0 2 | 18%21=18 3 | 41/21=1 4 | 41%21=20 5 | 42/21=2 6 | 42%21=0 7 | 43/21=2 8 | 43%21=1 9 | 126/21=6 10 | 126%21=0 11 | 131/21=6 12 | 131%21=5 13 | (UINT_MAX/2+3)/2=1073741825 14 | (UINT_MAX/2+3)%2=0 15 | 18/-21=0 16 | 18%-21=18 17 | 41/-21=4294967295 18 | 41%-21=20 19 | 42/-21=4294967294 20 | 42%-21=0 21 | 43/-21=4294967294 22 | 43%-21=1 23 | 126/-21=4294967290 24 | 126%-21=0 25 | 131/-21=4294967290 26 | 131%-21=5 27 | (UINT_MAX/2+3)/-2=0 28 | (UINT_MAX/2+3)%-2=2147483650 29 | -18/21=0 30 | -18%21=4294967278 31 | -41/21=4294967295 32 | -41%21=4294967276 33 | -42/21=4294967294 34 | -42%21=0 35 | -43/21=4294967294 36 | -43%21=4294967295 37 | -126/21=4294967290 38 | -126%21=0 39 | -131/21=4294967290 40 | -131%21=4294967291 41 | -(UINT_MAX/2+3)/2=1073741823 42 | -(UINT_MAX/2+3)%2=0 43 | -18/-21=0 44 | -18%-21=4294967278 45 | -41/-21=1 46 | -41%-21=4294967276 47 | -42/-21=2 48 | -42%-21=0 49 | -43/-21=2 50 | -43%-21=4294967295 51 | -126/-21=6 52 | -126%-21=0 53 | -131/-21=6 54 | -131%-21=4294967291 55 | -(UINT_MAX/2+3)/-2=0 56 | -(UINT_MAX/2+3)%-2=2147483646 57 | -------------------------------------------------------------------------------- /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/64_macro_nesting.expect: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/67_macro_concat.expect: -------------------------------------------------------------------------------- 1 | jim: 21, bob: 42 2 | jim: 63 3 | -------------------------------------------------------------------------------- /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/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/tests2/71_macro_empty_arg.expect: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/72_long_long_constant.expect: -------------------------------------------------------------------------------- 1 | long long constant test ok. 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/77_push_pop_macro.expect: -------------------------------------------------------------------------------- 1 | abort = 111 2 | abort = 222 3 | abort = 333 4 | abort = 222 5 | abort = 111 6 | -------------------------------------------------------------------------------- /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/78_vla_label.expect: -------------------------------------------------------------------------------- 1 | boom! 2 | boom! 3 | 11 4 | 12 5 | 0 6 | 1 7 | -------------------------------------------------------------------------------- /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 b[f()]; 52 | if (count >= 0) { 53 | int a[f()]; 54 | 55 | addr[count] = a; 56 | 57 | continue; 58 | } 59 | } 60 | 61 | if(addr[9] == addr[0]) { 62 | printf("OK\n"); 63 | } else { 64 | printf("NOT OK\n"); 65 | } 66 | } 67 | 68 | void test4() 69 | { 70 | int count = 10; 71 | void *addr[count]; 72 | do { 73 | int a[f()]; 74 | 75 | addr[--count] = a; 76 | 77 | continue; 78 | } while (count); 79 | 80 | if(addr[9] == addr[0]) { 81 | printf("OK\n"); 82 | } else { 83 | printf("NOT OK\n"); 84 | } 85 | } 86 | 87 | void test5() 88 | { 89 | int count = 10; 90 | int a[f()]; 91 | int c[f()]; 92 | 93 | c[0] = 42; 94 | 95 | for(;count--;) { 96 | int b[f()]; 97 | int i; 98 | for (i=0; i 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 empty[] = {}; // GNU extension 19 | int main (void) { 20 | char s[9]="nonono"; 21 | static struct wchar q = {"bugs", {'c'}}; 22 | //printf ("tcc has %s %s\n", s, q.data); 23 | if (f1char() || f1int()) 24 | printf ("bla\n"); 25 | return !s[0]; 26 | } 27 | -------------------------------------------------------------------------------- /tests/tests2/80_flexarray.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/80_flexarray.expect -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/81_types.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/81_types.expect -------------------------------------------------------------------------------- /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 | int label_attribute (void) 34 | { 35 | lab1: __attribute__((__unused__)); 36 | return 0; 37 | } 38 | 39 | extern int printf (const char *, ...); 40 | static int globalvar; 41 | int main() 42 | { 43 | void *function_pointer = &actual_function; 44 | int localvar = 42, i; 45 | 46 | int a = ((ATTR int(*) (void)) function_pointer)(); 47 | printf("%i\n", a); 48 | 49 | /* In the following we once misparsed 'ATTR *' is a btype 50 | and hence the whole type was garbled. */ 51 | int b = ( (int(ATTR *)(void)) function_pointer)(); 52 | printf("%i\n", b); 53 | 54 | /* All these should work and leave the stack pointer in its original 55 | position. */ 56 | some_stdcall_func(1, 10, 100); 57 | ((int __stdcall (*)(int, int, int))some_stdcall_func) (2, 20, 200); 58 | ((int(*__stdcall)(int, int, int))some_stdcall_func) (3, 30, 300); 59 | for (i = 0; i < 1024; i++) { 60 | globalvar = i; 61 | /* This was once misparsed at <= gitrev 325241c0, forgetting 62 | the stdcall attribute on the function pointer leading to 63 | stack increment being done twice (in callee and caller). 64 | This will clobber 'i' and 'localvar' which is how we detect 65 | this. */ 66 | ((int(__stdcall*)(int, int, int))some_stdcall_func) (4, 40, 400); 67 | if (localvar != 42 || globalvar != i) 68 | printf("error, localvar=%d i=%d globalvar=%d\n", localvar, i, globalvar); 69 | } 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /tests/tests2/82_attribs_position.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 42 3 | -------------------------------------------------------------------------------- /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/tests2/83_utf8_in_identifiers.expect: -------------------------------------------------------------------------------- 1 | привет=0.1 2 | Lefèvre=2 3 | -------------------------------------------------------------------------------- /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/tests2/84_hex-float.expect: -------------------------------------------------------------------------------- 1 | n+1 = 15 2 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.c: -------------------------------------------------------------------------------- 1 | #ifdef __leading_underscore 2 | # define _ "_" 3 | #else 4 | # define _ 5 | #endif 6 | 7 | extern int printf (const char *, ...); 8 | extern void vide(void); 9 | __asm__(_"vide: ret"); 10 | 11 | int main() { 12 | vide(); 13 | printf ("okay\n"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/tests2/85_asm-outside-function.expect: -------------------------------------------------------------------------------- 1 | okay 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/86_memory-model.expect: -------------------------------------------------------------------------------- 1 | Ok 2 | -------------------------------------------------------------------------------- /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 | nondead works 25 | -------------------------------------------------------------------------------- /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 __SIZE_TYPE__ 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 | int ext; 48 | 49 | void broken_jumpopt (int xxx) 50 | { 51 | /* This was broken in 8227db3a2 by code suppression during suppressed 52 | code :) */ 53 | ext = (xxx || 1) || ((xxx && 1) || 1); 54 | printf("okay: %d %d\n", xxx, ext); 55 | } 56 | 57 | _Bool chk(unsigned long addr, unsigned long limit, unsigned long size) 58 | { 59 | _Bool ret; 60 | /* This just needs to compile, no runtime test. (And it doesn't compile 61 | only with certain internal checking added that's not committed). */ 62 | if (0) 63 | ret = 0 != (!!(addr > limit - size)); 64 | return 0; 65 | } 66 | 67 | int main() 68 | { 69 | void *r; 70 | _brk_start = 1024; 71 | _brk_end = 1024; 72 | r = extend_brk (4096, 16); 73 | if (!r) 74 | printf("wrong4\n"); 75 | else 76 | printf("okay\n"); 77 | bla(); 78 | broken_jumpopt(42); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /tests/tests2/88_codeopt.expect: -------------------------------------------------------------------------------- 1 | okay 2 | okay 3 | okay: 42 1 4 | -------------------------------------------------------------------------------- /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/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 | (0) 45 | ni 46 | four 47 | one 48 | (0) 49 | ni 50 | four 51 | 1 1 2 2 52 | mdfa glob: 30 - 3 4 5 6 7 8 3 4 5 6 7 8 3 4 5 6 7 8 9 0 0 10 0 0 97 98 99 0 0 0 53 | mdfa locl: 30 - 3 4 5 6 7 8 3 4 5 6 7 8 3 4 5 6 7 8 9 0 0 10 0 0 97 98 99 0 0 0 54 | sea_fill0: okay 55 | sea_fill1: okay 56 | sea_fill2: okay 57 | 1438 58 | test_init_struct_from_struct: 1 2 3 4 - 1 2 3 4 - 3 4 5 6 59 | test_init_bf: 1 2 3 60 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/91_ptr_longlong_arith32.expect: -------------------------------------------------------------------------------- 1 | data = "0123-5678" 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/tests2/92_enum_bitfield.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/C-Chads/tinycc/08c777053cb3b7f4f5d33bb0beeb82787d30ebe0/tests/tests2/92_enum_bitfield.expect -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | 5 16 | -------------------------------------------------------------------------------- /tests/tests2/95_bitfields_ms.c: -------------------------------------------------------------------------------- 1 | #define MS_BITFIELDS 1 2 | #include "95_bitfields.c" 3 | -------------------------------------------------------------------------------- /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: cast between pointer and integer of different size 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/97_utf8_string_literal.c: -------------------------------------------------------------------------------- 1 | // this file contains BMP chars encoded in UTF-8 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | char hello_world_in_czech[] = "čau, světe"; 10 | char hello_world_in_czech_ucn[] = "\u010dau, sv\u011bte"; 11 | if (sizeof(hello_world_in_czech) != sizeof(hello_world_in_czech_ucn) 12 | || strcmp(hello_world_in_czech, hello_world_in_czech_ucn)) 13 | abort(); 14 | 15 | wchar_t s[] = L"hello$$你好¢¢世界€€world"; 16 | wchar_t *p; 17 | for (p = s; *p; p++) printf("%04X ", (unsigned) *p); 18 | printf("\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #ifndef __leading_underscore 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/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/99_fastcall.expect: -------------------------------------------------------------------------------- 1 | TEST OK 2 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #if (__STDC_VERSION__ >= 201112L) && !defined(static_assert) 58 | /* C11, section 7.2: The macro static_assert expands to _Static_assert. */ 59 | #define static_assert(exp, str) _Static_assert(exp, str) 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /win32/include/sec_api/string_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_STRING_S 7 | #define _INC_STRING_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 _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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /win32/lib/chkstk.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* chkstk86.s */ 3 | 4 | #ifdef __leading_underscore 5 | # define _(s) _##s 6 | #else 7 | # define _(s) s 8 | #endif 9 | 10 | /* ---------------------------------------------- */ 11 | #ifndef __x86_64__ 12 | /* ---------------------------------------------- */ 13 | 14 | .globl _(__chkstk) 15 | _(__chkstk): 16 | xchg (%esp),%ebp /* store ebp, get ret.addr */ 17 | push %ebp /* push ret.addr */ 18 | lea 4(%esp),%ebp /* setup frame ptr */ 19 | push %ecx /* save ecx */ 20 | mov %ebp,%ecx 21 | P0: 22 | sub $4096,%ecx 23 | test %eax,(%ecx) 24 | sub $4096,%eax 25 | cmp $4096,%eax 26 | jge P0 27 | sub %eax,%ecx 28 | test %eax,(%ecx) 29 | 30 | mov %esp,%eax 31 | mov %ecx,%esp 32 | mov (%eax),%ecx /* restore ecx */ 33 | jmp *4(%eax) 34 | 35 | /* ---------------------------------------------- */ 36 | #else 37 | /* ---------------------------------------------- */ 38 | 39 | .globl _(__chkstk) 40 | _(__chkstk): 41 | xchg (%rsp),%rbp /* store ebp, get ret.addr */ 42 | push %rbp /* push ret.addr */ 43 | lea 8(%rsp),%rbp /* setup frame ptr */ 44 | push %rcx /* save ecx */ 45 | mov %rbp,%rcx 46 | movslq %eax,%rax 47 | P0: 48 | sub $4096,%rcx 49 | test %rax,(%rcx) 50 | sub $4096,%rax 51 | cmp $4096,%rax 52 | jge P0 53 | sub %rax,%rcx 54 | test %rax,(%rcx) 55 | 56 | mov %rsp,%rax 57 | mov %rcx,%rsp 58 | mov (%rax),%rcx /* restore ecx */ 59 | jmp *8(%rax) 60 | 61 | /* ---------------------------------------------- */ 62 | /* setjmp/longjmp support */ 63 | 64 | .globl _(tinyc_getbp) 65 | _(tinyc_getbp): 66 | mov %rbp,%rax 67 | ret 68 | 69 | /* ---------------------------------------------- */ 70 | #endif 71 | /* ---------------------------------------------- */ 72 | 73 | 74 | -------------------------------------------------------------------------------- /win32/lib/crt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "crt1.c" 4 | -------------------------------------------------------------------------------- /win32/lib/crtinit.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #ifdef __leading_underscore 4 | # define _(s) s 5 | #else 6 | # define _(s) _##s 7 | #endif 8 | 9 | extern void (*_(_init_array_start)[]) (int argc, _TCHAR **argv, _TCHAR **envp); 10 | extern void (*_(_init_array_end)[]) (int argc, _TCHAR **argv, _TCHAR **envp); 11 | extern void (*_(_fini_array_start)[]) (void); 12 | extern void (*_(_fini_array_end)[]) (void); 13 | 14 | static void run_ctors(int argc, _TCHAR **argv, _TCHAR **env) 15 | { 16 | int i = 0; 17 | while (&_(_init_array_start)[i] != _(_init_array_end)) 18 | (*_(_init_array_start)[i++])(argc, argv, env); 19 | } 20 | 21 | static void run_dtors(void) 22 | { 23 | int i = 0; 24 | while (&_(_fini_array_end)[i] != _(_fini_array_start)) 25 | (*_(_fini_array_end)[--i])(); 26 | } 27 | -------------------------------------------------------------------------------- /win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | #include 5 | #include "crtinit.c" 6 | 7 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved); 8 | 9 | BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) 10 | { 11 | BOOL bRet; 12 | if (dwReason == DLL_PROCESS_ATTACH) /* ignore DLL_THREAD_ATTACH */ 13 | run_ctors(0, 0, 0); 14 | bRet = DllMain (hDll, dwReason, lpReserved); 15 | if (dwReason == DLL_PROCESS_DETACH) /* ignore DLL_THREAD_DETACH */ 16 | run_dtors(); 17 | return bRet; 18 | } 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /win32/lib/wincrt1w.c: -------------------------------------------------------------------------------- 1 | #define _UNICODE 1 2 | #define UNICODE 1 3 | #include "wincrt1.c" 4 | --------------------------------------------------------------------------------