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...@@ -3166,6 +3166,10 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3166 return nullptr;3166 return nullptr;
3167 } else if (first_arg_ret) {3167 } else if (first_arg_ret) {
3168 return instruction->tmp_ptr;3168 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;
3169 } else {3173 } else {
3170 return result;3174 return result;
3171 }3175 }
test/behavior.zig+1
...@@ -9,6 +9,7 @@ comptime {...@@ -9,6 +9,7 @@ comptime {
9 _ = @import("cases/bitcast.zig");9 _ = @import("cases/bitcast.zig");
10 _ = @import("cases/bool.zig");10 _ = @import("cases/bool.zig");
11 _ = @import("cases/bugs/1111.zig");11 _ = @import("cases/bugs/1111.zig");
12 _ = @import("cases/bugs/1230.zig");
12 _ = @import("cases/bugs/394.zig");13 _ = @import("cases/bugs/394.zig");
13 _ = @import("cases/bugs/655.zig");14 _ = @import("cases/bugs/655.zig");
14 _ = @import("cases/bugs/656.zig");15 _ = @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}