From 7cdf37eaf6ec9b4f2f4adf527eea55c7bc716472 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Mon, 3 Jul 2023 01:22:36 +0200 Subject: [PATCH 1/3] exit with code 1 on `odin test` failure --- src/llvm_backend.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 12abe7b16..6a4046d8d 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1825,25 +1825,45 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star TEMPORARY_ALLOCATOR_GUARD(); auto args = array_make(temporary_allocator(), 1); args[0] = lb_addr_load(p, all_tests_slice); - lb_emit_call(p, runner, args); + lbValue result = lb_emit_call(p, runner, args); + + lbBlock *block_success = lb_create_block(p, "success"); + lbBlock *block_failure = lb_create_block(p, "failure"); + + lbValue result_success = lb_emit_comp(p, Token_CmpEq, result, lb_const_bool(m, t_bool, true)); + lb_emit_if(p, result_success, block_success, block_failure); + + lbValue exit_runner = lb_find_package_value(m, str_lit("os"), str_lit("exit")); + + lb_start_block(p, block_success); + { + auto exit_args = array_make(temporary_allocator(), 1); + exit_args[0] = lb_const_int(m, t_int, 0); + lb_emit_call(p, exit_runner, exit_args); + } + + lb_start_block(p, block_failure); + { + auto exit_args = array_make(temporary_allocator(), 1); + exit_args[0] = lb_const_int(m, t_int, 1); + lb_emit_call(p, exit_runner, exit_args); + } } else { if (m->info->entry_point != nullptr) { lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point); lb_emit_call(p, entry_point, {}, ProcInlining_no_inline); } - } + if (call_cleanup) { + lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type}; + lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none); + } - if (call_cleanup) { - lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type}; - lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none); - } - - - if (is_dll_main) { - LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false)); - } else { - LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); + if (is_dll_main) { + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false)); + } else { + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); + } } lb_end_procedure_body(p); From 52700d6a840d5635cf8ebc3f9ebf516f9c47f615 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Tue, 11 Jul 2023 19:30:44 +0200 Subject: [PATCH 2/3] use lb_emit_select instead of lb_emit_if for exit check --- src/llvm_backend.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 6a4046d8d..90716dde0 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1827,30 +1827,12 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star args[0] = lb_addr_load(p, all_tests_slice); lbValue result = lb_emit_call(p, runner, args); - lbBlock *block_success = lb_create_block(p, "success"); - lbBlock *block_failure = lb_create_block(p, "failure"); - - lbValue result_success = lb_emit_comp(p, Token_CmpEq, result, lb_const_bool(m, t_bool, true)); - lb_emit_if(p, result_success, block_success, block_failure); - lbValue exit_runner = lb_find_package_value(m, str_lit("os"), str_lit("exit")); - - lb_start_block(p, block_success); - { - auto exit_args = array_make(temporary_allocator(), 1); - exit_args[0] = lb_const_int(m, t_int, 0); - lb_emit_call(p, exit_runner, exit_args); - } - - lb_start_block(p, block_failure); - { - auto exit_args = array_make(temporary_allocator(), 1); - exit_args[0] = lb_const_int(m, t_int, 1); - lb_emit_call(p, exit_runner, exit_args); - } + auto exit_args = array_make(temporary_allocator(), 1); + exit_args[0] = lb_emit_select(p, result, lb_const_int(m, t_int, 0), lb_const_int(m, t_int, 1)); + lb_emit_call(p, exit_runner, exit_args, ProcInlining_none); } else { - if (m->info->entry_point != nullptr) { - lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point); + if (m->info->entry_point != nullptr) { lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point); lb_emit_call(p, entry_point, {}, ProcInlining_no_inline); } From 3cce9721257f921b81bd757c453fecb8b5308227 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Tue, 11 Jul 2023 19:33:14 +0200 Subject: [PATCH 3/3] fix indentation --- src/llvm_backend.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 90716dde0..938c9b2ac 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1832,19 +1832,20 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star exit_args[0] = lb_emit_select(p, result, lb_const_int(m, t_int, 0), lb_const_int(m, t_int, 1)); lb_emit_call(p, exit_runner, exit_args, ProcInlining_none); } else { - if (m->info->entry_point != nullptr) { lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point); + if (m->info->entry_point != nullptr) { + lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point); lb_emit_call(p, entry_point, {}, ProcInlining_no_inline); } if (call_cleanup) { - lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type}; - lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none); + lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type}; + lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none); } if (is_dll_main) { - LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false)); + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false)); } else { - LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); } }