authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 16:04:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 16:04:04-04:00
logb3a4ec1bd209c022445b6f70385b3f88517e72f9
tree7e94fb3e78bc209cc97ed48797bcde338beb6c07
parente1d14e73b5f9c7a8d1a92ccd36cb689d625faf57
signature Commit is signed but in an unrecognized format.

fix returning scalar values

```zig export fn entry1() i32 { return bar(); } ``` ```llvm define i32 @entry1() #2 !dbg !35 { Entry: %0 = call fastcc i32 @bar(), !dbg !39 ret i32 %0, !dbg !41 } ```

2 files changed, 7 insertions(+), 2 deletions(-)

src/codegen.cpp+2-1
...@@ -3564,7 +3564,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -3564,7 +3564,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
3564static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,3564static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3565 IrInstructionReturnPtr *instruction)3565 IrInstructionReturnPtr *instruction)
3566{3566{
3567 assert(g->cur_ret_ptr != nullptr || !type_has_bits(instruction->base.value.type));3567 src_assert(g->cur_ret_ptr != nullptr || !type_has_bits(instruction->base.value.type),
3568 instruction->base.source_node);
3568 return g->cur_ret_ptr;3569 return g->cur_ret_ptr;
3569}3570}
35703571
src/ir.cpp+5-1
...@@ -14866,7 +14866,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -14866,7 +14866,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
14866 }14866 }
14867 case ResultLocIdReturn: {14867 case ResultLocIdReturn: {
14868 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;14868 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;
14869 if (is_comptime) return nullptr;14869 if (is_comptime)
14870 return nullptr;
14871 if (!type_has_bits(ira->explicit_return_type) || !handle_is_ptr(ira->explicit_return_type))
14872 return nullptr;
14873
14870 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);14874 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
14871 result_loc->written = true;14875 result_loc->written = true;
14872 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);14876 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);