commit ed3181f029809f8cd608f2c20b60d1b7c6e353e3 (tree)
parent 2a719ee6c598b7096060168a0e7c93ae3e244008
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Sat, 14 Jul 2018 11:33:13 -0400
Merge branch 'eduardosm-extern-return-small-struct'
Diffstat:
3 files changed, 19 insertions(+), 0 deletions(-)
diff --git 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
@@ -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
@@ -0,0 +1,14 @@
+const assert = @import("std").debug.assert;
+
+const S = extern struct {
+ x: i32,
+};
+
+extern fn ret_struct() S {
+ return S{ .x = 42 };
+}
+
+test "extern return small struct (bug 1230)" {
+ const s = ret_struct();
+ assert(s.x == 42);
+}