From: Brendan Hansen Date: Tue, 8 Dec 2020 17:05:00 +0000 (-0600) Subject: nasty bugfix when returning bools X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=28b661df3220872aea0d09261af3f082cb90f65e;p=onyx.git nasty bugfix when returning bools It used to mess up the stack and in unforgiving environments, i.e. wasmtime or wasmer, it caused misaligned reads resulting in undefined behaviour. --- diff --git a/core/file.onyx b/core/file.onyx index 7ec1d47b..c107ddd8 100644 --- a/core/file.onyx +++ b/core/file.onyx @@ -107,7 +107,7 @@ get_contents :: proc { proc (path: string) -> string { tmp_file: File; - if !open(^tmp_file, path, OpenMode.Read) do return ""; + if !open(^tmp_file, path, OpenMode.Read) do return string.{ null, 0 }; defer close(tmp_file); return get_contents(tmp_file); diff --git a/core/sys/js.onyx b/core/sys/js.onyx index 83b2dbd0..e09f55cb 100644 --- a/core/sys/js.onyx +++ b/core/sys/js.onyx @@ -13,12 +13,12 @@ proc () #export "_start" { context.allocator = allocator.heap_allocator; context.temp_allocator = allocator.heap_allocator; - stdio_init(); - args : [] cstring; args.data = null; args.count = 0; + stdio_init(); + main.main(args); print_buffer_flush(); diff --git a/onyx b/onyx index d33443f9..a01c7ce4 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxwasm.c b/src/onyxwasm.c index baea9823..a711607e 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -1413,14 +1413,15 @@ EMIT_FUNC(call, AstCall* call) { CallingConvention cc = type_function_get_cc(call->callee->type); assert(cc != CC_Undefined); + b32 needs_stack = (cc == CC_Return_Stack) || (stack_grow_amm > 0); + Type* return_type = call->callee->type->Function.return_type; u32 return_size = type_size_of(return_type); u32 return_align = type_alignment_of(return_type); bh_align(return_size, return_align); - stack_grow_amm += return_size; - - b32 needs_stack = (cc == CC_Return_Stack) || (stack_grow_amm > 0); + if (cc == CC_Return_Stack) + stack_grow_amm += return_size; if (needs_stack) { WID(WI_GLOBAL_GET, stack_top_idx);