From d5d900e292bf59885eb55ff4243af24c60eb82a0 Mon Sep 17 00:00:00 2001 From: Colter <32916571+Goldenlion5648@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:20:07 -0500 Subject: [PATCH 01/10] fix typo in float32_range doc string --- core/math/rand/rand.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/math/rand/rand.odin b/core/math/rand/rand.odin index bbd59a419..3082a0afc 100644 --- a/core/math/rand/rand.odin +++ b/core/math/rand/rand.odin @@ -468,7 +468,7 @@ Example: Possible Output: 15.312 - 673.130 + 273.130 */ @(require_results) float32_range :: proc(low, high: f32, gen := context.random_generator) -> (val: f32) { From 1281303ff756ce4a83dcdb20be6154c7a72f278f Mon Sep 17 00:00:00 2001 From: korvahkh <92224397+korvahkh@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:08:19 -0600 Subject: [PATCH 02/10] Preserve `#no_nil` in `intrinsics.type_convert_variants_to_pointers` Previously the newly returned type would not be marked as `#no_nil`. This caused `reflect.get_union_as_ptr_variants` to break on `#no_nil` unions. --- src/check_builtin.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index ea902387b..7d0ce3aef 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -5544,6 +5544,9 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As // NOTE(bill): Is this even correct? new_type->Union.node = operand->expr; new_type->Union.scope = bt->Union.scope; + if (bt->Union.kind == UnionType_no_nil) { + new_type->Union.kind = UnionType_no_nil; + } operand->type = new_type; } From 239c511ce9e580384eca804596dfaf227f98c807 Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 15:09:12 +0100 Subject: [PATCH 03/10] Fix strings.split_iterator when separator is empty --- core/strings/strings.odin | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index c014d2b2b..9e7ea6ac1 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1031,14 +1031,10 @@ Returns: */ @private _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { - if sep == "" { - res = s[:] - ok = true - s^ = s[len(s):] - return - } - m := index(s^, sep) + if sep == "" { + m = 1 if len(s) > 0 else -1 + } if m < 0 { // not found res = s[:] From 4c0b145bad3a49d3110ddc18c0dae2e59dcf05e4 Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 15:44:42 +0100 Subject: [PATCH 04/10] Fix unicode handling --- core/strings/strings.odin | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 9e7ea6ac1..b050262f0 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1033,7 +1033,12 @@ Returns: _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { m := index(s^, sep) if sep == "" { - m = 1 if len(s) > 0 else -1 + if len(s) == 0 { + m = -1 + } else { + _, w := utf8.decode_rune_in_string(s^) + m = w + } } if m < 0 { // not found From 385f5f50147f6f68f7722befc5ce0d36751a034d Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 19:51:48 +0100 Subject: [PATCH 05/10] Small optimization --- core/strings/strings.odin | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index b050262f0..e99a1bfb4 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1031,7 +1031,7 @@ Returns: */ @private _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { - m := index(s^, sep) + m: int if sep == "" { if len(s) == 0 { m = -1 @@ -1039,6 +1039,8 @@ _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, _, w := utf8.decode_rune_in_string(s^) m = w } + } else { + m = index(s^, sep) } if m < 0 { // not found From fbf536f465d22e5ea67bb9a4f973d7cebcf8915f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Sch=C3=B6n?= Date: Tue, 4 Feb 2025 21:27:44 +0100 Subject: [PATCH 06/10] `core:io` small documentation fixes --- core/io/io.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/io/io.odin b/core/io/io.odin index 6072aec6d..c2b44cbdb 100644 --- a/core/io/io.odin +++ b/core/io/io.odin @@ -126,7 +126,7 @@ _i64_err :: #force_inline proc "contextless" (n: int, err: Error) -> (i64, Error } -// read reads up to len(p) bytes into s. It returns the number of bytes read and any error if occurred. +// read reads up to len(p) bytes into p. It returns the number of bytes read and any error if occurred. // // When read encounters an .EOF or error after successfully reading n > 0 bytes, it returns the number of // bytes read along with the error. @@ -142,7 +142,7 @@ read :: proc(s: Reader, p: []byte, n_read: ^int = nil) -> (n: int, err: Error) { return } -// write writes up to len(p) bytes into s. It returns the number of bytes written and any error if occurred. +// write writes up to len(p) bytes into p. It returns the number of bytes written and any error if occurred. write :: proc(s: Writer, p: []byte, n_written: ^int = nil) -> (n: int, err: Error) { if s.procedure != nil { n64: i64 From b77430bea8ea29263750d0356343cee36808d8f3 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 5 Feb 2025 19:42:20 +0100 Subject: [PATCH 07/10] -obfuscate-source-code-locations on bounds checks and type assertions --- src/llvm_backend_expr.cpp | 8 ++---- src/llvm_backend_general.cpp | 52 +++++++++++++++--------------------- src/llvm_backend_utility.cpp | 8 ++---- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 871536927..693f2e225 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -3364,9 +3364,7 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { auto args = array_make(permanent_allocator(), arg_count); args[0] = ok; - args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(p->module, t_i32, pos.line); - args[3] = lb_const_int(p->module, t_i32, pos.column); + lb_set_file_line_col(p, array_slice(args, 1, args.count), pos); if (!build_context.no_rtti) { args[4] = lb_typeid(p->module, src_type); @@ -3393,9 +3391,7 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { auto args = array_make(permanent_allocator(), 6); args[0] = ok; - args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(p->module, t_i32, pos.line); - args[3] = lb_const_int(p->module, t_i32, pos.column); + lb_set_file_line_col(p, array_slice(args, 1, args.count), pos); args[4] = any_id; args[5] = id; diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 762256258..7425b9fd7 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -15,7 +15,6 @@ gb_global isize lb_global_type_info_member_offsets_index = 0; gb_global isize lb_global_type_info_member_usings_index = 0; gb_global isize lb_global_type_info_member_tags_index = 0; - gb_internal void lb_init_module(lbModule *m, Checker *c) { m->info = &c->info; @@ -540,6 +539,22 @@ gb_internal lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) { return lb_addr_get_ptr(p, addr); } +gb_internal void lb_set_file_line_col(lbProcedure *p, Array arr, TokenPos pos) { + String file = get_file_path_string(pos.file_id); + i32 line = pos.line; + i32 col = pos.column; + + if (build_context.obfuscate_source_code_locations) { + file = obfuscate_string(file, "F"); + line = obfuscate_i32(line); + col = obfuscate_i32(col); + } + + arr[0] = lb_find_or_add_entity_string(p->module, file); + arr[1] = lb_const_int(p->module, t_i32, line); + arr[2] = lb_const_int(p->module, t_i32, col); +} + gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) { if (build_context.no_bounds_check) { return; @@ -553,14 +568,8 @@ gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index index = lb_emit_conv(p, index, t_int); len = lb_emit_conv(p, len, t_int); - lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_i32, token.pos.line); - lbValue column = lb_const_int(p->module, t_i32, token.pos.column); - auto args = array_make(temporary_allocator(), 5); - args[0] = file; - args[1] = line; - args[2] = column; + lb_set_file_line_col(p, args, token.pos); args[3] = index; args[4] = len; @@ -582,14 +591,8 @@ gb_internal void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValu row_count = lb_emit_conv(p, row_count, t_int); column_count = lb_emit_conv(p, column_count, t_int); - lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_i32, token.pos.line); - lbValue column = lb_const_int(p->module, t_i32, token.pos.column); - auto args = array_make(temporary_allocator(), 7); - args[0] = file; - args[1] = line; - args[2] = column; + lb_set_file_line_col(p, args, token.pos); args[3] = row_index; args[4] = column_index; args[5] = row_count; @@ -610,14 +613,8 @@ gb_internal void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token low = lb_emit_conv(p, low, t_int); high = lb_emit_conv(p, high, t_int); - lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_i32, token.pos.line); - lbValue column = lb_const_int(p->module, t_i32, token.pos.column); - auto args = array_make(permanent_allocator(), 5); - args[0] = file; - args[1] = line; - args[2] = column; + lb_set_file_line_col(p, args, token.pos); args[3] = low; args[4] = high; @@ -632,16 +629,11 @@ gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue return; } - lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id)); - lbValue line = lb_const_int(p->module, t_i32, token.pos.line); - lbValue column = lb_const_int(p->module, t_i32, token.pos.column); high = lb_emit_conv(p, high, t_int); if (!lower_value_used) { auto args = array_make(permanent_allocator(), 5); - args[0] = file; - args[1] = line; - args[2] = column; + lb_set_file_line_col(p, args, token.pos); args[3] = high; args[4] = len; @@ -651,9 +643,7 @@ gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low = lb_emit_conv(p, low, t_int); auto args = array_make(permanent_allocator(), 6); - args[0] = file; - args[1] = line; - args[2] = column; + lb_set_file_line_col(p, args, token.pos); args[3] = low; args[4] = high; args[5] = len; diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 8910bd67a..aa425a9d5 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -771,9 +771,7 @@ gb_internal lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type auto args = array_make(permanent_allocator(), arg_count); args[0] = ok; - args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(m, t_i32, pos.line); - args[3] = lb_const_int(m, t_i32, pos.column); + lb_set_file_line_col(p, array_slice(args, 1, args.count), pos); if (!build_context.no_rtti) { args[4] = lb_typeid(m, src_type); @@ -847,9 +845,7 @@ gb_internal lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *ty auto args = array_make(permanent_allocator(), arg_count); args[0] = ok; - args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); - args[2] = lb_const_int(m, t_i32, pos.line); - args[3] = lb_const_int(m, t_i32, pos.column); + lb_set_file_line_col(p, array_slice(args, 1, args.count), pos); if (!build_context.no_rtti) { args[4] = any_typeid; From b86d2c30b600023ae643c4dcc2dcca10b08c29dc Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 5 Feb 2025 20:16:17 +0100 Subject: [PATCH 08/10] fix odin report macos version reporting unknown when release isn't a 3 point --- src/bug_report.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bug_report.cpp b/src/bug_report.cpp index ca5d0a395..c44c4be33 100644 --- a/src/bug_report.cpp +++ b/src/bug_report.cpp @@ -532,9 +532,9 @@ gb_internal void report_os_info() { return; } - uint32_t major, minor, patch; + uint32_t major, minor, patch = 0; - if (sscanf(cast(const char *)sw_vers, "%u.%u.%u", &major, &minor, &patch) != 3) { + if (sscanf(cast(const char *)sw_vers, "%u.%u.%u", &major, &minor, &patch) < 1) { gb_printf("macOS Unknown\n"); return; } From 80d09774b428f1201f550dee16d3104010260fc5 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 6 Feb 2025 19:15:12 +0100 Subject: [PATCH 09/10] fix not using RTLD_LOCAL on darwin --- core/dynlib/lib_unix.odin | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/dynlib/lib_unix.odin b/core/dynlib/lib_unix.odin index 50ab1acc8..1a6a737a4 100644 --- a/core/dynlib/lib_unix.odin +++ b/core/dynlib/lib_unix.odin @@ -13,6 +13,8 @@ _load_library :: proc(path: string, global_symbols: bool, allocator: runtime.All flags := posix.RTLD_Flags{.NOW} if global_symbols { flags += {.GLOBAL} + } else { + flags += posix.RTLD_LOCAL } cpath := strings.clone_to_cstring(path, allocator) From 1053ec30518486e3feb523d1a37e814ce992e79c Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 6 Feb 2025 20:42:41 +0100 Subject: [PATCH 10/10] make corrected linkage with -use-separate-modules apply hidden visibility Fixes #4798 The DLL was using the type info of the host/exe, causing crashes. This PR tries fixing by applying hidden visibility to these corrected symbols which makes sure that the DLL can't see the type table of the host/exe. --- src/llvm_backend.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 29fa67f3f..0896ea8c7 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -169,11 +169,17 @@ gb_internal void lb_correct_entity_linkage(lbGenerator *gen) { other_global = LLVMGetNamedGlobal(ec.other_module->mod, ec.cname); if (other_global) { LLVMSetLinkage(other_global, LLVMWeakAnyLinkage); + if (!ec.e->Variable.is_export) { + LLVMSetVisibility(other_global, LLVMHiddenVisibility); + } } } else if (ec.e->kind == Entity_Procedure) { other_global = LLVMGetNamedFunction(ec.other_module->mod, ec.cname); if (other_global) { LLVMSetLinkage(other_global, LLVMWeakAnyLinkage); + if (!ec.e->Procedure.is_export) { + LLVMSetVisibility(other_global, LLVMHiddenVisibility); + } } } }