@@ -2242,8 +2242,12 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
2242
2242
ZigType *return_type = return_instruction->value ->value .type ;
2243
2243
2244
2244
if (want_first_arg_sret (g, &g->cur_fn ->type_entry ->data .fn .fn_type_id )) {
2245
- assert (g->cur_ret_ptr );
2246
- gen_assign_raw (g, g->cur_ret_ptr , get_pointer_to_type (g, return_type, false ), value);
2245
+ // Assume that the result location mechanism populated the value,
2246
+ // unless the value is a comptime const.
2247
+ if (return_instruction->value ->value .special == ConstValSpecialStatic) {
2248
+ assert (g->cur_ret_ptr );
2249
+ gen_assign_raw (g, g->cur_ret_ptr , get_pointer_to_type (g, return_type, false ), value);
2250
+ }
2247
2251
LLVMBuildRetVoid (g->builder );
2248
2252
} else if (handle_is_ptr (return_type)) {
2249
2253
LLVMValueRef by_val_value = gen_load_untyped (g, value, 0 , false , " " );
@@ -5087,6 +5091,13 @@ static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstr
5087
5091
return LLVMBuildCall (g->builder , fn_val, &op, 1 , " " );
5088
5092
}
5089
5093
5094
+ static LLVMValueRef ir_render_result_return (CodeGen *g, IrExecutable *executable,
5095
+ IrInstructionResultReturn *instruction)
5096
+ {
5097
+ assert (g->cur_ret_ptr != nullptr );
5098
+ return g->cur_ret_ptr ;
5099
+ }
5100
+
5090
5101
static void set_debug_location (CodeGen *g, IrInstruction *instruction) {
5091
5102
AstNode *source_node = instruction->source_node ;
5092
5103
Scope *scope = instruction->scope ;
@@ -5326,9 +5337,9 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5326
5337
return ir_render_mark_err_ret_trace_ptr (g, executable, (IrInstructionMarkErrRetTracePtr *)instruction);
5327
5338
case IrInstructionIdSqrt:
5328
5339
return ir_render_sqrt (g, executable, (IrInstructionSqrt *)instruction);
5329
- case IrInstructionIdResultErrorUnionPayload:
5330
- zig_panic (" TODO" );
5331
5340
case IrInstructionIdResultReturn:
5341
+ return ir_render_result_return (g, executable, (IrInstructionResultReturn *)instruction);
5342
+ case IrInstructionIdResultErrorUnionPayload:
5332
5343
zig_panic (" TODO" );
5333
5344
case IrInstructionIdResultSliceToBytes:
5334
5345
zig_panic (" TODO" );
0 commit comments