diff --git a/bootstrap/compiler.zig b/bootstrap/compiler.zig index 59d3901..98ef02a 100644 --- a/bootstrap/compiler.zig +++ b/bootstrap/compiler.zig @@ -3120,7 +3120,7 @@ fn worker_thread(thread_index: u32, cpu_count: *u32) void { } }, .llvm_generate_ir => { - if (thread.functions.length > 0) { + if (thread.functions.length > 0 or thread.global_variables.length > 0) { const context = LLVM.Context.create(); const module_name: []const u8 = "thread"; const module = LLVM.Module.create(module_name.ptr, module_name.len, context); diff --git a/retest/standalone/loop_return_if/main.nat b/retest/standalone/loop_return_if/main.nat new file mode 100644 index 0000000..9c521fc --- /dev/null +++ b/retest/standalone/loop_return_if/main.nat @@ -0,0 +1,21 @@ +>m: s32 = 2; +>n: s32 = 6; + +fn foo(arg: s32) s32 { + >i: s32 = 0; + loop (i < arg) { + if (i > 2) { + return i; + } + + i += 1; + } + + return 15; +} + +fn[cc(.c)] main[export]() s32 { + >a = foo(n); + >b = foo(n); + return (a - b) + (a - (m + 1)) + (b - (m + 1)); +}