zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 46033a2128b09ed15f38f6ed2602bf80989a770f (tree)
parent 23bebdbcd51ac426f829713ce278b86ccaeb97f4
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Thu, 22 Dec 2016 00:46:17 -0500

pass void parameters test

Diffstat:
Msrc/analyze.cpp | 5++++-
Msrc/codegen.cpp | 3+++
Mtest/cases3/fn.zig | 11+++++++++++
Mtest/self_hosted.zig | 12------------
4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -2234,7 +2234,10 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope, param_decl->name, param_type, true, nullptr); var->src_arg_index = i; fn_table_entry->child_scope = var->child_scope; - fn_table_entry->variable_list.append(var); + + if (type_has_bits(param_type)) { + fn_table_entry->variable_list.append(var); + } if (fn_type->data.fn.gen_param_info) { var->gen_arg_index = fn_type->data.fn.gen_param_info[i].gen_index; diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -1650,6 +1650,9 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir } static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) { + if (!type_has_bits(instruction->base.type_entry)) + return nullptr; + LLVMTypeRef phi_type; if (handle_is_ptr(instruction->base.type_entry)) { phi_type = LLVMPointerType(instruction->base.type_entry->type_ref, 0); diff --git a/test/cases3/fn.zig b/test/cases3/fn.zig @@ -19,6 +19,17 @@ fn testLocVars(b: i32) { } +fn voidParameters() { + @setFnTest(this); + + voidFun(1, void{}, 2, {}); +} +fn voidFun(a: i32, b: void, c: i32, d: void) { + const v = b; + const vv: void = if (a == 1) {v} else {}; + assert(a + c == 3); + return vv; +} // TODO const assert = @import("std").debug.assert; diff --git a/test/self_hosted.zig b/test/self_hosted.zig @@ -17,18 +17,6 @@ const test_this = @import("cases/this.zig"); -fn voidParameters() { - @setFnTest(this); - - voidFun(1, void{}, 2, {}); -} -fn voidFun(a: i32, b: void, c: i32, d: void) { - const v = b; - const vv: void = if (a == 1) {v} else {}; - assert(a + c == 3); - return vv; -} - fn mutableLocalVariables() { @setFnTest(this, true);