From 816c47058da777bafb4bba17d0648a6e221b4a94 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 30 Oct 2025 16:14:32 +0000 Subject: For test runner, try to look for `os.exit` or `os2.exit` --- src/llvm_backend.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/llvm_backend.cpp') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 22a481187..3c9d92095 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2900,7 +2900,24 @@ 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); - lbValue exit_runner = lb_find_package_value(m, str_lit("os"), str_lit("exit")); + lbValue exit_runner = {}; + { + AstPackage *pkg = try_get_core_package(m->info, str_lit("os")); + if (pkg == nullptr) { + pkg = try_get_core_package(m->info, str_lit("os2")); + } + if (pkg == nullptr) { + pkg = get_core_package(m->info, str_lit("os2")); + } + + String name = str_lit("exit"); + Entity *e = scope_lookup_current(pkg->scope, name); + if (e == nullptr) { + compiler_error("Could not find type declaration for '%.*s.%.*s'\n", LIT(pkg->name), LIT(name)); + } + exit_runner = lb_find_value_from_entity(m, e); + } + 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); -- cgit v1.2.3 From 338733d9ef86d00215640b8cf749e426b9c27fb6 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 30 Oct 2025 17:54:02 +0100 Subject: Remove duplicate import --- base/runtime/os_specific_bsd.odin | 3 --- src/llvm_backend.cpp | 8 +------- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'src/llvm_backend.cpp') diff --git a/base/runtime/os_specific_bsd.odin b/base/runtime/os_specific_bsd.odin index 1c3a04e92..de300f1e0 100644 --- a/base/runtime/os_specific_bsd.odin +++ b/base/runtime/os_specific_bsd.odin @@ -25,9 +25,6 @@ _stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) { return int(ret), 0 } - -foreign import libc "system:c" - _exit :: proc "contextless" (code: int) -> ! { @(default_calling_convention="c") foreign libc { diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 3c9d92095..d6bd7d72d 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2902,13 +2902,7 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star lbValue exit_runner = {}; { - AstPackage *pkg = try_get_core_package(m->info, str_lit("os")); - if (pkg == nullptr) { - pkg = try_get_core_package(m->info, str_lit("os2")); - } - if (pkg == nullptr) { - pkg = get_core_package(m->info, str_lit("os2")); - } + AstPackage *pkg = get_runtime_package(m->info); String name = str_lit("exit"); Entity *e = scope_lookup_current(pkg->scope, name); -- cgit v1.2.3 From d6b5a3139a4cb42bfda53a05d87de0a03f91b9e0 Mon Sep 17 00:00:00 2001 From: Tohei Ichikawa Date: Sun, 9 Nov 2025 21:07:28 -0500 Subject: Fix allocation of anonymous globals --- src/llvm_backend.cpp | 1 + tests/internal/test_anonymous_globals.odin | 64 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/internal/test_anonymous_globals.odin (limited to 'src/llvm_backend.cpp') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index d6bd7d72d..71bca42ab 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2090,6 +2090,7 @@ gb_internal void lb_create_startup_runtime_generate_body(lbModule *m, lbProcedur name = gb_string_append_length(name, ename.text, ename.len); lbProcedure *dummy = lb_create_dummy_procedure(m, make_string_c(name), dummy_type); + dummy->is_startup = true; LLVMSetVisibility(dummy->value, LLVMHiddenVisibility); LLVMSetLinkage(dummy->value, LLVMWeakAnyLinkage); diff --git a/tests/internal/test_anonymous_globals.odin b/tests/internal/test_anonymous_globals.odin new file mode 100644 index 000000000..dd59ee376 --- /dev/null +++ b/tests/internal/test_anonymous_globals.odin @@ -0,0 +1,64 @@ +package test_internal + +import "core:testing" + + + +@(test) +test_address_of_anonymous_global :: proc(t: ^testing.T) { + // This loop exists so that we do more computation with stack memory + // This increases the likelihood of catching a bug where anonymous globals are incorrectly allocated on the stack + // instead of the data segment + for _ in 0..<10 { + testing.expect(t, global_variable.inner.field == 0xDEADBEEF) + } +} + +global_variable := Outer_Struct{ + inner = &Inner_Struct{ + field = 0xDEADBEEF, + }, +} +Outer_Struct :: struct{ + inner: ^Inner_Struct, + + // Must have a second field to prevent the compiler from simplifying the `Outer_Struct` type to `^Inner_Struct` + // ...I think? In any case, don't remove this field + _: int, +} +Inner_Struct :: struct{ + field: int, +} + + + +// Regression test for commit f1e3977cf94dfc0457f05d499cc280d8e1329086 where a larger anonymous global is needed to trigger +// the bug +@(test) +test_address_of_large_anonymous_global :: proc(t: ^testing.T) { + // This loop exists so that we do more computation with stack memory + // This increases the likelihood of catching a bug where anonymous globals are incorrectly allocated on the stack + // instead of the data segment + for _ in 0..<10 { + for i in 0..<8 { + testing.expect(t, global_variable_64.inner.field[i] == i) + } + } +} + +#assert(size_of(Inner_Struct_64) == 64) +global_variable_64 := Outer_Struct_64{ + inner = &Inner_Struct_64{ + field = [8]int{0, 1, 2, 3, 4, 5, 6, 7}, + }, +} +Outer_Struct_64 :: struct{ + inner: ^Inner_Struct_64, + + // Must have a second field to prevent the compiler from simplifying the `Outer_Struct` type to `^Inner_Struct` + // ...I think? In any case, don't remove this field + _: int, +} +Inner_Struct_64 :: struct{ + field: [8]int, +} -- cgit v1.2.3