From b3a4ec1bd209c022445b6f70385b3f88517e72f9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Jun 2019 16:04:04 -0400 Subject: [PATCH] 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 } ``` --- src/codegen.cpp | 3 ++- src/ir.cpp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index beee67888..a035c6b33 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3564,7 +3564,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable, IrInstructionReturnPtr *instruction) { - assert(g->cur_ret_ptr != nullptr || !type_has_bits(instruction->base.value.type)); + src_assert(g->cur_ret_ptr != nullptr || !type_has_bits(instruction->base.value.type), + instruction->base.source_node); return g->cur_ret_ptr; } diff --git a/src/ir.cpp b/src/ir.cpp index df7a59360..b3d5109e9 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14866,7 +14866,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s } case ResultLocIdReturn: { bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; - if (is_comptime) return nullptr; + if (is_comptime) + return nullptr; + if (!type_has_bits(ira->explicit_return_type) || !handle_is_ptr(ira->explicit_return_type)) + return nullptr; + ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); result_loc->written = true; result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);