From 5354d1f5fc496beb8313488ea1690e02e9c630fa Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 13 Jul 2018 12:34:42 -0400 Subject: allow == for comparing optional pointers closes #658 --- src/codegen.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 54e2da7d61..3f54c120b4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2249,10 +2249,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); } else if (type_entry->id == TypeTableEntryIdEnum || type_entry->id == TypeTableEntryIdErrorSet || - type_entry->id == TypeTableEntryIdPointer || type_entry->id == TypeTableEntryIdBool || - type_entry->id == TypeTableEntryIdPromise || - type_entry->id == TypeTableEntryIdFn) + get_codegen_ptr_type(type_entry) != nullptr) { LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false); return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); -- cgit v1.2.3 From 722b9b9e595027e76ab4255f13ad0eca539358ac Mon Sep 17 00:00:00 2001 From: Eduardo Sánchez Muñoz Date: Sat, 14 Jul 2018 01:12:23 +0200 Subject: codegen: Store returned value if type is 'handle_is_ptr' and function is not 'first_arg_ret'. Seems to fix #1230, includes test. --- src/codegen.cpp | 4 ++++ test/behavior.zig | 1 + test/cases/bugs/1230.zig | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 test/cases/bugs/1230.zig (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 3f54c120b4..0bcc211164 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3166,6 +3166,10 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr return nullptr; } else if (first_arg_ret) { return instruction->tmp_ptr; + } else if (handle_is_ptr(src_return_type)) { + auto store_instr = LLVMBuildStore(g->builder, result, instruction->tmp_ptr); + LLVMSetAlignment(store_instr, LLVMGetAlignment(instruction->tmp_ptr)); + return instruction->tmp_ptr; } else { return result; } diff --git a/test/behavior.zig b/test/behavior.zig index 450dded56c..21b1c597e1 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -9,6 +9,7 @@ comptime { _ = @import("cases/bitcast.zig"); _ = @import("cases/bool.zig"); _ = @import("cases/bugs/1111.zig"); + _ = @import("cases/bugs/1230.zig"); _ = @import("cases/bugs/394.zig"); _ = @import("cases/bugs/655.zig"); _ = @import("cases/bugs/656.zig"); diff --git a/test/cases/bugs/1230.zig b/test/cases/bugs/1230.zig new file mode 100644 index 0000000000..3fd22357d7 --- /dev/null +++ b/test/cases/bugs/1230.zig @@ -0,0 +1,11 @@ +const S = extern struct { + x: i32, +}; + +extern fn ret_struct() S { + return S { .x = 0 }; +} + +test "extern return small struct (bug 1230)" { + const s = ret_struct(); +} -- cgit v1.2.3