├── .clang-format ├── .clang-format-ignore ├── .clang-tidy ├── .clangd ├── .github └── workflows │ ├── jcc-site.yml │ ├── macos-aarch64.yml │ ├── macos-x86_64.yml │ ├── ubuntu-aarch64.yml │ ├── ubuntu-riscv.yml │ └── ubuntu-x86_64.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── docs ├── README.md ├── assets │ └── bad_literals.png ├── general.md ├── integers.md ├── known_issues.md ├── memory.md ├── parse.md ├── regalloc.md └── typechk.md ├── jcc.sh ├── scripts ├── benchmark.sh ├── build.sh ├── install.sh ├── prereqs.sh ├── profile.sh └── test.sh ├── src ├── aarch64.c ├── aarch64.h ├── aarch64 │ ├── codegen.c │ ├── codegen.h │ ├── emit.c │ ├── emit.h │ ├── emitter.c │ ├── emitter.h │ ├── isa.h │ ├── lower.c │ └── lower.h ├── alloc.c ├── alloc.h ├── ap_val.c ├── ap_val.h ├── args.c ├── args.h ├── argspec.h ├── bit_twiddle.h ├── bitset.c ├── bitset.h ├── builtins.c ├── builtins.h ├── codegen.c ├── codegen.h ├── compiler.c ├── compiler.h ├── compinfo.h ├── deque.c ├── deque.h ├── diagnostics.c ├── diagnostics.h ├── disasm.c ├── disasm.h ├── driver.c ├── driver.h ├── eep.c ├── eep.h ├── eep │ ├── README.md │ ├── codegen.c │ ├── codegen.h │ ├── disasm.c │ ├── disasm.h │ ├── emit.c │ ├── emit.h │ ├── emitter.c │ ├── emitter.h │ ├── isa.h │ ├── lower.c │ ├── lower.h │ ├── object.c │ └── object.h ├── emit.h ├── fcache.c ├── fcache.h ├── fs.c ├── fs.h ├── graphcol.c ├── graphcol.h ├── graphwriter.c ├── graphwriter.h ├── hash.c ├── hash.h ├── hashtbl.c ├── hashtbl.h ├── io.c ├── io.h ├── ir │ ├── build.c │ ├── build.h │ ├── eliminate_phi.c │ ├── eliminate_phi.h │ ├── interp.c │ ├── interp.h │ ├── ir.c │ ├── ir.h │ ├── prettyprint.c │ ├── prettyprint.h │ ├── rw.c │ ├── rw.h │ ├── validate.c │ ├── validate.h │ ├── var_refs.c │ └── var_refs.h ├── json.c ├── json.h ├── lex.c ├── lex.h ├── linux │ ├── elf.c │ ├── elf.h │ ├── elf_types.h │ ├── link.c │ └── link.h ├── liveness.c ├── liveness.h ├── log.c ├── log.h ├── lower.c ├── lower.h ├── lsp │ ├── ctx.h │ ├── lsp.c │ ├── lsp.h │ ├── lsp_types.c │ ├── lsp_types.h │ ├── map.c │ └── map.h ├── lsra.c ├── lsra.h ├── macos │ ├── link.c │ ├── link.h │ ├── mach-o.c │ ├── mach-o.h │ └── mach-o_types.h ├── main.c ├── opts │ ├── cnst_branches.c │ ├── cnst_branches.h │ ├── cnst_fold.c │ ├── cnst_fold.h │ ├── inline.c │ ├── inline.h │ ├── instr_comb.c │ ├── instr_comb.h │ ├── opts.c │ ├── opts.h │ ├── promote.c │ └── promote.h ├── parse.c ├── parse.h ├── preproc.c ├── preproc.h ├── profile.c ├── profile.h ├── program.c ├── program.h ├── rv32i.c ├── rv32i.h ├── rv32i │ ├── codegen.c │ ├── codegen.h │ ├── emit.c │ ├── emit.h │ ├── emitter.c │ ├── emitter.h │ ├── isa.h │ ├── lower.c │ ├── lower.h │ ├── object.c │ └── object.h ├── syscmd.c ├── syscmd.h ├── target.h ├── test.c ├── thrd.c ├── thrd.h ├── typechk.c ├── typechk.h ├── util.c ├── util.h ├── var_table.c ├── var_table.h ├── vector.c ├── vector.h ├── x64.c ├── x64.h └── x64 │ ├── codegen.c │ ├── codegen.h │ ├── emit.c │ ├── emit.h │ ├── emitter.c │ ├── emitter.h │ ├── isa.h │ ├── lower.c │ └── lower.h └── tests ├── 64_bit.c ├── aarch64_lower.c ├── add.c ├── addsub.c ├── advanced_decl.c ├── anonymous.c ├── array.c ├── array_access.c ├── array_init.c ├── array_inline_init.c ├── array_param.c ├── attribute.c ├── big_complex_maths.c ├── bitfield.c ├── bitfield_packed.c ├── bitwise.c ├── bool.c ├── brackets.c ├── c-testsuite ├── 00001.c ├── 00001.c.expected ├── 00002.c ├── 00002.c.expected ├── 00003.c ├── 00003.c.expected ├── 00004.c ├── 00004.c.expected ├── 00005.c ├── 00005.c.expected ├── 00006.c ├── 00006.c.expected ├── 00007.c ├── 00007.c.expected ├── 00008.c ├── 00008.c.expected ├── 00009.c ├── 00009.c.expected ├── 00010.c ├── 00010.c.expected ├── 00011.c ├── 00011.c.expected ├── 00012.c ├── 00012.c.expected ├── 00013.c ├── 00013.c.expected ├── 00014.c ├── 00014.c.expected ├── 00015.c ├── 00015.c.expected ├── 00016.c ├── 00016.c.expected ├── 00017.c ├── 00017.c.expected ├── 00018.c ├── 00018.c.expected ├── 00019.c ├── 00019.c.expected ├── 00020.c ├── 00020.c.expected ├── 00021.c ├── 00021.c.expected ├── 00022.c ├── 00022.c.expected ├── 00023.c ├── 00023.c.expected ├── 00024.c ├── 00024.c.expected ├── 00025.c ├── 00025.c.expected ├── 00026.c ├── 00026.c.expected ├── 00027.c ├── 00027.c.expected ├── 00028.c ├── 00028.c.expected ├── 00029.c ├── 00029.c.expected ├── 00030.c ├── 00030.c.expected ├── 00031.c ├── 00031.c.expected ├── 00032.c ├── 00032.c.expected ├── 00033.c ├── 00033.c.expected ├── 00034.c ├── 00034.c.expected ├── 00035.c ├── 00035.c.expected ├── 00036.c ├── 00036.c.expected ├── 00037.c ├── 00037.c.expected ├── 00038.c ├── 00038.c.expected ├── 00039.c ├── 00039.c.expected ├── 00040.c ├── 00040.c.expected ├── 00041.c ├── 00041.c.expected ├── 00042.c ├── 00042.c.expected ├── 00043.c ├── 00043.c.expected ├── 00044.c ├── 00044.c.expected ├── 00045.c ├── 00045.c.expected ├── 00046.c ├── 00046.c.expected ├── 00047.c ├── 00047.c.expected ├── 00048.c ├── 00048.c.expected ├── 00049.c ├── 00049.c.expected ├── 00050.c ├── 00050.c.expected ├── 00051.c ├── 00051.c.expected ├── 00052.c ├── 00052.c.expected ├── 00053.c ├── 00053.c.expected ├── 00054.c ├── 00054.c.expected ├── 00055.c ├── 00055.c.expected ├── 00056.c ├── 00056.c.expected ├── 00057.c ├── 00057.c.expected ├── 00058.c ├── 00058.c.expected ├── 00059.c ├── 00059.c.expected ├── 00060.c ├── 00060.c.expected ├── 00061.c ├── 00061.c.expected ├── 00062.c ├── 00062.c.expected ├── 00063.c ├── 00063.c.expected ├── 00064.c ├── 00064.c.expected ├── 00065.c ├── 00065.c.expected ├── 00066.c ├── 00066.c.expected ├── 00067.c ├── 00067.c.expected ├── 00068.c ├── 00068.c.expected ├── 00069.c ├── 00069.c.expected ├── 00070.c ├── 00070.c.expected ├── 00071.c ├── 00071.c.expected ├── 00072.c ├── 00072.c.expected ├── 00073.c ├── 00073.c.expected ├── 00074.c ├── 00074.c.expected ├── 00075.c ├── 00075.c.expected ├── 00076.c ├── 00076.c.expected ├── 00077.c ├── 00077.c.expected ├── 00078.c ├── 00078.c.expected ├── 00079.c ├── 00079.c.expected ├── 00080.c ├── 00080.c.expected ├── 00081.c ├── 00081.c.expected ├── 00082.c ├── 00082.c.expected ├── 00083.c ├── 00083.c.expected ├── 00084.c ├── 00084.c.expected ├── 00085.c ├── 00085.c.expected ├── 00086.c ├── 00086.c.expected ├── 00087.c ├── 00087.c.expected ├── 00088.c ├── 00088.c.expected ├── 00089.c ├── 00089.c.expected ├── 00090.c ├── 00090.c.expected ├── 00091.c ├── 00091.c.expected ├── 00092.c ├── 00092.c.expected ├── 00093.c ├── 00093.c.expected ├── 00094.c ├── 00094.c.expected ├── 00095.c ├── 00095.c.expected ├── 00096.c ├── 00096.c.expected ├── 00097.c ├── 00097.c.expected ├── 00098.c ├── 00098.c.expected ├── 00099.c ├── 00099.c.expected ├── 00100.c ├── 00100.c.expected ├── 00101.c ├── 00101.c.expected ├── 00102.c ├── 00102.c.expected ├── 00103.c ├── 00103.c.expected ├── 00104.c ├── 00104.c.expected ├── 00105.c ├── 00105.c.expected ├── 00106.c ├── 00106.c.expected ├── 00107.c ├── 00107.c.expected ├── 00108.c ├── 00108.c.expected ├── 00109.c ├── 00109.c.expected ├── 00110.c ├── 00110.c.expected ├── 00111.c ├── 00111.c.expected ├── 00112.c ├── 00112.c.expected ├── 00113.c ├── 00113.c.expected ├── 00114.c ├── 00114.c.expected ├── 00115.c ├── 00115.c.expected ├── 00116.c ├── 00116.c.expected ├── 00117.c ├── 00117.c.expected ├── 00118.c ├── 00118.c.expected ├── 00119.c ├── 00119.c.expected ├── 00120.c ├── 00120.c.expected ├── 00121.c ├── 00121.c.expected ├── 00122.c ├── 00122.c.expected ├── 00123.c ├── 00123.c.expected ├── 00124.c ├── 00124.c.expected ├── 00125.c ├── 00125.c.expected ├── 00126.c ├── 00126.c.expected ├── 00127.c ├── 00127.c.expected ├── 00128.c ├── 00128.c.expected ├── 00129.c ├── 00129.c.expected ├── 00130.c ├── 00130.c.expected ├── 00131.c ├── 00131.c.expected ├── 00132.c ├── 00132.c.expected ├── 00133.c ├── 00133.c.expected ├── 00134.c ├── 00134.c.expected ├── 00135.c ├── 00135.c.expected ├── 00136.c ├── 00136.c.expected ├── 00137.c ├── 00137.c.expected ├── 00138.c ├── 00138.c.expected ├── 00139.c ├── 00139.c.expected ├── 00140.c ├── 00140.c.expected ├── 00141.c ├── 00141.c.expected ├── 00142.c ├── 00142.c.expected ├── 00143.c ├── 00143.c.expected ├── 00144.c ├── 00144.c.expected ├── 00145.c ├── 00145.c.expected ├── 00146.c ├── 00146.c.expected ├── 00147.c ├── 00147.c.expected ├── 00148.c ├── 00148.c.expected ├── 00149.c ├── 00149.c.expected ├── 00150.c ├── 00150.c.expected ├── 00151.c ├── 00151.c.expected ├── 00152.c ├── 00152.c.expected ├── 00153.c ├── 00153.c.expected ├── 00154.c ├── 00154.c.expected ├── 00155.c ├── 00155.c.expected ├── 00156.c ├── 00156.c.expected ├── 00157.c ├── 00157.c.expected ├── 00158.c ├── 00158.c.expected ├── 00159.c ├── 00159.c.expected ├── 00160.c ├── 00160.c.expected ├── 00161.c ├── 00161.c.expected ├── 00162.c ├── 00162.c.expected ├── 00163.c ├── 00163.c.expected ├── 00164.c ├── 00164.c.expected ├── 00165.c ├── 00165.c.expected ├── 00166.c ├── 00166.c.expected ├── 00167.c ├── 00167.c.expected ├── 00168.c ├── 00168.c.expected ├── 00169.c ├── 00169.c.expected ├── 00170.c ├── 00170.c.expected ├── 00171.c ├── 00171.c.expected ├── 00172.c ├── 00172.c.expected ├── 00173.c ├── 00173.c.expected ├── 00174.c ├── 00174.c.expected ├── 00175.c ├── 00175.c.expected ├── 00176.c ├── 00176.c.expected ├── 00177.c ├── 00177.c.expected ├── 00178.c ├── 00178.c.expected ├── 00179.c ├── 00179.c.expected ├── 00180.c ├── 00180.c.expected ├── 00181.c ├── 00181.c.expected ├── 00182.c ├── 00182.c.expected ├── 00183.c ├── 00183.c.expected ├── 00184.c ├── 00184.c.expected ├── 00185.c ├── 00185.c.expected ├── 00186.c ├── 00186.c.expected ├── 00187.c ├── 00187.c.expected ├── 00188.c ├── 00188.c.expected ├── 00189.c ├── 00189.c.expected ├── 00190.c ├── 00190.c.expected ├── 00191.c ├── 00191.c.expected ├── 00192.c ├── 00192.c.expected ├── 00193.c ├── 00193.c.expected ├── 00194.c ├── 00194.c.expected ├── 00195.c ├── 00195.c.expected ├── 00196.c ├── 00196.c.expected ├── 00197.c ├── 00197.c.expected ├── 00198.c ├── 00198.c.expected ├── 00199.c ├── 00199.c.expected ├── 00200.c ├── 00200.c.expected ├── 00201.c ├── 00201.c.expected ├── 00202.c ├── 00202.c.expected ├── 00203.c ├── 00203.c.expected ├── 00204.c ├── 00204.c.expected ├── 00205.c ├── 00205.c.expected ├── 00206.c ├── 00206.c.expected ├── 00207.c ├── 00207.c.expected ├── 00208.c ├── 00208.c.expected ├── 00209.c ├── 00209.c.expected ├── 00210.c ├── 00210.c.expected ├── 00211.c ├── 00211.c.expected ├── 00212.c ├── 00212.c.expected ├── 00213.c ├── 00213.c.expected ├── 00214.c ├── 00214.c.expected ├── 00215.c ├── 00215.c.expected ├── 00216.c ├── 00216.c.expected ├── 00217.c ├── 00217.c.expected ├── 00218.c ├── 00218.c.expected ├── 00219.c ├── 00219.c.expected ├── 00220.c ├── 00220.c.expected └── LICENSE ├── c_exit_call.c ├── call_multi_func.c ├── cast.c ├── char_literals.c ├── cmp_zero.c ├── compare.c ├── complex_decls.c ├── compound_assg.c ├── compound_expr.c ├── compound_expr_stmt.c ├── compound_literal.c ├── compound_literal_and_init_list.c ├── compound_literal_scalar.c ├── cross_func_vars.c ├── decl.c ├── decl_shadow.c ├── defer.c ├── define.c ├── deref.c ├── designated.c ├── do_while.c ├── duffy.c ├── eep ├── mov_add_sub.c ├── mul.c ├── mul_asm.ram ├── mul_asm.txt └── mul_instr.c ├── empty.bin ├── empty.c ├── enum.c ├── eq.c ├── eq_var.c ├── escape_string.c ├── explicit_enum.c ├── extern_incomplete.c ├── fallthrough.c ├── fancy_pointer.c ├── fib.c ├── find_todo_tests.sh ├── float.c ├── float_arith.c ├── float_compare.c ├── float_if.c ├── flow.c ├── for.c ├── func.c ├── func_glb.c ├── func_pointer.c ├── func_var.c ├── generic.c ├── globals.c ├── half.c ├── hello_world.c ├── if.c ├── if_assign.c ├── if_else.c ├── if_else_assign.c ├── if_else_vars.c ├── implicit_addr.c ├── inc.c ├── inc_pointer.c ├── include.c ├── include.h ├── incomplete.c ├── init_list_arr.c ├── init_list_sub.c ├── init_lists.c ├── int_literal_types.c ├── integer_const_expr.c ├── langproc ├── _example │ ├── example.c │ └── example_driver.c ├── array │ ├── declare_global.c │ ├── declare_global_driver.c │ ├── declare_local.c │ ├── declare_local_driver.c │ ├── index_constant.c │ ├── index_constant_driver.c │ ├── index_expression.c │ ├── index_expression_driver.c │ ├── index_variable.c │ └── index_variable_driver.c ├── control_flow │ ├── for_multiple.c │ ├── for_multiple_driver.c │ ├── for_one.c │ ├── for_one_driver.c │ ├── for_zero_v1.c │ ├── for_zero_v1_driver.c │ ├── for_zero_v2.c │ ├── for_zero_v2_driver.c │ ├── if_else_false.c │ ├── if_else_false_driver.c │ ├── if_else_true.c │ ├── if_else_true_driver.c │ ├── if_false.c │ ├── if_false_driver.c │ ├── if_true.c │ ├── if_true_driver.c │ ├── sequence.c │ ├── sequence_driver.c │ ├── while_multiple.c │ ├── while_multiple_driver.c │ ├── while_once.c │ ├── while_once_driver.c │ ├── while_zero.c │ └── while_zero_driver.c ├── default │ ├── test_ADD0.c │ ├── test_ADD0_driver.c │ ├── test_ADD1.c │ ├── test_ADD1_driver.c │ ├── test_CALL.c │ ├── test_CALL_driver.c │ ├── test_LOCAL.c │ └── test_LOCAL_driver.c ├── float │ ├── add.c │ ├── add_double.c │ ├── add_double_driver.c │ ├── add_driver.c │ ├── add_mul.c │ ├── add_mul_driver.c │ ├── mul.c │ ├── mul_add.c │ ├── mul_add_driver.c │ ├── mul_double.c │ ├── mul_double_driver.c │ ├── mul_driver.c │ ├── pow.c │ └── pow_driver.c ├── functions │ ├── call_constant_external.c │ ├── call_constant_external_driver.c │ ├── call_constant_internal.c │ ├── call_constant_internal_driver.c │ ├── call_five_args_external.c │ ├── call_five_args_external_driver.c │ ├── call_five_args_internal.c │ ├── call_five_args_internal_driver.c │ ├── call_identity_external.c │ ├── call_identity_external_driver.c │ ├── call_identity_internal.c │ ├── call_identity_internal_driver.c │ ├── call_mutual_recursive.c │ ├── call_mutual_recursive_driver.c │ ├── call_recursive_internal.c │ ├── call_recursive_internal_driver.c │ ├── call_two_args_external.c │ ├── call_two_args_external_driver.c │ ├── call_two_args_internal.c │ └── call_two_args_internal_driver.c ├── integer │ ├── add.c │ ├── add_driver.c │ ├── bitwise_and.c │ ├── bitwise_and_driver.c │ ├── bitwise_or.c │ ├── bitwise_or_driver.c │ ├── bitwise_xor.c │ ├── bitwise_xor_driver.c │ ├── div.c │ ├── div_driver.c │ ├── equal.c │ ├── equal_driver.c │ ├── less_than.c │ ├── less_than_driver.c │ ├── less_than_equal.c │ ├── less_than_equal_driver.c │ ├── logical_and.c │ ├── logical_and_driver.c │ ├── logical_or.c │ ├── logical_or_driver.c │ ├── mul.c │ ├── mul_driver.c │ ├── sub.c │ └── sub_driver.c ├── local_var │ ├── constant_initialiser.c │ ├── constant_initialiser_driver.c │ ├── dual_var.c │ ├── dual_var_driver.c │ ├── expression_initialiser.c │ ├── expression_initialiser_driver.c │ ├── identity.c │ ├── identity_driver.c │ ├── scoped_var.c │ ├── scoped_var_driver.c │ ├── single_var.c │ └── single_var_driver.c ├── misc │ ├── enum1.c │ ├── enum1_driver.c │ ├── enum2.c │ ├── enum2_driver.c │ ├── switch1.c │ ├── switch1_driver.c │ ├── switch2.c │ ├── switch2_driver.c │ ├── typedef1.c │ ├── typedef1_driver.c │ ├── typedef2.c │ └── typedef2_driver.c ├── pointer │ ├── addressof.c │ ├── addressof_driver.c │ ├── arithmetic.c │ ├── arithmetic_driver.c │ ├── assign.c │ ├── assign_driver.c │ ├── dereference.c │ ├── dereference_driver.c │ ├── index.c │ └── index_driver.c ├── programs │ ├── fibonacci.c │ ├── fibonacci_driver.c │ ├── multiply.c │ ├── multiply_driver.c │ ├── sqrt.c │ └── sqrt_driver.c ├── strings │ ├── chliteral.c │ ├── chliteral_driver.c │ ├── escaped.c │ ├── escaped_driver.c │ ├── literal.c │ ├── literal_driver.c │ ├── puts.c │ ├── puts_driver.c │ ├── search.c │ └── search_driver.c ├── struct │ ├── sizeof.c │ ├── sizeof_driver.c │ ├── struct_inst.c │ ├── struct_inst_driver.c │ ├── struct_member_get.c │ ├── struct_member_get_driver.c │ ├── struct_member_set.c │ ├── struct_member_set_driver.c │ ├── struct_two_members.c │ └── struct_two_members_driver.c └── types │ ├── sizeof_char_inst.c │ ├── sizeof_char_inst_driver.c │ ├── sizeof_char_type.c │ ├── sizeof_char_type_driver.c │ ├── sizeof_int_inst.c │ ├── sizeof_int_inst_driver.c │ ├── sizeof_int_type.c │ ├── sizeof_int_type_driver.c │ ├── unsigned.c │ └── unsigned_driver.c ├── literals.c ├── local_static.c ├── logical.c ├── logical_and.c ├── macro_fn.c ├── many_args.c ├── math.c ├── md_array.c ├── memset.c ├── mixed_fp_ret.c ├── mul.c ├── multi_function.c ├── multi_if_else.c ├── multi_line_comment.c ├── negative.c ├── nested_struct.c ├── no_ret.c ├── null_char.c ├── offsetof.c ├── pointer.c ├── pointer_access.c ├── pointer_add.c ├── pointer_sub.c ├── popcnt.c ├── postfix.c ├── preproc.c ├── preproc_nested_if.c ├── preproc_nl.c ├── preproc_prescan.c ├── preproc_punctuator.c ├── preproc_ternary.c ├── printf_format.c ├── printf_string.c ├── programs ├── bf.c ├── donut.c ├── mandelbrot.c ├── mandelbrot_no_str.c └── maze.c ├── promote_phi.c ├── ptr_global.c ├── pythag.c ├── recursive_struct.c ├── reg_pressure.c ├── reg_pressure_extreme.c ├── sdiv.c ├── sext.c ├── single_line_comment.c ├── sizeof_ambigous.c ├── sizeof_expr.c ├── sizeof_ty.c ├── special.c ├── spill.c ├── sqrt.c ├── squot.c ├── static_assert.c ├── static_assert_fail.c ├── static_func.c ├── str_array.c ├── str_concat.c ├── str_global.c ├── str_index.c ├── struct.c ├── struct_arg.c ├── struct_inline_init.c ├── struct_move.c ├── struct_ret.c ├── sub.c ├── switch.c ├── ternary.c ├── typedef.c ├── typedef2.c ├── typedef_complex.c ├── typedef_duplicate.c ├── typeof.c ├── udiv.c ├── uninit_pointer.c ├── union.c ├── union_struct_nested.c ├── uquot.c ├── utf8.c ├── va_arg.c ├── va_list.c ├── variadic.c ├── vec2_add.c ├── vec2i_add.c ├── vec3 └── main.c ├── vec3_add.c ├── void_cast.c ├── while.c ├── while_complex.c ├── wide_char.c └── x_macro_fn.c /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | IndentWidth: 2 4 | --- 5 | # also configures for C 6 | Language: Cpp 7 | 8 | IncludeBlocks: Regroup 9 | -------------------------------------------------------------------------------- /.clang-format-ignore: -------------------------------------------------------------------------------- 1 | tests/* 2 | -------------------------------------------------------------------------------- /docs/assets/bad_literals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/docs/assets/bad_literals.png -------------------------------------------------------------------------------- /docs/known_issues.md: -------------------------------------------------------------------------------- 1 | 2 | # Known issues 3 | 4 | Scalar array initializers do not work as expected. 5 | 6 | ```c 7 | struct foo { 8 | int a[2]; 9 | }; 10 | 11 | struct foo f = { 1, 2, }; 12 | ``` 13 | 14 | is legal, but JCC currently rejects it; 15 | 16 | On systems where `ftell` fails for `stderr`, certain debug functions that attempt to pad their output will fail and enter a loop (known: `aarch64_debug_print_codegen`) 17 | -------------------------------------------------------------------------------- /src/argspec.h: -------------------------------------------------------------------------------- 1 | /********** Generic argument parser **********/ 2 | 3 | // i sort of don't like the file name 4 | 5 | #ifndef ARG_OPT_LIST 6 | #error 'Must define `ARG_OPT_LIST`' 7 | #else 8 | 9 | #undef ARG_OPT_LIST 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/builtins.c: -------------------------------------------------------------------------------- 1 | #include "builtins.h" 2 | 3 | #define BUILTIN_TY(...) 4 | #define BUILTIN_FN(name, ret_ty, param_count, param_tys) \ 5 | const struct builtin_fn_spec builtin_##name = { \ 6 | .ret = ret_ty, .num_params = param_count, .params = param_tys}; 7 | 8 | BUILTINS_LIST 9 | 10 | #undef BUILTIN_FN 11 | #undef BUILTIN_TY 12 | -------------------------------------------------------------------------------- /src/disasm.h: -------------------------------------------------------------------------------- 1 | #ifndef DISASM_H 2 | #define DISASM_H 3 | 4 | #include "compiler.h" 5 | 6 | // dumps using `objdump -d ` 7 | void objdump_debug_disasm(enum compile_target target, const char *filename, 8 | const char *output); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/driver.h: -------------------------------------------------------------------------------- 1 | #ifndef DRIVER_H 2 | #define DRIVER_H 3 | 4 | // top-level code for running a compilation, parsing args, etc 5 | 6 | void jcc_init(void); 7 | 8 | int jcc_main(int argc, char **argv); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/eep.h: -------------------------------------------------------------------------------- 1 | #ifndef EEP_H 2 | #define EEP_H 3 | 4 | #include "eep/disasm.h" 5 | #include "eep/emit.h" 6 | #include "eep/lower.h" 7 | #include "eep/object.h" 8 | #include "target.h" 9 | 10 | #define EEP_FUNCTION_ALIGNMENT (2) 11 | 12 | extern const struct target EEP_TARGET; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/eep/README.md: -------------------------------------------------------------------------------- 1 | # EEP - Read me! 2 | 3 | You almost certainly do not want to be reading this directory. It is a (currently disabled) backend for EEP, the first-year CPU coursework at Imperial College London. 4 | -------------------------------------------------------------------------------- /src/eep/disasm.h: -------------------------------------------------------------------------------- 1 | #ifndef EEP_DISASM 2 | #define EEP_DISASM 3 | 4 | void eep_debug_disasm(const char *filename); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/eep/emit.h: -------------------------------------------------------------------------------- 1 | #ifndef EEP_EMIT_H 2 | #define EEP_EMIT_H 3 | 4 | #include "../emit.h" 5 | #include "../lsra.h" 6 | 7 | // intervals MUST be sorted such that `interval[i].op_id == i` ID 8 | struct emitted_unit eep_emit(const struct codegen_unit *unit); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/eep/lower.h: -------------------------------------------------------------------------------- 1 | #ifndef EEP_LOWER_H 2 | #define EEP_LOWER_H 3 | 4 | #include "../ir/build.h" 5 | 6 | // performs platform specific lowering transformations to the IR 7 | void eep_lower(struct ir_unit *unit); 8 | 9 | void eep_debug_print_custom_ir_op(FILE *file, const struct ir_func *func, 10 | const struct ir_op *op); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/eep/object.h: -------------------------------------------------------------------------------- 1 | #ifndef EEP_OBJECT_H 2 | #define EEP_OBJECT_H 3 | 4 | #include "../target.h" 5 | 6 | void write_eep(const struct build_object_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/emit.h: -------------------------------------------------------------------------------- 1 | #ifndef EMIT_H 2 | #define EMIT_H 3 | 4 | #include "target.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/graphcol.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHCOL_H 2 | #define GRAPHCOL_H 3 | 4 | #include "ir/ir.h" 5 | #include "target.h" 6 | 7 | void graphcol_register_alloc(struct ir_func *irb, struct reg_info reg_info); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/ir/eliminate_phi.h: -------------------------------------------------------------------------------- 1 | #ifndef IR_ELIMINATE_PHI_H 2 | #define IR_ELIMINATE_PHI_H 3 | 4 | #include "ir.h" 5 | 6 | void eliminate_phi(struct ir_func *irb); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/ir/rw.h: -------------------------------------------------------------------------------- 1 | #ifndef IR_RW_H 2 | #define IR_RW_H 3 | 4 | // IR (de)?serialization 5 | 6 | #if 0 7 | #include "ir.h" 8 | 9 | #include 10 | 11 | void ir_unit_ser(FILE *file, struct ir_unit *unit); 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/linux/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_ELF_H 2 | #define LINUX_ELF_H 3 | 4 | #include "../target.h" 5 | 6 | void write_elf(const struct build_object_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/linux/link.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_LINK_H 2 | #define LINUX_LINK_H 3 | 4 | #include "../target.h" 5 | 6 | enum link_result linux_link_objects(const struct link_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/lsp/lsp.h: -------------------------------------------------------------------------------- 1 | #ifndef LSP_LSP_H 2 | #define LSP_LSP_H 3 | 4 | #include "../alloc.h" 5 | #include "../args.h" 6 | #include "../compiler.h" 7 | #include "../fs.h" 8 | 9 | int lsp_run(struct arena_allocator *arena, struct fs *fs, 10 | struct parsed_args args, struct compile_args compile_args, 11 | const struct target *target); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/lsra.h: -------------------------------------------------------------------------------- 1 | #ifndef LSRA_H 2 | #define LSRA_H 3 | 4 | #include "ir/ir.h" 5 | #include "target.h" 6 | 7 | void lsra_register_alloc(struct ir_func *irb, struct reg_info reg_info); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/macos/link.h: -------------------------------------------------------------------------------- 1 | #ifndef MACOS_LINK_H 2 | #define MACOS_LINK_H 3 | 4 | #include "../target.h" 5 | 6 | enum link_result macos_link_objects(const struct link_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/macos/mach-o.h: -------------------------------------------------------------------------------- 1 | #ifndef MACOS_MACH_O_H 2 | #define MACOS_MACH_O_H 3 | 4 | #include "../target.h" 5 | 6 | void write_macho(const struct build_object_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "driver.h" 2 | 3 | #include 4 | 5 | int main(int argc, char **argv) { 6 | jcc_init(); 7 | return jcc_main(argc, argv); 8 | } 9 | -------------------------------------------------------------------------------- /src/opts/cnst_branches.h: -------------------------------------------------------------------------------- 1 | #ifndef CNST_BRANCHES_H 2 | #define CNST_BRANCHES_H 3 | 4 | #include "../ir/ir.h" 5 | 6 | void opts_cnst_branches(struct ir_unit *unit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/opts/cnst_fold.h: -------------------------------------------------------------------------------- 1 | #ifndef CNST_FOLD_H 2 | #define CNST_FOLD_H 3 | 4 | #include "../ir/ir.h" 5 | 6 | void opts_cnst_fold(struct ir_unit *unit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/opts/inline.h: -------------------------------------------------------------------------------- 1 | #ifndef INLINE_H 2 | #define INLINE_H 3 | 4 | #include "../ir/ir.h" 5 | 6 | void opts_inline(struct ir_unit *unit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/opts/instr_comb.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTR_COMB_H 2 | #define INSTR_COMB_H 3 | 4 | #include "../ir/ir.h" 5 | 6 | void opts_instr_comb(struct ir_unit *unit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/opts/promote.h: -------------------------------------------------------------------------------- 1 | #ifndef PROMOTE_H 2 | #define PROMOTE_H 3 | 4 | #include "../ir/ir.h" 5 | 6 | void opts_promote(struct ir_unit *unit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/rv32i.h: -------------------------------------------------------------------------------- 1 | #ifndef RV32I_H 2 | #define RV32I_H 3 | 4 | #include "target.h" 5 | 6 | #define RV32I_FUNCTION_ALIGNMENT (8) 7 | 8 | extern const struct target RV32I_LINUX_TARGET; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/rv32i/emit.h: -------------------------------------------------------------------------------- 1 | #ifndef RV32I_EMIT_H 2 | #define RV32I_EMIT_H 3 | 4 | #include "../emit.h" 5 | #include "../ir/ir.h" 6 | 7 | // intervals MUST be sorted such that `interval[i].op_id == i` ID 8 | struct emitted_unit rv32i_emit(const struct cg_unit *unit); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/rv32i/object.h: -------------------------------------------------------------------------------- 1 | #ifndef RV32I_OBJECT_H 2 | #define RV32I_OBJECT_H 3 | 4 | #include "../target.h" 5 | 6 | void rv32i_write_object(const struct build_object_args *args); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/x64.h: -------------------------------------------------------------------------------- 1 | #ifndef X64_H 2 | #define X64_H 3 | 4 | #include "target.h" 5 | 6 | #define X64_FUNCTION_ALIGNMENT (4) 7 | #define X64_STACK_ALIGNMENT (16) 8 | #define MAX_IMM_SIZE (4095) 9 | 10 | extern const struct target X64_MACOS_TARGET; 11 | extern const struct target X64_LINUX_TARGET; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/x64/emit.h: -------------------------------------------------------------------------------- 1 | #ifndef X64_EMIT_H 2 | #define X64_EMIT_H 3 | 4 | #include "../codegen.h" 5 | 6 | const char *x64_linux_mangle(struct arena_allocator *arena, const char *name); 7 | const char *x64_macos_mangle(struct arena_allocator *arena, const char *name); 8 | 9 | // intervals MUST be sorted such that `interval[i].op_id == i` ID 10 | struct emitted_unit x64_emit(const struct cg_unit *unit); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tests/64_bit.c: -------------------------------------------------------------------------------- 1 | // expected value: 2 2 | int main() { 3 | long a = 1; 4 | long b = 1; 5 | 6 | return a + b; 7 | } 8 | -------------------------------------------------------------------------------- /tests/aarch64_lower.c: -------------------------------------------------------------------------------- 1 | // expected value: 5 2 | 3 | // ignore the slightly weird code 4 | // - it helps generate clearer IR for explaining lowering 5 | int main() { 6 | int a = 10, b = 7; 7 | 8 | int answer; 9 | 10 | if (a % b) { 11 | answer = 5; 12 | } else { 13 | answer = 88; 14 | } 15 | 16 | return answer; 17 | } 18 | -------------------------------------------------------------------------------- /tests/add.c: -------------------------------------------------------------------------------- 1 | // expected value: 16 2 | 3 | int puts(const char *); 4 | int main() { return 9 + 7; } 5 | -------------------------------------------------------------------------------- /tests/addsub.c: -------------------------------------------------------------------------------- 1 | // expected value: 56 2 | int main() { return 5 + 9 + 88 - 44 - 9 + 7; } 3 | -------------------------------------------------------------------------------- /tests/advanced_decl.c: -------------------------------------------------------------------------------- 1 | // expected value: 54 2 | int main() { 3 | int a = 1, b = 7; 4 | int z; 5 | z = 9; 6 | int k = 30; 7 | return k / 10 + 10 + a + b * b - z; 8 | } 9 | -------------------------------------------------------------------------------- /tests/array.c: -------------------------------------------------------------------------------- 1 | // expected value: 12 2 | 3 | int main() { 4 | int a[7]; 5 | for (int i = 0; i < 7; i += 1) { 6 | a[i] = i * 2; 7 | } 8 | return a[6]; 9 | } 10 | -------------------------------------------------------------------------------- /tests/array_access.c: -------------------------------------------------------------------------------- 1 | // expected value: 222 2 | 3 | int main() { 4 | int a = 57005; 5 | char *b = (char *)&a; 6 | return b[1]; 7 | } 8 | -------------------------------------------------------------------------------- /tests/array_init.c: -------------------------------------------------------------------------------- 1 | // expected value: 12 2 | 3 | int main() { 4 | int a[7] = {1, 2, 3, 4, 5, 6, 12}; 5 | return a[6]; 6 | } 7 | -------------------------------------------------------------------------------- /tests/array_param.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | int foo(int a[]) { 4 | return a[0]; 5 | } 6 | 7 | int main() { 8 | int a[1] = {1}; 9 | 10 | return foo(a); 11 | } 12 | -------------------------------------------------------------------------------- /tests/attribute.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | __attribute__ ((noinline)) int printf(const char * , ...) __attribute__((__format__ (__printf__, 1, 2))) __attribute__((foo)); 4 | 5 | int foo __attribute__((bar)); 6 | 7 | int main() { 8 | } 9 | -------------------------------------------------------------------------------- /tests/bitwise.c: -------------------------------------------------------------------------------- 1 | // expected value: 106 2 | 3 | int main() { 4 | int a = 0xFE; 5 | int b = a & 1; 6 | int c = a | 0xFF; 7 | int d = a ^ 0xF; 8 | int e = ~a; 9 | int f = a << 1; 10 | int g = a >> 1; 11 | 12 | return a + b + c + d + e + f + g; 13 | } 14 | -------------------------------------------------------------------------------- /tests/brackets.c: -------------------------------------------------------------------------------- 1 | // expected value: 20 2 | int main() { 3 | int a = 1; 4 | int b = 10; 5 | return (a + a) * b; 6 | } 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00001.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00001.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00001.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00002.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return 3-3; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00002.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00002.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00003.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 4; 7 | return x - 4; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00003.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00003.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00004.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 4; 8 | p = &x; 9 | *p = 0; 10 | 11 | return *p; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00004.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00004.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00005.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | int **pp; 7 | 8 | x = 0; 9 | p = &x; 10 | pp = &p; 11 | 12 | if(*p) 13 | return 1; 14 | if(**pp) 15 | return 1; 16 | else 17 | **pp = 1; 18 | 19 | if(x) 20 | return 0; 21 | else 22 | return 1; 23 | } 24 | -------------------------------------------------------------------------------- /tests/c-testsuite/00005.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00005.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00006.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 50; 7 | while (x) 8 | x = x - 1; 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00006.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00006.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00007.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | for(x = 10; x; x = x - 1) 8 | ; 9 | if(x) 10 | return 1; 11 | x = 10; 12 | for (;x;) 13 | x = x - 1; 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00007.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00007.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00008.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 50; 7 | do 8 | x = x - 1; 9 | while(x); 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00008.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00008.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00009.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x * 10; 8 | x = x / 2; 9 | x = x % 3; 10 | return x - 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00009.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00009.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00010.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | start: 5 | goto next; 6 | return 1; 7 | success: 8 | return 0; 9 | next: 10 | foo: 11 | goto success; 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00010.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00010.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00011.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int y; 6 | x = y = 0; 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00011.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00011.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00012.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return (2 + 2) * 2 - 8; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00012.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00012.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00013.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 0; 8 | p = &x; 9 | return p[0]; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00013.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00013.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00014.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | int *p; 6 | 7 | x = 1; 8 | p = &x; 9 | p[0] = 0; 10 | return x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00014.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00014.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00015.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | 6 | arr[0] = 1; 7 | arr[1] = 2; 8 | 9 | return arr[0] + arr[1] - 3; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00015.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00015.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00016.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[1]; 8 | *p = 0; 9 | return arr[1]; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00016.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00016.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00017.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct { int x; int y; } s; 5 | 6 | s.x = 3; 7 | s.y = 5; 8 | return s.y - s.x - 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00017.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00017.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00018.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | 5 | struct S { int x; int y; } s; 6 | struct S *p; 7 | 8 | p = &s; 9 | s.x = 1; 10 | p->y = 2; 11 | return p->y + p->x - 3; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00018.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00018.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00019.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct S { struct S *p; int x; } s; 5 | 6 | s.x = 0; 7 | s.p = &s; 8 | return s.p->p->p->p->p->x; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00019.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00019.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00020.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x, *p, **pp; 5 | 6 | x = 0; 7 | p = &x; 8 | pp = &p; 9 | return **pp; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00020.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00020.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00021.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(int a, int b) 3 | { 4 | return 2 + a - b; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return foo(1, 3); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00021.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00021.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00022.c: -------------------------------------------------------------------------------- 1 | typedef int x; 2 | 3 | int 4 | main() 5 | { 6 | x v; 7 | v = 0; 8 | return v; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00022.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00022.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00023.c: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | int 4 | main() 5 | { 6 | x = 0; 7 | return x; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00023.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00023.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00024.c: -------------------------------------------------------------------------------- 1 | typedef struct { int x; int y; } s; 2 | 3 | s v; 4 | 5 | int 6 | main() 7 | { 8 | v.x = 1; 9 | v.y = 2; 10 | return 3 - v.x - v.y; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00024.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00024.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00025.c: -------------------------------------------------------------------------------- 1 | int strlen(char *); 2 | 3 | int 4 | main() 5 | { 6 | char *p; 7 | 8 | p = "hello"; 9 | return strlen(p) - 5; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00025.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00025.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00026.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char *p; 5 | 6 | p = "hello"; 7 | return p[0] - 104; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00026.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00026.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00027.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x | 4; 8 | return x - 5; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00027.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00027.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00028.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x & 3; 8 | return x - 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00028.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00028.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00029.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | x = x ^ 3; 8 | return x - 2; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00029.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00029.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00030.c: -------------------------------------------------------------------------------- 1 | int 2 | f() 3 | { 4 | return 100; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | if (f() > 1000) 11 | return 1; 12 | if (f() >= 1000) 13 | return 1; 14 | if (1000 < f()) 15 | return 1; 16 | if (1000 <= f()) 17 | return 1; 18 | if (1000 == f()) 19 | return 1; 20 | if (100 != f()) 21 | return 1; 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/c-testsuite/00030.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00030.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00031.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00031.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00032.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00032.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00033.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00033.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00034.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00034.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00035.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 4; 7 | if(!x != 0) 8 | return 1; 9 | if(!!x != 1) 10 | return 1; 11 | if(-x != 0 - 4) 12 | return 1; 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00035.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00035.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00036.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 0; 7 | x += 2; 8 | x += 2; 9 | if (x != 4) 10 | return 1; 11 | x -= 1; 12 | if (x != 3) 13 | return 2; 14 | x *= 2; 15 | if (x != 6) 16 | return 3; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/c-testsuite/00036.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00036.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00037.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x[2]; 5 | int *p; 6 | 7 | x[1] = 7; 8 | p = &x[0]; 9 | p = p + 1; 10 | 11 | if(*p != 7) 12 | return 1; 13 | if(&x[1] - &x[0] != 1) 14 | return 1; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00037.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00037.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00038.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x, *p; 5 | 6 | if (sizeof(0) < 2) 7 | return 1; 8 | if (sizeof 0 < 2) 9 | return 2; 10 | if (sizeof(char) < 1) 11 | return 3; 12 | if (sizeof(int) - 2 < 0) 13 | return 4; 14 | if (sizeof(&x) != sizeof p) 15 | return 5; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00038.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00038.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00039.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | void *p; 5 | int x; 6 | 7 | x = 2; 8 | p = &x; 9 | 10 | if(*((int*)p) != 2) 11 | return 1; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00039.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00039.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00040.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00040.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00041.c: -------------------------------------------------------------------------------- 1 | int 2 | main() { 3 | int n; 4 | int t; 5 | int c; 6 | int p; 7 | 8 | c = 0; 9 | n = 2; 10 | while (n < 5000) { 11 | t = 2; 12 | p = 1; 13 | while (t*t <= n) { 14 | if (n % t == 0) 15 | p = 0; 16 | t++; 17 | } 18 | n++; 19 | if (p) 20 | c++; 21 | } 22 | if (c != 669) 23 | return 1; 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /tests/c-testsuite/00041.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00041.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00042.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | union { int a; int b; } u; 5 | u.a = 1; 6 | u.b = 3; 7 | 8 | if (u.a != 3 || u.b != 3) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00042.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00042.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00043.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int x; 3 | struct { 4 | int y; 5 | int z; 6 | } nest; 7 | }; 8 | 9 | int 10 | main() { 11 | struct s v; 12 | v.x = 1; 13 | v.nest.y = 2; 14 | v.nest.z = 3; 15 | if (v.x + v.nest.y + v.nest.z != 6) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/c-testsuite/00043.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00043.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00044.c: -------------------------------------------------------------------------------- 1 | struct T; 2 | 3 | struct T { 4 | int x; 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | struct T v; 11 | { struct T { int z; }; } 12 | v.x = 2; 13 | if(v.x != 2) 14 | return 1; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00044.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00044.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00045.c: -------------------------------------------------------------------------------- 1 | int x = 5; 2 | long y = 6; 3 | int *p = &x; 4 | 5 | int 6 | main() 7 | { 8 | if (x != 5) 9 | return 1; 10 | if (y != 6) 11 | return 2; 12 | if (*p != 5) 13 | return 3; 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00045.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00045.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00046.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00046.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00047.c: -------------------------------------------------------------------------------- 1 | struct { int a; int b; int c; } s = {1, 2, 3}; 2 | 3 | int 4 | main() 5 | { 6 | if (s.a != 1) 7 | return 1; 8 | if (s.b != 2) 9 | return 2; 10 | if (s.c != 3) 11 | return 3; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00047.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00047.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00048.c: -------------------------------------------------------------------------------- 1 | struct S {int a; int b;}; 2 | struct S s = { .b = 2, .a = 1}; 3 | 4 | int 5 | main() 6 | { 7 | if(s.a != 1) 8 | return 1; 9 | if(s.b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00048.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00048.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00049.c: -------------------------------------------------------------------------------- 1 | int x = 10; 2 | 3 | struct S {int a; int *p;}; 4 | struct S s = { .p = &x, .a = 1}; 5 | 6 | int 7 | main() 8 | { 9 | if(s.a != 1) 10 | return 1; 11 | if(*s.p != 10) 12 | return 2; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00049.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00049.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00050.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00050.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00051.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00051.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00052.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct T { int x; }; 5 | { 6 | struct T s; 7 | s.x = 0; 8 | return s.x; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00052.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00052.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00053.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct T { int x; } s1; 5 | s1.x = 1; 6 | { 7 | struct T { int y; } s2; 8 | s2.y = 1; 9 | if (s1.x - s2.y != 0) 10 | return 1; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00053.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00053.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00054.c: -------------------------------------------------------------------------------- 1 | enum E { 2 | x, 3 | y, 4 | z, 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | enum E e; 11 | 12 | if(x != 0) 13 | return 1; 14 | if(y != 1) 15 | return 2; 16 | if(z != 2) 17 | return 3; 18 | 19 | e = x; 20 | return e; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/c-testsuite/00054.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00054.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00055.c: -------------------------------------------------------------------------------- 1 | enum E { 2 | x, 3 | y = 2, 4 | z, 5 | }; 6 | 7 | int 8 | main() 9 | { 10 | enum E e; 11 | 12 | if(x != 0) 13 | return 1; 14 | if(y != 2) 15 | return 2; 16 | if(z != 3) 17 | return 3; 18 | 19 | e = x; 20 | return e; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/c-testsuite/00055.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00055.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00056.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/c-testsuite/00056.c.expected: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /tests/c-testsuite/00057.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char a[16], b[16]; 5 | 6 | if(sizeof(a) != sizeof(b)) 7 | return 1; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00057.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00057.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00058.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | char * s; 4 | 5 | s = "abc" "def"; 6 | if(s[0] != 'a') return 1; 7 | if(s[1] != 'b') return 2; 8 | if(s[2] != 'c') return 3; 9 | if(s[3] != 'd') return 4; 10 | if(s[4] != 'e') return 5; 11 | if(s[5] != 'f') return 6; 12 | if(s[6] != 0) return 7; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00058.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00058.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00059.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | if ('a' != 97) 5 | return 1; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00059.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00059.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00060.c: -------------------------------------------------------------------------------- 1 | 2 | // line comment 3 | 4 | int 5 | main() 6 | { 7 | /* 8 | multiline 9 | comment 10 | */ 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00060.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00060.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00061.c: -------------------------------------------------------------------------------- 1 | #define FOO 0 2 | 3 | int main() 4 | { 5 | return FOO; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00061.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00061.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00062.c: -------------------------------------------------------------------------------- 1 | #ifdef FOO 2 | XXX 3 | #ifdef BAR 4 | XXX 5 | #endif 6 | XXX 7 | #endif 8 | 9 | #define FOO 1 10 | 11 | #ifdef FOO 12 | 13 | #ifdef FOO 14 | int x = 0; 15 | #endif 16 | 17 | int 18 | main() 19 | { 20 | return x; 21 | } 22 | #endif 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/c-testsuite/00062.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00062.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00063.c: -------------------------------------------------------------------------------- 1 | #define BAR 0 2 | #ifdef BAR 3 | #ifdef FOO 4 | XXX 5 | #ifdef FOO 6 | XXX 7 | #endif 8 | #else 9 | #define FOO 10 | #ifdef FOO 11 | int x = BAR; 12 | #endif 13 | #endif 14 | #endif 15 | 16 | int 17 | main() 18 | { 19 | return BAR; 20 | } 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00063.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00063.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00064.c: -------------------------------------------------------------------------------- 1 | #define X 6 / 2 2 | 3 | int 4 | main() 5 | { 6 | return X - 3; 7 | } 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00064.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00064.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00065.c: -------------------------------------------------------------------------------- 1 | #define ADD(X, Y) (X + Y) 2 | 3 | 4 | int 5 | main() 6 | { 7 | return ADD(1, 2) - 3; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00065.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00065.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00066.c: -------------------------------------------------------------------------------- 1 | #define A 3 2 | #define FOO(X,Y,Z) X + Y + Z 3 | #define SEMI ; 4 | 5 | int 6 | main() 7 | { 8 | if(FOO(1, 2, A) != 6) 9 | return 1 SEMI 10 | return FOO(0,0,0); 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00066.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00066.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00067.c: -------------------------------------------------------------------------------- 1 | #if 1 2 | int x = 0; 3 | #endif 4 | 5 | #if 0 6 | int x = 1; 7 | #if 1 8 | X 9 | #endif 10 | #ifndef AAA 11 | X 12 | #endif 13 | #endif 14 | 15 | int main() 16 | { 17 | return x; 18 | } 19 | -------------------------------------------------------------------------------- /tests/c-testsuite/00067.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00067.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00068.c: -------------------------------------------------------------------------------- 1 | #if 0 2 | X 3 | #elif 1 4 | int x = 0; 5 | #else 6 | X 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return x; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00068.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00068.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00069.c: -------------------------------------------------------------------------------- 1 | #if 0 2 | X 3 | #elif 0 4 | X 5 | #elif 1 6 | int x = 0; 7 | #endif 8 | 9 | int 10 | main() 11 | { 12 | return x; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00069.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00069.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00070.c: -------------------------------------------------------------------------------- 1 | #ifndef DEF 2 | int x = 0; 3 | #endif 4 | 5 | #define DEF 6 | 7 | #ifndef DEF 8 | X 9 | #endif 10 | 11 | int 12 | main() 13 | { 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00070.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00070.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00071.c: -------------------------------------------------------------------------------- 1 | #define X 1 2 | #undef X 3 | 4 | #ifdef X 5 | FAIL 6 | #endif 7 | 8 | int 9 | main() 10 | { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00071.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00071.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00072.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[0]; 8 | p += 1; 9 | *p = 123; 10 | 11 | if(arr[1] != 123) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00072.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00072.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00073.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int arr[2]; 5 | int *p; 6 | 7 | p = &arr[1]; 8 | p -= 1; 9 | *p = 123; 10 | 11 | if(arr[0] != 123) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00073.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00073.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00074.c: -------------------------------------------------------------------------------- 1 | #if defined X 2 | X 3 | #endif 4 | 5 | #if defined(X) 6 | X 7 | #endif 8 | 9 | #if X 10 | X 11 | #endif 12 | 13 | #define X 0 14 | 15 | #if X 16 | X 17 | #endif 18 | 19 | #if defined(X) 20 | int x = 0; 21 | #endif 22 | 23 | #undef X 24 | #define X 1 25 | 26 | #if X 27 | int 28 | main() 29 | { 30 | return 0; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /tests/c-testsuite/00074.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00074.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00075.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00075.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00076.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | if(0 ? 1 : 0) 5 | return 1; 6 | if(1 ? 0 : 1) 7 | return 2; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00076.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00076.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00077.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00077.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00078.c: -------------------------------------------------------------------------------- 1 | int 2 | f1(char *p) 3 | { 4 | return *p+1; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | char s = 1; 11 | int v[1000]; 12 | int f1(char *); 13 | 14 | if (f1(&s) != 2) 15 | return 1; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00078.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00078.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00079.c: -------------------------------------------------------------------------------- 1 | #define x(y) ((y) + 1) 2 | 3 | int 4 | main() 5 | { 6 | int x; 7 | int y; 8 | 9 | y = 0; 10 | x = x(y); 11 | 12 | if(x != 1) 13 | return 1; 14 | 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00079.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00079.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00080.c: -------------------------------------------------------------------------------- 1 | void 2 | voidfn() 3 | { 4 | return; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | voidfn(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00080.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00080.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00081.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | int 4 | main() 5 | { 6 | long long x; 7 | 8 | x = 0; 9 | x = x + 1; 10 | if (x != 1) 11 | return 1; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00081.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00081.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00082.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | int 4 | main() 5 | { 6 | unsigned long long x; 7 | 8 | x = 0; 9 | x = x + 1; 10 | if (x != 1) 11 | return 1; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00082.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00082.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00083.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00083.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00084.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00084.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00085.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00085.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00086.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | short x; 5 | 6 | x = 0; 7 | x = x + 1; 8 | if (x != 1) 9 | return 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00086.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00086.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00087.c: -------------------------------------------------------------------------------- 1 | struct S 2 | { 3 | int (*fptr)(); 4 | }; 5 | 6 | int 7 | foo() 8 | { 9 | return 0; 10 | } 11 | 12 | int 13 | main() 14 | { 15 | struct S v; 16 | 17 | v.fptr = foo; 18 | return v.fptr(); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00087.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00087.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00088.c: -------------------------------------------------------------------------------- 1 | int (*fptr)() = 0; 2 | 3 | 4 | int 5 | main() 6 | { 7 | if (fptr) 8 | return 1; 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00088.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00088.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00089.c: -------------------------------------------------------------------------------- 1 | int 2 | zero() 3 | { 4 | return 0; 5 | } 6 | 7 | struct S 8 | { 9 | int (*zerofunc)(); 10 | } s = { &zero }; 11 | 12 | struct S * 13 | anon() 14 | { 15 | return &s; 16 | } 17 | 18 | typedef struct S * (*fty)(); 19 | 20 | fty 21 | go() 22 | { 23 | return &anon; 24 | } 25 | 26 | int 27 | main() 28 | { 29 | return go()()->zerofunc(); 30 | } 31 | -------------------------------------------------------------------------------- /tests/c-testsuite/00089.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00089.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00090.c: -------------------------------------------------------------------------------- 1 | int a[3] = {0, 1, 2}; 2 | 3 | int 4 | main() 5 | { 6 | if (a[0] != 0) 7 | return 1; 8 | if (a[1] != 1) 9 | return 2; 10 | if (a[2] != 2) 11 | return 3; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00090.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00090.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00091.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int v; 3 | int sub[2]; 4 | } S; 5 | 6 | S a[1] = {{1, {2, 3}}}; 7 | 8 | int 9 | main() 10 | { 11 | if (a[0].v != 1) 12 | return 1; 13 | if (a[0].sub[0] != 2) 14 | return 2; 15 | if (a[0].sub[1] != 3) 16 | return 3; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/c-testsuite/00091.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00091.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00092.c: -------------------------------------------------------------------------------- 1 | int a[] = {5, [2] = 2, 3}; 2 | 3 | int 4 | main() 5 | { 6 | if (sizeof(a) != 4*sizeof(int)) 7 | return 1; 8 | 9 | if (a[0] != 5) 10 | return 2; 11 | if (a[1] != 0) 12 | return 3; 13 | if (a[2] != 2) 14 | return 4; 15 | if (a[3] != 3) 16 | return 5; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/c-testsuite/00092.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00092.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00093.c: -------------------------------------------------------------------------------- 1 | int a[] = {1, 2, 3, 4}; 2 | 3 | int 4 | main() 5 | { 6 | if (sizeof(a) != 4*sizeof(int)) 7 | return 1; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00093.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00093.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00094.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | 3 | int main() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00094.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00094.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00095.c: -------------------------------------------------------------------------------- 1 | int x; 2 | int x = 3; 3 | int x; 4 | 5 | int main(); 6 | 7 | void * 8 | foo() 9 | { 10 | return &main; 11 | } 12 | 13 | int 14 | main() 15 | { 16 | if (x != 3) 17 | return 0; 18 | 19 | x = 0; 20 | return x; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/c-testsuite/00095.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00095.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00096.c: -------------------------------------------------------------------------------- 1 | int x, x = 3, x; 2 | 3 | int 4 | main() 5 | { 6 | if (x != 3) 7 | return 0; 8 | 9 | x = 0; 10 | return x; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00096.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00096.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00097.c: -------------------------------------------------------------------------------- 1 | #define NULL ((void*)0) 2 | #define NULL ((void*)0) 3 | 4 | #define FOO(X, Y) (X + Y + Z) 5 | #define FOO(X, Y) (X + Y + Z) 6 | 7 | #define BAR(X, Y, ...) (X + Y + Z) 8 | #define BAR(X, Y, ...) (X + Y + Z) 9 | 10 | int 11 | main() 12 | { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00097.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00097.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00098.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return L'\0'; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00098.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00098.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00099.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { int n; } Vec; 3 | 4 | static void 5 | vecresize(Vec *v, int cap) 6 | { 7 | return; 8 | } 9 | 10 | int main() 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00099.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00099.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00100.c: -------------------------------------------------------------------------------- 1 | int 2 | foo(void) 3 | { 4 | return 0; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return foo(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00100.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00100.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00101.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int c; 5 | c = 0; 6 | do 7 | ; 8 | while (0); 9 | return c; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00101.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00101.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00102.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 1; 7 | if ((x << 1) != 2) 8 | return 1; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00102.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00102.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00103.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | void *foo; 6 | void **bar; 7 | 8 | x = 0; 9 | 10 | foo = (void*)&x; 11 | bar = &foo; 12 | 13 | return **(int**)bar; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00103.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00103.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00104.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | #include 4 | 5 | int 6 | main() 7 | { 8 | int32_t x; 9 | int64_t l; 10 | 11 | x = 0; 12 | l = 0; 13 | 14 | x = ~x; 15 | if (x != 0xffffffff) 16 | return 1; 17 | 18 | l = ~l; 19 | if (x != 0xffffffffffffffff) 20 | return 2; 21 | 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/c-testsuite/00104.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00104.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00105.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int i; 5 | 6 | for(i = 0; i < 10; i++) 7 | if (!i) 8 | continue; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00105.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00105.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00106.c: -------------------------------------------------------------------------------- 1 | struct S1 { int x; }; 2 | struct S2 { struct S1 s1; }; 3 | 4 | int 5 | main() 6 | { 7 | struct S2 s2; 8 | s2.s1.x = 1; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00106.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00106.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00107.c: -------------------------------------------------------------------------------- 1 | typedef int myint; 2 | myint x = (myint)1; 3 | 4 | int 5 | main(void) 6 | { 7 | return x-1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00107.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00107.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00108.c: -------------------------------------------------------------------------------- 1 | int foo(void); 2 | int foo(void); 3 | #define FOO 0 4 | 5 | int 6 | main() 7 | { 8 | return FOO; 9 | } 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00108.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00108.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00109.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x = 0; 5 | int y = 1; 6 | if(x ? 1 : 0) 7 | return 1; 8 | if(y ? 0 : 1) 9 | return 2; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00109.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00109.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00110.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | int x; 3 | 4 | int 5 | main() 6 | { 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00110.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00110.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00111.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | short s = 1; 5 | long l = 1; 6 | 7 | s -= l; 8 | return s; 9 | } 10 | -------------------------------------------------------------------------------- /tests/c-testsuite/00111.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00111.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00112.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return "abc" == (void *)0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00112.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00112.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00113.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int a = 0; 5 | float f = a + 1; 6 | 7 | return f == a; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00113.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00113.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00114.c: -------------------------------------------------------------------------------- 1 | int main(void); 2 | 3 | int 4 | main() 5 | { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00114.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00114.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00115.c: -------------------------------------------------------------------------------- 1 | #define B "b" 2 | 3 | char s[] = "a" B "c"; 4 | 5 | int 6 | main() 7 | { 8 | if (s[0] != 'a') 9 | return 1; 10 | if (s[1] != 'b') 11 | return 2; 12 | if (s[2] != 'c') 13 | return 3; 14 | if (s[3] != '\0') 15 | return 4; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00115.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00115.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00116.c: -------------------------------------------------------------------------------- 1 | int 2 | f(int f) 3 | { 4 | return f; 5 | } 6 | 7 | int 8 | main() 9 | { 10 | return f(0); 11 | } 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00116.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00116.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00117.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int x[] = { 1, 0 }; 4 | return x[1]; 5 | } 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00117.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00117.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00118.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | struct { int x; } s = { 0 }; 5 | return s.x; 6 | } 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00118.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00118.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00119.c: -------------------------------------------------------------------------------- 1 | double x = 100; 2 | 3 | int 4 | main() 5 | { 6 | return x < 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00119.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00119.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00120.c: -------------------------------------------------------------------------------- 1 | struct { 2 | enum { X } x; 3 | } s; 4 | 5 | 6 | int 7 | main() 8 | { 9 | return X; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00120.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00120.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00121.c: -------------------------------------------------------------------------------- 1 | int f(int a), g(int a), a; 2 | 3 | 4 | int 5 | main() 6 | { 7 | return f(1) - g(1); 8 | } 9 | 10 | int 11 | f(int a) 12 | { 13 | return a; 14 | } 15 | 16 | int 17 | g(int a) 18 | { 19 | return a; 20 | } 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00121.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00121.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00122.c: -------------------------------------------------------------------------------- 1 | #define F(a, b) a 2 | int 3 | main() 4 | { 5 | return F(, 1) 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00122.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00122.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00123.c: -------------------------------------------------------------------------------- 1 | double x = 100.0; 2 | 3 | int 4 | main() 5 | { 6 | return x < 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00123.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00123.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00124.c: -------------------------------------------------------------------------------- 1 | int 2 | f2(int c, int b) 3 | { 4 | return c - b; 5 | } 6 | 7 | int (* 8 | f1(int a, int b))(int c, int b) 9 | { 10 | if (a != b) 11 | return f2; 12 | return 0; 13 | } 14 | 15 | int 16 | main() 17 | { 18 | int (* (*p)(int a, int b))(int c, int d) = f1; 19 | 20 | 21 | return (*(*p)(0, 2))(2, 2); 22 | } 23 | -------------------------------------------------------------------------------- /tests/c-testsuite/00124.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00124.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00125.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | printf("hello world\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00125.c.expected: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00126.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | int x; 5 | 6 | x = 3; 7 | x = !x; 8 | x = !x; 9 | x = ~x; 10 | x = -x; 11 | if(x != 2) 12 | return 1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00126.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00126.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00127.c: -------------------------------------------------------------------------------- 1 | int c; 2 | 3 | int 4 | main() 5 | { 6 | if(0) { 7 | return 1; 8 | } else if(0) { 9 | } else { 10 | if(1) { 11 | if(c) 12 | return 1; 13 | else 14 | return 0; 15 | } else { 16 | return 1; 17 | } 18 | } 19 | return 1; 20 | } 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00127.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00127.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00128.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00128.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00129.c: -------------------------------------------------------------------------------- 1 | typedef struct s s; 2 | 3 | struct s { 4 | struct s1 { 5 | int s; 6 | struct s2 { 7 | int s; 8 | } s1; 9 | } s; 10 | } s2; 11 | 12 | #define s s 13 | 14 | int 15 | main(void) 16 | { 17 | #undef s 18 | goto s; 19 | struct s s; 20 | { 21 | int s; 22 | return s; 23 | } 24 | return s.s.s + s.s.s1.s; 25 | s: 26 | { 27 | return 0; 28 | } 29 | return 1; 30 | } 31 | -------------------------------------------------------------------------------- /tests/c-testsuite/00129.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00129.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00130.c: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | char arr[2][4], (*p)[4], *q; 5 | int v[4]; 6 | 7 | p = arr; 8 | q = &arr[1][3]; 9 | arr[1][3] = 2; 10 | v[0] = 2; 11 | 12 | if (arr[1][3] != 2) 13 | return 1; 14 | if (p[1][3] != 2) 15 | return 1; 16 | if (*q != 2) 17 | return 1; 18 | if (*v != 2) 19 | return 1; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/c-testsuite/00130.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00130.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00131.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/c-testsuite/00131.c.expected: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00132.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00133.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | int main(void) 4 | { 5 | int i; 6 | unsigned u; 7 | 8 | i = 1; 9 | i = -1; 10 | i = -1l; 11 | i = -1u; 12 | i = -1ll; 13 | i = 32766 + 1 & 3; 14 | i = (int) 32768 < 0; 15 | i = -1u < 0; 16 | 17 | u = 1; 18 | u = -1; 19 | u = -1l; 20 | u = -1u; 21 | u = -1ll; 22 | u = (unsigned) 32768 < 0; 23 | u = 32766 + 1 & 3; 24 | u = -1u < 0; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/c-testsuite/00133.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00133.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00134.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00134.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00135.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | int 4 | main(void) 5 | { 6 | long long i; 7 | unsigned long long u; 8 | 9 | i = 1; 10 | i = -1; 11 | i = -1l; 12 | i = -1u; 13 | i = -1ll; 14 | i = -1ll & 3; 15 | i = -1ll < 0; 16 | 17 | u = 1; 18 | u = -1; 19 | u = -1l; 20 | u = -1u; 21 | u = -1ll; 22 | u = -1llu & 3; 23 | u = -1llu < 0; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/c-testsuite/00135.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00135.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00136.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00136.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00137.c: -------------------------------------------------------------------------------- 1 | #define x(y) #y 2 | 3 | int 4 | main(void) 5 | { 6 | char *p; 7 | p = x(hello) " is better than bye"; 8 | 9 | return (*p == 'h') ? 0 : 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00137.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00137.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00138.c: -------------------------------------------------------------------------------- 1 | #define M(x) x 2 | #define A(a,b) a(b) 3 | 4 | int 5 | main(void) 6 | { 7 | char *a = A(M,"hi"); 8 | 9 | return (a[1] == 'i') ? 0 : 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00138.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00138.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00139.c: -------------------------------------------------------------------------------- 1 | /* 2 | * f(2) will expand to 2*g, which will expand to 2*f, and in this 3 | * moment f will not be expanded because the macro definition is 4 | * a function alike macro, and in this case there is no arguments. 5 | */ 6 | #define f(a) a*g 7 | #define g f 8 | 9 | int 10 | main(void) 11 | { 12 | int f = 0; 13 | 14 | return f(2); 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00139.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00139.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00140.c: -------------------------------------------------------------------------------- 1 | struct foo { 2 | int i, j, k; 3 | char *p; 4 | float v; 5 | }; 6 | 7 | int 8 | f1(struct foo f, struct foo *p, int n, ...) 9 | { 10 | if (f.i != p->i) 11 | return 0; 12 | return p->j + n; 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | struct foo f; 19 | 20 | f.i = f.j = 1; 21 | f1(f, &f, 2); 22 | f1(f, &f, 2, 1, f, &f); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/c-testsuite/00140.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00140.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00141.c: -------------------------------------------------------------------------------- 1 | #define CAT(x,y) x ## y 2 | #define XCAT(x,y) CAT(x,y) 3 | #define FOO foo 4 | #define BAR bar 5 | 6 | int 7 | main(void) 8 | { 9 | int foo, bar, foobar; 10 | 11 | CAT(foo,bar) = foo + bar; 12 | XCAT(FOO,BAR) = foo + bar; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/c-testsuite/00141.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00141.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00142.c: -------------------------------------------------------------------------------- 1 | #if defined(FOO) 2 | int a; 3 | #elif !defined(FOO) && defined(BAR) 4 | int b; 5 | #elif !defined(FOO) && !defined(BAR) 6 | int c; 7 | #else 8 | int d; 9 | #endif 10 | 11 | int 12 | main(void) 13 | { 14 | return c; 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00142.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00142.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00143.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00143.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00144.c: -------------------------------------------------------------------------------- 1 | int 2 | main(void) 3 | { 4 | int i, *q; 5 | void *p; 6 | 7 | i = i ? 0 : 0l; 8 | p = i ? (void *) 0 : 0; 9 | p = i ? 0 : (void *) 0; 10 | p = i ? 0 : (const void *) 0; 11 | q = i ? 0 : p; 12 | q = i ? p : 0; 13 | q = i ? q : 0; 14 | q = i ? 0 : q; 15 | 16 | return (int) q; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00144.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00144.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00145.c: -------------------------------------------------------------------------------- 1 | #if 0 != (0 && (0/0)) 2 | #error 0 != (0 && (0/0)) 3 | #endif 4 | 5 | #if 1 != (-1 || (0/0)) 6 | #error 1 != (-1 || (0/0)) 7 | #endif 8 | 9 | #if 3 != (-1 ? 3 : (0/0)) 10 | #error 3 != (-1 ? 3 : (0/0)) 11 | #endif 12 | 13 | int 14 | main() 15 | { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00145.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00145.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00146.c: -------------------------------------------------------------------------------- 1 | struct S { int a; int b; }; 2 | struct S s = {1, 2}; 3 | 4 | int 5 | main() 6 | { 7 | if(s.a != 1) 8 | return 1; 9 | if(s.b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00146.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00146.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00147.c: -------------------------------------------------------------------------------- 1 | int arr[3] = {[2] = 2, [0] = 0, [1] = 1}; 2 | 3 | int 4 | main() 5 | { 6 | if(arr[0] != 0) 7 | return 1; 8 | if(arr[1] != 1) 9 | return 2; 10 | if(arr[2] != 2) 11 | return 3; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00147.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00147.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00148.c: -------------------------------------------------------------------------------- 1 | struct S {int a; int b;}; 2 | struct S arr[2] = {[1] = {3, 4}, [0] = {1, 2}}; 3 | 4 | int 5 | main() 6 | { 7 | if(arr[0].a != 1) 8 | return 1; 9 | if(arr[0].b != 2) 10 | return 2; 11 | if(arr[1].a != 3) 12 | return 3; 13 | if(arr[1].b != 4) 14 | return 4; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00148.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00148.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00149.c: -------------------------------------------------------------------------------- 1 | struct S { int a; int b; }; 2 | struct S *s = &(struct S) { 1, 2 }; 3 | 4 | int 5 | main() 6 | { 7 | if(s->a != 1) 8 | return 1; 9 | if(s->b != 2) 10 | return 2; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/c-testsuite/00149.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00149.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00150.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00150.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00151.c: -------------------------------------------------------------------------------- 1 | int arr[][3][5] = { 2 | { 3 | { 0, 0, 3, 5 }, 4 | { 1, [3] = 6, 7 }, 5 | }, 6 | { 7 | { 1, 2 }, 8 | { [4] = 7, }, 9 | }, 10 | }; 11 | 12 | int 13 | main(void) 14 | { 15 | return !(arr[0][1][4] == arr[1][1][4]); 16 | } 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00151.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00151.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00152.c: -------------------------------------------------------------------------------- 1 | #undef line 2 | #define line 1000 3 | 4 | int a = __LINE__; 5 | #line line 6 | int a = __LINE__; 7 | #if 1000 != __LINE__ 8 | // #error " # line line" not work as expected 9 | #endif 10 | 11 | int 12 | main() 13 | { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00152.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00152.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00153.c: -------------------------------------------------------------------------------- 1 | #define x f 2 | #define y() f 3 | 4 | typedef struct { int f; } S; 5 | 6 | int 7 | main() 8 | { 9 | S s; 10 | 11 | s.x = 0; 12 | return s.y(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00153.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00153.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00154.c.expected: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00155.c: -------------------------------------------------------------------------------- 1 | 2 | int 3 | main(void) 4 | { 5 | sizeof((int) 1); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00155.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00155.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00156.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/c-testsuite/00156.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00157.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/c-testsuite/00157.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00158.c.expected: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00159.c.expected: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00160.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/c-testsuite/00160.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00161.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/c-testsuite/00161.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tests/c-testsuite/00162.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00162.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00163.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00164.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00165.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/c-testsuite/00165.c.expected: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00166.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 | 10 | printf("%d\n", a); 11 | printf("%d\n", b); 12 | printf("%d\n", c); 13 | printf("%d\n", d); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tests/c-testsuite/00166.c.expected: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00167.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/c-testsuite/00167.c.expected: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00168.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/c-testsuite/00168.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00169.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/c-testsuite/00169.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00170.c.expected: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | enum to int: 1 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00171.c.expected: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /tests/c-testsuite/00172.c.expected: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00173.c.expected: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /tests/c-testsuite/00174.c.expected: -------------------------------------------------------------------------------- 1 | 69.120003 2 | 69.120000 3 | -44.440000 4 | 700.665200 5 | 0.217330 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.120003 10 | -44.439999 11 | 700.665222 12 | 0.217330 13 | 12.340000 14 | -12.340000 15 | 2.000000 16 | 0.909297 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00175.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00176.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00177.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/c-testsuite/00177.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @ 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00178.c: -------------------------------------------------------------------------------- 1 | // flags: --no-warnings 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | char a; 8 | int b; 9 | double c; 10 | 11 | printf("%d\n", sizeof(a)); 12 | printf("%d\n", sizeof(b)); 13 | printf("%d\n", sizeof(c)); 14 | 15 | printf("%d\n", sizeof(!a)); 16 | 17 | return 0; 18 | } 19 | 20 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00178.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | 4 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00179.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00180.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/c-testsuite/00180.c.expected: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00182.c.expected: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00183.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 10; Count++) 8 | { 9 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tests/c-testsuite/00183.c.expected: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00184.c: -------------------------------------------------------------------------------- 1 | // flags: --no-warnings 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | char a; 8 | short b; 9 | 10 | printf("%d %d\n", sizeof(char), sizeof(a)); 11 | printf("%d %d\n", sizeof(short), sizeof(b)); 12 | 13 | return 0; 14 | } 15 | 16 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00184.c.expected: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00185.c.expected: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /tests/c-testsuite/00186.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/c-testsuite/00186.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00188.c.expected: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00189.c.expected: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00190.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/c-testsuite/00190.c.expected: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00191.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/c-testsuite/00191.c.expected: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00192.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/c-testsuite/00192.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tests/c-testsuite/00193.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/c-testsuite/00193.c.expected: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /tests/c-testsuite/00194.c.expected: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00195.c.expected: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00196.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00197.c.expected: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00198.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00199.c.expected: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /tests/c-testsuite/00200.c.expected: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00201.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/c-testsuite/00201.c.expected: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00202.c: -------------------------------------------------------------------------------- 1 | // skip: not yet implemented - preprocessor concat punctuators 2 | 3 | #include 4 | 5 | #define P(A,B) A ## B ; bob 6 | #define Q(A,B) A ## B+ 7 | 8 | int main(void) 9 | { 10 | int bob, jim = 21; 11 | bob = P(jim,) *= 2; 12 | printf("jim: %d, bob: %d\n", jim, bob); 13 | jim = 60 Q(+,)3; 14 | printf("jim: %d\n", jim); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/c-testsuite/00202.c.expected: -------------------------------------------------------------------------------- 1 | jim: 21, bob: 42 2 | jim: 63 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00203.c.expected: -------------------------------------------------------------------------------- 1 | long long constant test ok. 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00206.c.expected: -------------------------------------------------------------------------------- 1 | abort = 111 2 | abort = 222 3 | abort = 333 4 | abort = 222 5 | abort = 111 6 | -------------------------------------------------------------------------------- /tests/c-testsuite/00207.c.expected: -------------------------------------------------------------------------------- 1 | boom! 2 | boom! 3 | 11 4 | 12 5 | 0 6 | 1 7 | -------------------------------------------------------------------------------- /tests/c-testsuite/00208.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00208.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00209.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00209.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00210.c.expected: -------------------------------------------------------------------------------- 1 | 42 2 | 42 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00211.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/c-testsuite/00211.c.expected: -------------------------------------------------------------------------------- 1 | n+1 = 15 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00212.c.expected: -------------------------------------------------------------------------------- 1 | Ok 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00213.c.expected: -------------------------------------------------------------------------------- 1 | timeout=2 2 | timeout=1 3 | boo 4 | yeah 5 | twice 6 | once 7 | twice 8 | SEtwice 9 | SEonce 10 | SEtwice 11 | twice2 12 | once2 13 | twice2 14 | twice3 15 | once3 16 | twice3 17 | caseok 18 | caseok2 19 | g=1 20 | check 1 21 | g=2 22 | check 2 23 | g=3 24 | -------------------------------------------------------------------------------- /tests/c-testsuite/00214.c.expected: -------------------------------------------------------------------------------- 1 | okay 2 | okay 3 | -------------------------------------------------------------------------------- /tests/c-testsuite/00215.c.expected: -------------------------------------------------------------------------------- 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/c-testsuite/00217.c: -------------------------------------------------------------------------------- 1 | // arch-skip: rv32i 2 | 3 | int printf(const char *, ...); 4 | char t[] = "012345678"; 5 | 6 | int main(void) 7 | { 8 | char *data = t; 9 | unsigned long long r = 4; 10 | unsigned a = 5; 11 | unsigned long long b = 12; 12 | 13 | *(unsigned*)(data + r) += a - b; 14 | 15 | printf("data = \"%s\"\n", data); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/c-testsuite/00217.c.expected: -------------------------------------------------------------------------------- 1 | data = "0123-5678" 2 | -------------------------------------------------------------------------------- /tests/c-testsuite/00218.c.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/c-testsuite/00218.c.expected -------------------------------------------------------------------------------- /tests/c-testsuite/00219.c.expected: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /tests/c-testsuite/00220.c: -------------------------------------------------------------------------------- 1 | 2 | // this file contains BMP chars encoded in UTF-8 3 | #include 4 | // #include 5 | 6 | int main() 7 | { 8 | int s[] = L"hello$$你好¢¢世界€€world"; 9 | int *p; 10 | for (p = s; *p; p++) printf("%04X ", (unsigned) *p); 11 | printf("\n"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/c-testsuite/00220.c.expected: -------------------------------------------------------------------------------- 1 | 0068 0065 006C 006C 006F 0024 0024 4F60 597D 00A2 00A2 4E16 754C 20AC 20AC 0077 006F 0072 006C 0064 2 | -------------------------------------------------------------------------------- /tests/c_exit_call.c: -------------------------------------------------------------------------------- 1 | // expected value: 17 2 | 3 | void exit(int code); 4 | 5 | int main() { exit(17); } 6 | -------------------------------------------------------------------------------- /tests/call_multi_func.c: -------------------------------------------------------------------------------- 1 | // expected value: 20 2 | 3 | int idouble(int a) { return a * 2; } 4 | 5 | int add(int a, int b) { return a + b; } 6 | 7 | int main() { return add(idouble(7), 6); } 8 | -------------------------------------------------------------------------------- /tests/cast.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | int main() { 4 | int a = (int)1; 5 | long b = (long)a; 6 | return (char)b; 7 | } 8 | -------------------------------------------------------------------------------- /tests/char_literals.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: -`A 3 | 4 | int printf(const char *, ...); 5 | 6 | int main() { 7 | char c = '\055'; 8 | char d = '\u0060'; 9 | char e = '\x41'; 10 | 11 | printf("%c%c%c\n", c, d, e); 12 | } 13 | -------------------------------------------------------------------------------- /tests/cmp_zero.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdin: 10 3 | 4 | int scanf(const char *format, ...); 5 | 6 | int main() { 7 | int a; 8 | scanf("%d", &a); 9 | 10 | if (a == 0) { 11 | return 1; 12 | } else { 13 | return 0; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compound_assg.c: -------------------------------------------------------------------------------- 1 | // expected value: 2 2 | 3 | int main() { 4 | int a = 0; 5 | a += 15; 6 | a *= 4; 7 | a /= 4; 8 | a %= 10; 9 | a ^= 38459; 10 | a &= 256; 11 | a |= 3; 12 | a >>= 1; 13 | a <<= 1; 14 | return a; 15 | } 16 | -------------------------------------------------------------------------------- /tests/compound_expr_stmt.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int printf(const char *, ...); 4 | 5 | int main() { 6 | return ({ 7 | printf("Hello!\n"); 8 | 0; 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /tests/cross_func_vars.c: -------------------------------------------------------------------------------- 1 | // expected value: 3 2 | 3 | void bar() {} 4 | 5 | int main() { 6 | int a = 1; 7 | int b = 2; 8 | 9 | bar(); 10 | 11 | return a + b; 12 | } 13 | -------------------------------------------------------------------------------- /tests/decl.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | int main() { 3 | int a = 1; 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /tests/decl_shadow.c: -------------------------------------------------------------------------------- 1 | // expected value: 4 2 | int main() { 3 | int a = 1; 4 | unsigned b = 7; 5 | { 6 | int a = 2; 7 | b = 3; 8 | } 9 | 10 | return a + b; 11 | } 12 | -------------------------------------------------------------------------------- /tests/defer.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: "dog says woof woof bark!" 3 | // std: c2y 4 | 5 | #include 6 | 7 | int main () { 8 | const char* s = "this is not going to appear because it's going to be reassigned"; 9 | defer printf(" bark!\""); 10 | defer printf("%s", s); 11 | defer { 12 | defer printf(" woof"); 13 | printf(" says"); 14 | } 15 | printf("\"dog"); 16 | s = " woof"; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/define.c: -------------------------------------------------------------------------------- 1 | // expected value: 7 2 | 3 | #define FOO \ 4 | 4 5 | 6 | #define BAR 7 | 8 | #define buzz 10 9 | #undef buzz 10 | 11 | #ifdef FIZZ 12 | #define buzz 0 13 | invalid stuff 14 | #else 15 | #define BAT 16 | #endif 17 | 18 | #define A 0 19 | #define VAL A 20 | #define A 3 21 | 22 | int main() { 23 | int buzz = 1; 24 | return FOO BAR BAT + VAL; 25 | } 26 | -------------------------------------------------------------------------------- /tests/deref.c: -------------------------------------------------------------------------------- 1 | // expected value: 20 2 | 3 | int main() { 4 | int a; 5 | int *p = &a; 6 | *p = 10; 7 | return *p + a; 8 | } 9 | -------------------------------------------------------------------------------- /tests/do_while.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | int main() { 4 | int a = 10; 5 | int b = 0; 6 | 7 | do { 8 | do { 9 | a = a - 1; 10 | b = b + 1; 11 | } while (0); 12 | } while (a); 13 | 14 | return b; 15 | } 16 | -------------------------------------------------------------------------------- /tests/eep/mov_add_sub.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | int main() { 3 | int a = 1; 4 | int b = 2; 5 | 6 | int c = a + b; 7 | int d = a - b; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/eep/mul.c: -------------------------------------------------------------------------------- 1 | // expected value: 35 2 | int main() { 3 | unsigned int op1, op2, op2_shifted, sum; 4 | 5 | op1 = 5; 6 | op2 = 7; 7 | 8 | sum = 0; 9 | op2_shifted = op2; 10 | 11 | // while (op1 != 0) { 12 | while (op1) { 13 | if (op1 & 1) { 14 | sum = sum + op2_shifted; 15 | } 16 | op2_shifted = op2_shifted << 1; 17 | op1 = op1 >> 1; 18 | } 19 | 20 | return sum; 21 | } 22 | -------------------------------------------------------------------------------- /tests/eep/mul_instr.c: -------------------------------------------------------------------------------- 1 | // expected value: 35 2 | int main() { 3 | int a = 7; 4 | int b = 5; 5 | 6 | int c = a * b; 7 | 8 | return c; 9 | } 10 | -------------------------------------------------------------------------------- /tests/empty.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-h-k/jcc/633ee66b027270444ec30638d28dbf5511efa7c1/tests/empty.bin -------------------------------------------------------------------------------- /tests/empty.c: -------------------------------------------------------------------------------- 1 | // expected value: 88 2 | 3 | int main() { 4 | return 88; 5 | } 6 | -------------------------------------------------------------------------------- /tests/enum.c: -------------------------------------------------------------------------------- 1 | // expected value: 6 2 | 3 | enum foo { ZERO, ONE, TWO, THREE }; 4 | 5 | enum bar { B_TWO = TWO, B_ONE = ONE }; 6 | 7 | int main() { return THREE + B_TWO + B_ONE ; } 8 | -------------------------------------------------------------------------------- /tests/eq.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | int main() { 3 | int a = 1; 4 | int b = 2; 5 | 6 | if (a == b) { 7 | return 1; 8 | } else { 9 | return 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/eq_var.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | int main() { 3 | int a = 2; 4 | int b = 2; 5 | 6 | int result = a == b; 7 | return result; 8 | } 9 | -------------------------------------------------------------------------------- /tests/escape_string.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: " 3 | 4 | int puts(const char *s); 5 | 6 | int main() { 7 | const char *foo = "\""; 8 | 9 | puts(foo); 10 | } 11 | -------------------------------------------------------------------------------- /tests/explicit_enum.c: -------------------------------------------------------------------------------- 1 | // expected value: 45 2 | 3 | enum foo { FOUR = 4, FIVE, TWO = 2, THREE }; 4 | 5 | int main() { return (FOUR + FIVE) * (TWO + THREE); } 6 | -------------------------------------------------------------------------------- /tests/extern_incomplete.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // flags-darwin: -Wl,-U,_foo 3 | // flags-linux: -Wl,--unresolved-symbols=ignore-all 4 | 5 | struct c; 6 | 7 | __attribute__((weak)) 8 | extern struct c foo; 9 | 10 | int main() { 11 | return (int)(long)&foo; 12 | } 13 | -------------------------------------------------------------------------------- /tests/fallthrough.c: -------------------------------------------------------------------------------- 1 | // expected value: 5 2 | 3 | int main() { 4 | int x = 0; 5 | 6 | switch (x) { 7 | case 0: 8 | x++; 9 | case 1: 10 | x++; 11 | case 2: 12 | x++; 13 | case 3: 14 | x++; 15 | case 4: 16 | x++; 17 | break; 18 | case 5: 19 | x = 0; 20 | } 21 | 22 | return x; 23 | } 24 | -------------------------------------------------------------------------------- /tests/fancy_pointer.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | int main() { 4 | int a[4]; 5 | int *p = a; 6 | 7 | *p = 1; 8 | *(p + 0) = 1; 9 | *(p + 1) = 2; 10 | *(p + 2) = 3; 11 | *(p + 3) = (p + 4) - (p); 12 | 13 | return p[0] + p[1] + p[2] + p[3]; 14 | } 15 | -------------------------------------------------------------------------------- /tests/float.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | // stdout: 1.400000 1.400000 -1.400000 -1.400000 3 | 4 | int printf(const char *format, ...); 5 | 6 | int main() { 7 | double a = 1.4; 8 | 9 | printf("%f %f %f %f\n", a, 1.4, -a, -1.4); 10 | return 10; 11 | } 12 | -------------------------------------------------------------------------------- /tests/float_if.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | int main() { 4 | int a, b; 5 | float c = 1, d = 0; 6 | 7 | if (c) { 8 | a = 1; 9 | } else { 10 | a = 0; 11 | } 12 | 13 | if (d) { 14 | b = 1; 15 | } else { 16 | b = 0; 17 | } 18 | 19 | return a + (b << 1); 20 | } 21 | -------------------------------------------------------------------------------- /tests/flow.c: -------------------------------------------------------------------------------- 1 | // expected value: 25 2 | 3 | int main() { 4 | 5 | int i = 0; 6 | while (1) { 7 | if (i == 10) { 8 | break; 9 | } 10 | 11 | i++; 12 | } 13 | 14 | int j = 0; 15 | while (1) { 16 | if (j != 15) { 17 | j++; 18 | continue; 19 | } 20 | 21 | break; 22 | } 23 | 24 | return i + j; 25 | } 26 | -------------------------------------------------------------------------------- /tests/for.c: -------------------------------------------------------------------------------- 1 | // expected value: 40 2 | int main() { 3 | int a = 0; 4 | int c = 0; 5 | 6 | for (int b = 10; b; b = b - 1) { 7 | a = a + 2; 8 | } 9 | 10 | int d = 0; 11 | for (d = 10; d; d = d - 1) { 12 | a = a + 2; 13 | } 14 | 15 | return a + c; 16 | } 17 | -------------------------------------------------------------------------------- /tests/func.c: -------------------------------------------------------------------------------- 1 | // expected value: 25 2 | 3 | int hypot2(int a, int b) { 4 | return (a * a) + (b * b); 5 | } 6 | 7 | int main() { return hypot2(3, 4); } 8 | -------------------------------------------------------------------------------- /tests/func_pointer.c: -------------------------------------------------------------------------------- 1 | // expected value: 3 2 | 3 | int val; 4 | int inc() { return val++; } 5 | 6 | int main() { 7 | int (*a)() = inc; 8 | int (*b)() = &inc; 9 | 10 | return a() + b() + val; 11 | } 12 | -------------------------------------------------------------------------------- /tests/func_var.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: foomain 3 | 4 | int printf(const char *, ...); 5 | 6 | void foo() { 7 | printf("%s", __func__); 8 | } 9 | 10 | int main() { 11 | foo(); 12 | printf("%s\n", __func__); 13 | } 14 | -------------------------------------------------------------------------------- /tests/half.c: -------------------------------------------------------------------------------- 1 | // arch: aarch64 2 | // expected value: 3 3 | 4 | int main() { 5 | _Float16 a = 0; 6 | _Float16 b = 2; 7 | 8 | __fp16 c = 1; 9 | __fp16 d = 3; 10 | 11 | _Float16 *p = &a; 12 | *p = 1; 13 | 14 | return ((a + b) + (c * d)) / 2; 15 | } 16 | -------------------------------------------------------------------------------- /tests/hello_world.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: Hello, World! 3 | 4 | #include 5 | 6 | int main() { 7 | printf("Hello, World!\n"); 8 | } 9 | -------------------------------------------------------------------------------- /tests/if.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | int main() { 3 | if (1) { 4 | return 10; 5 | } 6 | 7 | return 5; 8 | } 9 | -------------------------------------------------------------------------------- /tests/if_assign.c: -------------------------------------------------------------------------------- 1 | // expected value: 20 2 | int main() { 3 | int a = 5; 4 | 5 | if (1) { 6 | a = 10; 7 | } 8 | 9 | int b = a + a; 10 | return b; 11 | } 12 | -------------------------------------------------------------------------------- /tests/if_else.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | int main() { 3 | if (1) { 4 | return 10; 5 | } else { 6 | return 5; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/if_else_assign.c: -------------------------------------------------------------------------------- 1 | // expected value: 11 2 | int main() { 3 | int a; 4 | 5 | if (50) { 6 | a = 10; 7 | } else { 8 | a = 20; 9 | } 10 | 11 | int b; 12 | 13 | if (0) { 14 | b = 5; 15 | } else { 16 | b = 1; 17 | } 18 | 19 | return a + b; 20 | } 21 | -------------------------------------------------------------------------------- /tests/if_else_vars.c: -------------------------------------------------------------------------------- 1 | // expected value: 60 2 | int main() { 3 | int question = 1; 4 | int answer; 5 | 6 | question = 1; 7 | 8 | if (question) { 9 | answer = 60; 10 | } else { 11 | answer = 100; 12 | } 13 | 14 | return answer; 15 | } 16 | -------------------------------------------------------------------------------- /tests/implicit_addr.c: -------------------------------------------------------------------------------- 1 | // expected value: 100 2 | 3 | int foo(int a) { 4 | return a; 5 | } 6 | 7 | int bar(int (*f)(int), int idx, int arr[1]) { 8 | return f(arr[idx]); 9 | } 10 | 11 | int main() { 12 | int arr[] = { 100 }; 13 | return bar(foo, 0, arr); 14 | } 15 | -------------------------------------------------------------------------------- /tests/inc.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | int foo(int a) { 4 | return a; 5 | } 6 | 7 | int main() { 8 | int a = 0; 9 | int b = a++; 10 | 11 | int c = 0; 12 | int d = ++c; 13 | 14 | int e = 0; 15 | int f = foo(e++); 16 | 17 | if (e != 1) { 18 | return 2; 19 | } 20 | 21 | if (f != 0) { 22 | return 3; 23 | } 24 | 25 | return a == 1 && b == 0 && c == 1 && d == 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/inc_pointer.c: -------------------------------------------------------------------------------- 1 | // expected value: 12 2 | 3 | int main() { 4 | int a[2] = { 0 }; 5 | 6 | int *p = &a[0]; 7 | *p++ = 5; 8 | *p++ = 7; 9 | 10 | return a[0] + a[1]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/include.c: -------------------------------------------------------------------------------- 1 | // expected value: 66 2 | 3 | #ifndef FOO 4 | #define FOO 5 | #include "include.c" 6 | 7 | int main() { 8 | return foo; 9 | } 10 | #else 11 | int foo = 66; 12 | #endif 13 | -------------------------------------------------------------------------------- /tests/incomplete.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | struct foo bar(); 4 | 5 | struct foo { 6 | int a; 7 | }; 8 | 9 | struct foo bar() { 10 | return (struct foo){1}; 11 | } 12 | 13 | int main() { 14 | return bar().a != 1; 15 | } 16 | -------------------------------------------------------------------------------- /tests/init_list_arr.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | typedef long I; 4 | typedef struct{I c[4];I b,e,k;} PT; 5 | 6 | PT cases[] = { 7 | 0, 1, 2, 3, 4, 5, 6, 8 | 7, 8, 9, 10, 11, 12, 13 9 | }; 10 | 11 | int main() { 12 | I* p = cases; 13 | 14 | for (int i = 0; i < 14; i++) { 15 | if (p[i] != i) { 16 | return i; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/int_literal_types.c: -------------------------------------------------------------------------------- 1 | // expected value: 69 2 | 3 | int main() { 4 | int a = 0; 5 | int b = 00; 6 | int c = 0000; 7 | int d = 0x0; 8 | 9 | int e = 0xFE; 10 | int f = 010; 11 | int g = 0077; 12 | 13 | return a + b + c + d + e + f + g; 14 | } 15 | -------------------------------------------------------------------------------- /tests/integer_const_expr.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int main() { 4 | char a[1]; 5 | char b[1 + 3]; 6 | char c[1 ? 2 : 4]; 7 | char d[1 * 5 + 9 + (~-1)]; 8 | 9 | if (sizeof(a) != 1) { 10 | return 1; 11 | } 12 | 13 | if (sizeof(b) != 4) { 14 | return 2; 15 | } 16 | 17 | if (sizeof(c) != 2) { 18 | return 3; 19 | } 20 | 21 | if (sizeof(d) != 14) { 22 | return 4; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/langproc/_example/example.c: -------------------------------------------------------------------------------- 1 | // stdout: Hello from RISC-V Test function produced value: 8.700000 Example function returned: 5 2 | 3 | int f() 4 | { 5 | return 5; 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/_example/example_driver.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int f(); 4 | 5 | void test(double a) 6 | { 7 | printf("Test function produced value: %f ", (float)a + 3.2f); 8 | } 9 | 10 | int main() 11 | { 12 | printf("Hello from RISC-V "); 13 | 14 | test(5.5); 15 | printf("Example function returned: %d\n", f()); 16 | 17 | return !(f() == 5); 18 | } 19 | -------------------------------------------------------------------------------- /tests/langproc/array/declare_global.c: -------------------------------------------------------------------------------- 1 | int x[8]; 2 | 3 | int f() 4 | { 5 | return 11; 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/array/declare_global_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==11); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/array/declare_local.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int y; 4 | int x[8]; 5 | y=13; 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/array/declare_local_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==13); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/array/index_constant.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x[8]; 4 | x[0]=23; 5 | return x[0]; 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/array/index_constant_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==23); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/array/index_expression.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int i; 4 | int x[8]; 5 | int acc; 6 | for(i=8; i<16; i++){ 7 | x[i-8]=i; 8 | } 9 | acc=0; 10 | for(i=0; i<8; i++){ 11 | acc=acc+x[i+0]; 12 | } 13 | return acc; 14 | } 15 | -------------------------------------------------------------------------------- /tests/langproc/array/index_expression_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==92); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/array/index_variable.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int i; 4 | int x[8]; 5 | for(i=0; i<8; i++){ 6 | x[i]=i; 7 | } 8 | return x[4]; 9 | } 10 | -------------------------------------------------------------------------------- /tests/langproc/array/index_variable_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==4); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_multiple.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | int y; 5 | y=0; 6 | for(x=0; x<10; x=x+1){ 7 | y=y-1; 8 | } 9 | return y; 10 | } 11 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_multiple_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==-10); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_one.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | for(x=0; x<1; x=x+1){ 5 | 6 | } 7 | return x+19937; 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_one_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==19938); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_zero_v1.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | for(x=0; x<0; x=x+1){ 5 | return 1; 6 | } 7 | return 19937; 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_zero_v1_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==19937); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_zero_v2.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | for(x=0; x<0; x++){ 5 | return 1; 6 | } 7 | return 19937; 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/for_zero_v2_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==19937); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_else_false.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | if(0){ 4 | return 11; 5 | }else{ 6 | return 10; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_else_false_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==10); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_else_true.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | if(1){ 4 | return 11; 5 | }else{ 6 | return 10; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_else_true_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==11); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_false.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | if(0){ 4 | return 11; 5 | } 6 | return 10; 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_false_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==10); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_true.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | if(1){ 4 | return 11; 5 | } 6 | return 10; 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/if_true_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==11); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/sequence.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | x=1; 5 | x=x+x; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/sequence_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(int x, int y); 3 | 4 | int main() 5 | { 6 | return !(f(10,20)==2); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_multiple.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | x=20; 5 | while(x > 10){ 6 | x=x-1; 7 | } 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_multiple_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f(10,20)==10); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_once.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | x=1; 5 | while(x){ 6 | x=0; 7 | } 8 | return 19937; 9 | } 10 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_once_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(int x, int y); 3 | 4 | int main() 5 | { 6 | return !(f(10,20)==19937); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_zero.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | while(0){ 4 | 5 | } 6 | return 19937; 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/control_flow/while_zero_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int main() 5 | { 6 | return !(f()==19937); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/default/test_ADD0.c: -------------------------------------------------------------------------------- 1 | int f(int a, int b) 2 | { 3 | return a+b; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/default/test_ADD0_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(int x, int y); 3 | 4 | int main() 5 | { 6 | return !( 40 == f(30,10) ); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/default/test_ADD1.c: -------------------------------------------------------------------------------- 1 | int f(int a) 2 | { 3 | return a+10; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/default/test_ADD1_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(int x); 3 | 4 | int main() 5 | { 6 | return !( 40 == f(30) ); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/default/test_CALL.c: -------------------------------------------------------------------------------- 1 | int g(); 2 | 3 | int f() 4 | { 5 | return g(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/default/test_CALL_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int f(); 3 | 4 | int g() 5 | { 6 | return 10; 7 | } 8 | 9 | int main() 10 | { 11 | return !( 10==f() ); 12 | } 13 | -------------------------------------------------------------------------------- /tests/langproc/default/test_LOCAL.c: -------------------------------------------------------------------------------- 1 | int ffff() 2 | { 3 | int x; 4 | x=10; 5 | return x; 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/default/test_LOCAL_driver.c: -------------------------------------------------------------------------------- 1 | int ffff(); 2 | 3 | int main() 4 | { 5 | return !( ffff()==10 ); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/float/add.c: -------------------------------------------------------------------------------- 1 | float f(float x, float y) 2 | { 3 | return x+y; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/add_double.c: -------------------------------------------------------------------------------- 1 | double f(double x, double y) 2 | { 3 | return x+y; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/add_double_driver.c: -------------------------------------------------------------------------------- 1 | 2 | double f(double x, double y); 3 | 4 | int main() 5 | { 6 | return !(f(11.0,1.0)==12.0); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/add_driver.c: -------------------------------------------------------------------------------- 1 | 2 | float f(float x, float y); 3 | 4 | int main() 5 | { 6 | return !(f(11.0f,1.0f)==12.0f); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/add_mul.c: -------------------------------------------------------------------------------- 1 | float f(float x, float y, float z) 2 | { 3 | return x+y*z; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/add_mul_driver.c: -------------------------------------------------------------------------------- 1 | 2 | float f(float x, float y, float z); 3 | 4 | int main() 5 | { 6 | return !(f(2.0f,3.0f,4.0f)==14.0f); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/mul.c: -------------------------------------------------------------------------------- 1 | float f(float x, float y) 2 | { 3 | return x*y; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/mul_add.c: -------------------------------------------------------------------------------- 1 | float f(float x, float y, float z) 2 | { 3 | return x*y+z; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/mul_add_driver.c: -------------------------------------------------------------------------------- 1 | 2 | float f(float x, float y, float z); 3 | 4 | int main() 5 | { 6 | return !(f(2.0f,3.0f,4.0f)==10.0f); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/mul_double.c: -------------------------------------------------------------------------------- 1 | double f(double x, double y) 2 | { 3 | return x*y; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/float/mul_double_driver.c: -------------------------------------------------------------------------------- 1 | 2 | double f(double x, double y); 3 | 4 | int main() 5 | { 6 | return !(f(11.0,2.0)==22.0); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/mul_driver.c: -------------------------------------------------------------------------------- 1 | 2 | float f(float x, float y); 3 | 4 | int main() 5 | { 6 | return !(f(11.0f,2.0f)==22.0f); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/float/pow.c: -------------------------------------------------------------------------------- 1 | float f(float x, int n) 2 | { 3 | float acc=1.0f; 4 | int i=0; 5 | while(i 0){ 9 | acc += y; 10 | x--; 11 | } 12 | return acc; 13 | } 14 | -------------------------------------------------------------------------------- /tests/langproc/programs/multiply_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int multiply(int x, int y); 3 | 4 | int main() 5 | { 6 | return !(multiply(-20,30)==-600); 7 | } 8 | -------------------------------------------------------------------------------- /tests/langproc/programs/sqrt.c: -------------------------------------------------------------------------------- 1 | int bsqrt(int lo, int hi, int val) 2 | { 3 | while(lo+1 < hi){ 4 | int mid=(lo+hi)>>1; 5 | int sqr=mid*mid; 6 | if(sqr <= val){ 7 | lo=mid; 8 | }else{ 9 | hi=mid; 10 | } 11 | } 12 | if( lo*lo < val ) { 13 | return hi; 14 | }else{ 15 | return lo; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/langproc/programs/sqrt_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int bsqrt(int lo, int hi, int v); 3 | 4 | int main() 5 | { 6 | int x; 7 | return !(bsqrt(1,1000,64)==8); 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/strings/chliteral.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | return 'h'; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/strings/chliteral_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int g(); 3 | 4 | int main() 5 | { 6 | int x; 7 | return !(g()=='h'); 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/strings/escaped.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | char *x="\\"; 4 | return x[0]; 5 | } 6 | -------------------------------------------------------------------------------- /tests/langproc/strings/escaped_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int g(); 3 | 4 | int main() 5 | { 6 | int x; 7 | return !(g()=='\\'); 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/strings/literal.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | char *x="hello"; 4 | return x[0]; 5 | } 6 | -------------------------------------------------------------------------------- /tests/langproc/strings/literal_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int g(); 3 | 4 | int main() 5 | { 6 | int x; 7 | return !(g()=='h'); 8 | } 9 | -------------------------------------------------------------------------------- /tests/langproc/strings/puts.c: -------------------------------------------------------------------------------- 1 | void fakeputs(char *x); 2 | 3 | void g() 4 | { 5 | fakeputs("wibble"); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/strings/puts_driver.c: -------------------------------------------------------------------------------- 1 | 2 | int strcmp(const char *, const char *); 3 | 4 | int ok; 5 | 6 | void fakeputs(char *x) 7 | { 8 | ok=!strcmp(x,"wibble"); 9 | } 10 | 11 | int g(); 12 | 13 | int main() 14 | { 15 | ok=0; 16 | g(); 17 | return !(ok==1); 18 | } 19 | -------------------------------------------------------------------------------- /tests/langproc/strings/search.c: -------------------------------------------------------------------------------- 1 | char *search(char *x, char c) 2 | { 3 | while(*x){ 4 | if(*x==c){ 5 | return x; 6 | } 7 | x=x+1; 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/langproc/strings/search_driver.c: -------------------------------------------------------------------------------- 1 | char *search(char *x, char c); 2 | 3 | int main() 4 | { 5 | char *s="abcdef"; 6 | 7 | char *p=search((char*)s,'c'); 8 | return !(p==s+2); 9 | } 10 | -------------------------------------------------------------------------------- /tests/langproc/struct/sizeof.c: -------------------------------------------------------------------------------- 1 | struct x{ 2 | int y; 3 | }; 4 | 5 | int f() 6 | { 7 | struct x y; 8 | return sizeof(y); 9 | } -------------------------------------------------------------------------------- /tests/langproc/struct/sizeof_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==4); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/struct/struct_inst.c: -------------------------------------------------------------------------------- 1 | struct x{ 2 | int y; 3 | }; 4 | 5 | int f() 6 | { 7 | struct x y; 8 | return 13; 9 | } -------------------------------------------------------------------------------- /tests/langproc/struct/struct_inst_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==13); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/struct/struct_member_get.c: -------------------------------------------------------------------------------- 1 | struct x{ 2 | int y; 3 | }; 4 | 5 | int f() 6 | { 7 | struct x z; 8 | z.y=13; 9 | return z.y; 10 | } -------------------------------------------------------------------------------- /tests/langproc/struct/struct_member_get_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==13); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/struct/struct_member_set.c: -------------------------------------------------------------------------------- 1 | struct x{ 2 | int y; 3 | }; 4 | 5 | int f() 6 | { 7 | struct x z; 8 | z.y=17; 9 | return 13; 10 | } -------------------------------------------------------------------------------- /tests/langproc/struct/struct_member_set_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==13); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/struct/struct_two_members.c: -------------------------------------------------------------------------------- 1 | struct x{ 2 | int y; 3 | int z; 4 | }; 5 | 6 | int f() 7 | { 8 | struct x g; 9 | g.y=17; 10 | g.z=13; 11 | return g.y+g.z; 12 | } -------------------------------------------------------------------------------- /tests/langproc/struct/struct_two_members_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==30); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_char_inst.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | char x; 4 | return sizeof(x); 5 | } 6 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_char_inst_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==1); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_char_type.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | return sizeof(char); 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_char_type_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==1); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_int_inst.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int x; 4 | return sizeof(x); 5 | } 6 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_int_inst_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==4); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_int_type.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | return sizeof(int); 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/types/sizeof_int_type_driver.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() 4 | { 5 | return !(f()==4); 6 | } 7 | -------------------------------------------------------------------------------- /tests/langproc/types/unsigned.c: -------------------------------------------------------------------------------- 1 | unsigned f() 2 | { 3 | return 11; 4 | } 5 | -------------------------------------------------------------------------------- /tests/langproc/types/unsigned_driver.c: -------------------------------------------------------------------------------- 1 | unsigned f(); 2 | 3 | int main() 4 | { 5 | return !(f()==11); 6 | } 7 | -------------------------------------------------------------------------------- /tests/local_static.c: -------------------------------------------------------------------------------- 1 | // expected value: 2 2 | 3 | int foo() { 4 | static int a = 0; 5 | return a++; 6 | } 7 | 8 | int main() { 9 | foo(); 10 | foo(); 11 | return foo(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/logical_and.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int f(int x, int y) { 4 | return x && y; 5 | } 6 | 7 | int main() 8 | { 9 | if( (f(0x0F,0xF0)!=1) ) return 1; 10 | if( (f(0x00,0xF0)!=0) ) return 2; 11 | if( (f(0x0F,0x00)!=0) ) return 3; 12 | if( (f(0x00,0x00)!=0) ) return 4; 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/math.c: -------------------------------------------------------------------------------- 1 | // expected value: 84 2 | int main() { 3 | return 5 + 9 * 9 - 1 * 7 / 3; 4 | } 5 | -------------------------------------------------------------------------------- /tests/md_array.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int main() { 4 | int md0[2][2] = { {0, 1}, {2, 3} }; 5 | 6 | for (int i = 0; i < 2; i++) { 7 | for (int j = 0; j < 2; j++) { 8 | if (md0[i][j] != (i * 2) + j) { 9 | return (i * 2) + j; 10 | } 11 | } 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/memset.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | void *memset(void *str, int c, unsigned long n); 4 | 5 | int main() { 6 | char b[2000]; 7 | memset(b, 0, 2000); 8 | 9 | for (int i = 0; i < 2000; i++) { 10 | if (b[i]) { 11 | return 1; 12 | } 13 | } 14 | 15 | memset(b, 32, 2000); 16 | 17 | for (int i = 0; i < 2000; i++) { 18 | if (b[i] != 32) { 19 | return 1; 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/mixed_fp_ret.c: -------------------------------------------------------------------------------- 1 | // expected value: 3 2 | 3 | struct S { float x; double y; }; 4 | 5 | int printf(const char *, ...); 6 | 7 | struct S f(double d) { 8 | struct S s; 9 | s.x = d; 10 | s.y = d; 11 | return s; 12 | } 13 | 14 | int main() { 15 | struct S s = f(1.5); 16 | return s.x + s.y; 17 | } 18 | -------------------------------------------------------------------------------- /tests/mul.c: -------------------------------------------------------------------------------- 1 | // expected value: 45 2 | int main() { return 5 * 9; } 3 | -------------------------------------------------------------------------------- /tests/multi_function.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | int main() { return 0; } 3 | 4 | int add() { return 1 + 3; } 5 | 6 | int sub() { return 3 - 1; } 7 | -------------------------------------------------------------------------------- /tests/multi_line_comment.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | int main() { /* this */ 3 | /* blah */ /* int a = 1*/ 4 | /* here is one */ int /**/ a = 1; /* 5 | multi 6 | linecomments 7 | */ 8 | 9 | /* 10 | ** fizz 11 | ** buzz 12 | */ 13 | return a; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/negative.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | int main() { 4 | int a = -1; 5 | int b = -9; 6 | 7 | return -(a + b); 8 | } 9 | -------------------------------------------------------------------------------- /tests/nested_struct.c: -------------------------------------------------------------------------------- 1 | // expected value: 50 2 | 3 | struct bar { 4 | int z; 5 | }; 6 | 7 | struct foo { 8 | int a, b; 9 | char *c; 10 | unsigned long d[3]; 11 | 12 | struct bar e; 13 | }; 14 | 15 | int main() { 16 | struct foo bar; 17 | bar.a = 25; 18 | bar.e.z = 50; 19 | return bar.e.z; 20 | } 21 | -------------------------------------------------------------------------------- /tests/no_ret.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int main() {} 4 | -------------------------------------------------------------------------------- /tests/offsetof.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | struct Foo { 4 | int a; 5 | int b; 6 | }; 7 | 8 | 9 | long off_a = (long)&(((struct Foo *)0)->a); 10 | long off_b = (long)&(((struct Foo *)0)->b); 11 | 12 | int main() { 13 | if (off_a) { 14 | return 1; 15 | } 16 | 17 | if (off_b != sizeof(int)) { 18 | return 2; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/pointer.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: 0 5 3 | 4 | int printf(const char *format, ...); 5 | 6 | int *const *volatile *foo(void *bar, int *const *volatile *baz) { 7 | printf("%d %d", (int)bar, ***baz); 8 | return baz; 9 | } 10 | 11 | int main() { 12 | int a = 5; 13 | int *const b = &a; 14 | int *const *volatile c = &b; 15 | 16 | foo(0, &c); 17 | } 18 | -------------------------------------------------------------------------------- /tests/pointer_sub.c: -------------------------------------------------------------------------------- 1 | // expected value: 3 2 | 3 | int main() { 4 | int a[4]; 5 | 6 | int *p = &a[0]; 7 | int *q = &a[3]; 8 | 9 | return q - p; 10 | } 11 | -------------------------------------------------------------------------------- /tests/postfix.c: -------------------------------------------------------------------------------- 1 | // expected value: 254 2 | 3 | int main() { 4 | int a = 77; 5 | int b = 25; 6 | 7 | int c = ++a; 8 | int d = a++; 9 | 10 | int e = ++a; 11 | int f = a++; 12 | 13 | int g = --b; 14 | int h = b--; 15 | 16 | int i = --b; 17 | int j = b--; 18 | 19 | return (a + b + c + d + e + f) | (g + h + i + j); 20 | } 21 | -------------------------------------------------------------------------------- /tests/preproc_nl.c: -------------------------------------------------------------------------------- 1 | // skip: not implemented 2 | // expected value: 0 3 | 4 | #define FOO bar\ 5 | baz 6 | 7 | int main() { 8 | int FOO = 0; 9 | 10 | return barbaz; 11 | } 12 | -------------------------------------------------------------------------------- /tests/preproc_prescan.c: -------------------------------------------------------------------------------- 1 | // skip: preproc prescan fixes needed 2 | // no-compile 3 | 4 | #define T(a, b, c) a + b + c; 5 | #define FOO 1, 2, 3 6 | 7 | int main() { 8 | return T(FOO); 9 | } 10 | -------------------------------------------------------------------------------- /tests/preproc_punctuator.c: -------------------------------------------------------------------------------- 1 | // no-compile 2 | 3 | int main() { 4 | int a = 0; 5 | int b = 0; 6 | 7 | int c = a+++++b; 8 | 9 | return c; 10 | } 11 | -------------------------------------------------------------------------------- /tests/preproc_ternary.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | #define yes 10 4 | 5 | #if defined no ? no >= 10L : defined yes 6 | int main() 7 | #else 8 | #error fail 9 | #endif 10 | 11 | 12 | #if defined yes ? yes >= 10L : defined no 13 | { 14 | return 0; 15 | } 16 | #else 17 | #error fail 18 | #endif 19 | -------------------------------------------------------------------------------- /tests/printf_format.c: -------------------------------------------------------------------------------- 1 | // no-compile 2 | // flags: -Werror 3 | 4 | [[jcc::__format__(printf, 1, 2), gnu::format(printf, 1, 2)]] int printf(const char *, ...); 5 | // int printf(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); 6 | 7 | int main() { 8 | printf("%s\n", 1); 9 | printf(); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/printf_string.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: hello world 3 | 4 | int printf(const char *, ...); 5 | 6 | int main() { 7 | const char *h = "hello"; 8 | const char *w = "world"; 9 | 10 | printf("%s %s\n", h, w); 11 | } 12 | -------------------------------------------------------------------------------- /tests/promote_phi.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | 4 | int yes() { return 1; } 5 | 6 | int main() { 7 | int a = 0; 8 | int *p = &a; 9 | 10 | if (yes()) { 11 | *p = 10; 12 | } else { 13 | *p = 50; 14 | } 15 | 16 | return *p; 17 | } 18 | -------------------------------------------------------------------------------- /tests/ptr_global.c: -------------------------------------------------------------------------------- 1 | // expected value: 34 2 | 3 | int a[2] = { 5, 7 }; 4 | 5 | int *p0 = a; 6 | int *p1 = a + 1; 7 | int *p2 = &a[0]; 8 | int *p3 = &a[1]; 9 | 10 | struct foo { 11 | int a; 12 | }; 13 | 14 | struct foo f = { 10 }; 15 | int *p4 = &f.a; 16 | 17 | int main() { 18 | return *p0 + *p1 + *p2 + *p3 + *p4; 19 | } 20 | -------------------------------------------------------------------------------- /tests/recursive_struct.c: -------------------------------------------------------------------------------- 1 | // expected value: 91 2 | 3 | int main() { 4 | struct S { 5 | struct S *p; 6 | int x; 7 | } s; 8 | 9 | s.x = 91; 10 | s.p = &s; 11 | return s.p->p->p->p->p->x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/sdiv.c: -------------------------------------------------------------------------------- 1 | // expected value: 8 2 | int main() { return 88 / 10; } 3 | -------------------------------------------------------------------------------- /tests/sext.c: -------------------------------------------------------------------------------- 1 | // expected value: 3 2 | int main() { 3 | int a = 1, b = 2; 4 | long c = a + b; 5 | 6 | unsigned char d = 0xFF; 7 | int e = d; 8 | 9 | if (e != 0xFF) { 10 | return 1; 11 | } 12 | 13 | return c; 14 | } 15 | -------------------------------------------------------------------------------- /tests/single_line_comment.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | int main() { // this 3 | // tests 4 | // tests // // int a = 1; 5 | int a = 1; // comments 6 | return a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/sizeof_ambigous.c: -------------------------------------------------------------------------------- 1 | // expected value: 40 2 | 3 | int main() { 4 | // should be parsed as `sizeof(int) * p`, not `sizeof((int) *p)` 5 | int p = 10; 6 | return sizeof(int) * p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/sizeof_expr.c: -------------------------------------------------------------------------------- 1 | // expected value: 15 2 | 3 | int main() { 4 | char a; 5 | short b; 6 | unsigned c; 7 | unsigned long long d; 8 | return sizeof a + sizeof(b) + sizeof c + sizeof(d); 9 | } 10 | -------------------------------------------------------------------------------- /tests/sizeof_ty.c: -------------------------------------------------------------------------------- 1 | // expected value: 15 2 | 3 | int main() { 4 | return sizeof(char) + sizeof(short) + sizeof(unsigned int) + 5 | sizeof(unsigned long long); 6 | } 7 | -------------------------------------------------------------------------------- /tests/special.c: -------------------------------------------------------------------------------- 1 | // expected value: 8 2 | // stdout: special.c 7 10:04:33 Dec 10 2025 3 | 4 | int printf(const char *, ...); 5 | 6 | int main() { 7 | printf("%s %d %s %s", __FILE__, __LINE__, __TIME__, __DATE__); 8 | return __LINE__; 9 | } 10 | -------------------------------------------------------------------------------- /tests/spill.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int read(int *p) { 4 | return *p; 5 | } 6 | 7 | int main() { 8 | int a = 7; 9 | 10 | if (10) { 11 | a = 1; 12 | } else { 13 | a = 80; 14 | } 15 | 16 | int *p = &a; 17 | 18 | if (0) { 19 | a += 100; 20 | } else { 21 | a *= 3; 22 | } 23 | 24 | return read(p) != 3; 25 | } 26 | -------------------------------------------------------------------------------- /tests/sqrt.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | double sqrt(double); 4 | 5 | int main() { 6 | return sqrt(100.0); 7 | } 8 | -------------------------------------------------------------------------------- /tests/squot.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | int main() { 3 | int a = 10, b = 3; 4 | return a % b; 5 | } 6 | -------------------------------------------------------------------------------- /tests/static_assert.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int main() { 4 | static_assert(1.0 * 2 == 2.0, "floats work"); 5 | static_assert(sizeof(char) == 1); 6 | static_assert(sizeof(int) == 4, "with message"); 7 | } 8 | -------------------------------------------------------------------------------- /tests/static_assert_fail.c: -------------------------------------------------------------------------------- 1 | // no-compile 2 | 3 | int main() { 4 | static_assert(sizeof(char) != 1); 5 | static_assert(sizeof(char) != 1, "this test should fail"); 6 | static_assert(1.0 * 2 != 2.0, "floats work"); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/static_func.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | 3 | static inline int foo() { 4 | return 10; 5 | } 6 | 7 | int main() { 8 | return foo(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/str_concat.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: foobarbaz 3 | 4 | int puts(const char *); 5 | int main() { 6 | const char *a = "foo" 7 | "bar" 8 | "baz"; 9 | 10 | puts(a); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/str_global.c: -------------------------------------------------------------------------------- 1 | // expected value: 65 2 | 3 | const char *s = "hello"; 4 | 5 | int main() { 6 | if (s[0] != 'h') { 7 | return 1; 8 | } 9 | 10 | s = "A"; 11 | return s[0]; 12 | } 13 | -------------------------------------------------------------------------------- /tests/str_index.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: ~ 3 | 4 | int putchar(int); 5 | int main() { 6 | char b[2] = { 0 }; 7 | int N = 3; 8 | b[0] = ".,-~:;=!*#$@"[N > 0 ? N : 0]; 9 | putchar(b[0]); 10 | putchar('\n'); 11 | } 12 | -------------------------------------------------------------------------------- /tests/struct.c: -------------------------------------------------------------------------------- 1 | // expected value: 26 2 | 3 | struct bar; 4 | struct baz { 5 | struct baz *b; 6 | }; 7 | 8 | struct foo { 9 | int a, b; 10 | char *c; 11 | unsigned long d[3]; 12 | }; 13 | 14 | struct bat { 15 | int a; 16 | }; 17 | 18 | struct bat l; 19 | 20 | int main() { 21 | l.a = 1; 22 | 23 | struct foo bar; 24 | bar.a = 25; 25 | return bar.a + l.a; 26 | } 27 | -------------------------------------------------------------------------------- /tests/struct_inline_init.c: -------------------------------------------------------------------------------- 1 | // expected value: 7 2 | 3 | struct bar { 4 | int a; 5 | }; 6 | 7 | struct foo { 8 | int a; 9 | struct bar b; 10 | }; 11 | 12 | int main() { 13 | struct foo f = { 14 | 3, 4 15 | }; 16 | 17 | return f.a + f.b.a; 18 | } 19 | -------------------------------------------------------------------------------- /tests/struct_move.c: -------------------------------------------------------------------------------- 1 | // expected value: 18 2 | 3 | struct foo { 4 | int b[3]; 5 | }; 6 | 7 | int main() { 8 | struct foo a; 9 | a.b[0] = 1; 10 | a.b[1] = 2; 11 | a.b[2] = 3; 12 | 13 | 14 | struct foo b = a; 15 | b.b[0] = 2 * b.b[0]; 16 | b.b[1] = 2 * b.b[1]; 17 | b.b[2] = 2 * b.b[2]; 18 | 19 | return a.b[0] + a.b[1] + a.b[2] + b.b[0] + b.b[1] + b.b[2]; 20 | } 21 | -------------------------------------------------------------------------------- /tests/sub.c: -------------------------------------------------------------------------------- 1 | // expected value: 2 2 | int main() { return 9 - 7; } 3 | -------------------------------------------------------------------------------- /tests/typedef2.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | typedef int int_t; 4 | 5 | typedef int_t *pint_t; 6 | 7 | int_t g(int_t y) 8 | { 9 | pint_t p; 10 | int_t x; 11 | x=y; 12 | p=&x; 13 | return 1+*p; 14 | } 15 | 16 | int main() { 17 | return g(1) != 2; 18 | } 19 | -------------------------------------------------------------------------------- /tests/typedef_duplicate.c: -------------------------------------------------------------------------------- 1 | // skip: not yet implemented 2 | // expected value: 0 3 | 4 | typedef void *bazl; 5 | typedef void *bazl; 6 | 7 | typedef int my_int; 8 | typedef int my_int; 9 | 10 | typedef void (*foo)(int *); 11 | typedef void (*foo)(int *); 12 | 13 | int main() { 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/udiv.c: -------------------------------------------------------------------------------- 1 | // expected value: 5 2 | int main() { 3 | int a = 7; 4 | unsigned b = 2; 5 | long c = 5; 6 | unsigned long d = 2; 7 | 8 | // a / b -> type `unsigned` 9 | // b / c -> type `long` 10 | return (a / b) + (b / c) + (c / d); 11 | } 12 | -------------------------------------------------------------------------------- /tests/uninit_pointer.c: -------------------------------------------------------------------------------- 1 | // expected value: 64 2 | 3 | int main() { 4 | int a; 5 | 6 | int *p = &a; 7 | *p = 64; 8 | 9 | return (a + *p) / 2; 10 | } 11 | -------------------------------------------------------------------------------- /tests/union.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | union foo { 4 | int a; 5 | int b; 6 | }; 7 | 8 | int main() { 9 | union foo bar; 10 | bar.a = 1; 11 | return bar.b; 12 | } 13 | -------------------------------------------------------------------------------- /tests/union_struct_nested.c: -------------------------------------------------------------------------------- 1 | // expected value: 222 2 | 3 | struct bytes { 4 | char a, b, c, d; 5 | }; 6 | 7 | union bar { 8 | int value; 9 | struct bytes bytes; 10 | }; 11 | 12 | struct foo { 13 | int a; 14 | long b; 15 | union bar c; 16 | }; 17 | 18 | int main() { 19 | struct foo foo; 20 | foo.a = 50; 21 | foo.b = 100; 22 | foo.c.value = 57005; 23 | return foo.c.bytes.b; 24 | } 25 | -------------------------------------------------------------------------------- /tests/uquot.c: -------------------------------------------------------------------------------- 1 | // expected value: 4 2 | int main() { 3 | unsigned a = 9, b = 5; 4 | return a % b; 5 | } 6 | -------------------------------------------------------------------------------- /tests/utf8.c: -------------------------------------------------------------------------------- 1 | // expected value: 1 2 | 3 | double foo(double xₖ, double xₖ₊₁) { 4 | return xₖ₊₁ - xₖ; 5 | } 6 | 7 | int main() { 8 | if (foo(1, 2) != 1) { 9 | return 2; 10 | } 11 | 12 | int 😁 = 1; 13 | return 😁; 14 | } 15 | -------------------------------------------------------------------------------- /tests/variadic.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | // stdout: Hello, World!. Numbers work too - 2! 3 | 4 | int printf(const char *format, ...); 5 | 6 | int main() { printf("%s. Numbers work too - %d!", "Hello, World!", 2); } 7 | -------------------------------------------------------------------------------- /tests/void_cast.c: -------------------------------------------------------------------------------- 1 | // expected value: 0 2 | 3 | int main() { 4 | int a = 1; 5 | (void)a; 6 | } 7 | -------------------------------------------------------------------------------- /tests/while.c: -------------------------------------------------------------------------------- 1 | // expected value: 10 2 | int main() { 3 | int a = 10; 4 | int b = 0; 5 | 6 | while (a) { 7 | a = a - 1; 8 | b = b + 1; 9 | } 10 | 11 | return b; 12 | } 13 | -------------------------------------------------------------------------------- /tests/while_complex.c: -------------------------------------------------------------------------------- 1 | // expected value: 76 2 | int main() { 3 | int a = 50, b = 2; 4 | int iter_count = 0; 5 | int c = 1; 6 | 7 | int diff = a - b; 8 | 9 | while (diff) { 10 | iter_count = iter_count + 1; 11 | a = a * c - 1; 12 | b = b * c + 1; 13 | 14 | diff = a - b; 15 | } 16 | 17 | return iter_count + a + b; 18 | } 19 | -------------------------------------------------------------------------------- /tests/wide_char.c: -------------------------------------------------------------------------------- 1 | // expected value: 97 2 | 3 | int main() { 4 | int c = L'a'; 5 | 6 | const int *w = L"_a"; 7 | 8 | return (c + w[1]) / 2; 9 | } 10 | --------------------------------------------------------------------------------