authorgravatar for esm@eduardosm.netEduardo Sánchez Muñoz <esm@eduardosm.net> 2018-07-14 01:12:23+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-14 11:33:01-04:00
log722b9b9e595027e76ab4255f13ad0eca539358ac
tree160a103df662ed026ade45dc536907f022da54cc
parent2a719ee6c598b7096060168a0e7c93ae3e244008

codegen: Store returned value if type is 'handle_is_ptr' and function is not 'first_arg_ret'.

Seems to fix #1230, includes test.

3 files changed, 16 insertions(+), 0 deletions(-)

src/codegen.cpp+4
......@@ -3166,6 +3166,10 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
31663166 return nullptr;
31673167 } else if (first_arg_ret) {
31683168 return instruction->tmp_ptr;
3169 } else if (handle_is_ptr(src_return_type)) {
3170 auto store_instr = LLVMBuildStore(g->builder, result, instruction->tmp_ptr);
3171 LLVMSetAlignment(store_instr, LLVMGetAlignment(instruction->tmp_ptr));
3172 return instruction->tmp_ptr;
31693173 } else {
31703174 return result;
31713175 }
test/behavior.zig+1
......@@ -9,6 +9,7 @@ comptime {
99 _ = @import("cases/bitcast.zig");
1010 _ = @import("cases/bool.zig");
1111 _ = @import("cases/bugs/1111.zig");
12 _ = @import("cases/bugs/1230.zig");
1213 _ = @import("cases/bugs/394.zig");
1314 _ = @import("cases/bugs/655.zig");
1415 _ = @import("cases/bugs/656.zig");
test/cases/bugs/1230.zig created+11
......@@ -0,0 +1,11 @@
1const S = extern struct {
2 x: i32,
3};
4
5extern fn ret_struct() S {
6 return S { .x = 0 };
7}
8
9test "extern return small struct (bug 1230)" {
10 const s = ret_struct();
11}