Skip to content

Commit bced3fb

Browse files
committed
codegen for get_implicit_allocator instruction
See #727
1 parent 93cbd4e commit bced3fb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/codegen.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
25682568
}
25692569
}
25702570

2571+
static bool get_prefix_arg_err_ret_stack(CodeGen *g, TypeTableEntry *src_return_type) {
2572+
return g->have_err_ret_tracing &&
2573+
(src_return_type->id == TypeTableEntryIdErrorUnion || src_return_type->id == TypeTableEntryIdErrorSet);
2574+
}
2575+
25712576
static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
25722577
LLVMValueRef fn_val;
25732578
TypeTableEntry *fn_type;
@@ -2587,7 +2592,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
25872592

25882593
bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) &&
25892594
calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc);
2590-
bool prefix_arg_err_ret_stack = g->have_err_ret_tracing && (src_return_type->id == TypeTableEntryIdErrorUnion || src_return_type->id == TypeTableEntryIdErrorSet);
2595+
bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, src_return_type);
25912596
size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0);
25922597
bool is_var_args = fn_type_id->is_var_args;
25932598
LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
@@ -3178,8 +3183,13 @@ static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrIns
31783183
return nullptr;
31793184
}
31803185

3181-
static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable, IrInstructionGetImplicitAllocator *instruction) {
3182-
zig_panic("TODO ir_render_get_implicit_allocator");
3186+
static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable,
3187+
IrInstructionGetImplicitAllocator *instruction)
3188+
{
3189+
TypeTableEntry *src_return_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
3190+
bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, src_return_type);
3191+
size_t allocator_arg_index = prefix_arg_err_ret_stack ? 1 : 0;
3192+
return LLVMGetParam(g->cur_fn_val, allocator_arg_index);
31833193
}
31843194

31853195
static LLVMAtomicOrdering to_LLVMAtomicOrdering(AtomicOrder atomic_order) {

0 commit comments

Comments
 (0)