| ... | @@ -4384,6 +4384,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn | ... | @@ -4384,6 +4384,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn |
| 4384 | } | 4384 | } |
| 4385 | } | 4385 | } |
| 4386 | LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false); | 4386 | LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false); |
| | 4387 | heap::c_allocator.deallocate(field_types, field_count); |
| 4387 | LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0); | 4388 | LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0); |
| 4388 | | 4389 | |
| 4389 | casted_frame = LLVMBuildBitCast(g->builder, frame_result_loc, ptr_frame_with_args_type, ""); | 4390 | casted_frame = LLVMBuildBitCast(g->builder, frame_result_loc, ptr_frame_with_args_type, ""); |
| ... | @@ -4398,6 +4399,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn | ... | @@ -4398,6 +4399,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn |
| 4398 | gen_assign_raw(g, arg_ptr, get_pointer_to_type(g, gen_param_types.at(arg_i), true), | 4399 | gen_assign_raw(g, arg_ptr, get_pointer_to_type(g, gen_param_types.at(arg_i), true), |
| 4399 | gen_param_values.at(arg_i)); | 4400 | gen_param_values.at(arg_i)); |
| 4400 | } | 4401 | } |
| | 4402 | gen_param_types.deinit(); |
| 4401 | | 4403 | |
| 4402 | if (instruction->modifier == CallModifierAsync) { | 4404 | if (instruction->modifier == CallModifierAsync) { |
| 4403 | gen_resume(g, fn_val, frame_result_loc, ResumeIdCall); | 4405 | gen_resume(g, fn_val, frame_result_loc, ResumeIdCall); |
| ... | @@ -4475,6 +4477,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn | ... | @@ -4475,6 +4477,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn |
| 4475 | LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, ""); | 4477 | LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, ""); |
| 4476 | return LLVMBuildLoad(g->builder, result_ptr, ""); | 4478 | return LLVMBuildLoad(g->builder, result_ptr, ""); |
| 4477 | } | 4479 | } |
| | 4480 | } else { |
| | 4481 | gen_param_types.deinit(); |
| 4478 | } | 4482 | } |
| 4479 | | 4483 | |
| 4480 | if (instruction->new_stack == nullptr || instruction->is_async_call_builtin) { | 4484 | if (instruction->new_stack == nullptr || instruction->is_async_call_builtin) { |
| ... | @@ -4792,12 +4796,15 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I | ... | @@ -4792,12 +4796,15 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I |
| 4792 | ret_type = get_llvm_type(g, instruction->base.value->type); | 4796 | ret_type = get_llvm_type(g, instruction->base.value->type); |
| 4793 | } | 4797 | } |
| 4794 | LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false); | 4798 | LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false); |
| | 4799 | heap::c_allocator.deallocate(param_types, input_and_output_count); |
| 4795 | | 4800 | |
| 4796 | bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0); | 4801 | bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0); |
| 4797 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template), | 4802 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template), |
| 4798 | buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT); | 4803 | buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT); |
| 4799 | | 4804 | |
| 4800 | return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, ""); | 4805 | LLVMValueRef built_call = LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, ""); |
| | 4806 | heap::c_allocator.deallocate(param_values, input_and_output_count); |
| | 4807 | return built_call; |
| 4801 | } | 4808 | } |
| 4802 | | 4809 | |
| 4803 | static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) { | 4810 | static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) { |
| ... | @@ -5050,6 +5057,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns | ... | @@ -5050,6 +5057,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns |
| 5050 | incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block; | 5057 | incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block; |
| 5051 | } | 5058 | } |
| 5052 | LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count); | 5059 | LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count); |
| | 5060 | heap::c_allocator.deallocate(incoming_values, instruction->incoming_count); |
| | 5061 | heap::c_allocator.deallocate(incoming_blocks, instruction->incoming_count); |
| 5053 | return phi; | 5062 | return phi; |
| 5054 | } | 5063 | } |
| 5055 | | 5064 | |
| ... | @@ -7472,10 +7481,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n | ... | @@ -7472,10 +7481,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n |
| 7472 | } | 7481 | } |
| 7473 | } | 7482 | } |
| 7474 | if (make_unnamed_struct) { | 7483 | if (make_unnamed_struct) { |
| 7475 | return LLVMConstStruct(fields, type_entry->data.structure.gen_field_count, | 7484 | LLVMValueRef unnamed_struct = LLVMConstStruct(fields, type_entry->data.structure.gen_field_count, |
| 7476 | type_entry->data.structure.layout == ContainerLayoutPacked); | 7485 | type_entry->data.structure.layout == ContainerLayoutPacked); |
| | 7486 | heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count); |
| | 7487 | return unnamed_struct; |
| 7477 | } else { | 7488 | } else { |
| 7478 | return LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count); | 7489 | LLVMValueRef named_struct = LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count); |
| | 7490 | heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count); |
| | 7491 | return named_struct; |
| 7479 | } | 7492 | } |
| 7480 | } | 7493 | } |
| 7481 | case ZigTypeIdArray: | 7494 | case ZigTypeIdArray: |
| ... | @@ -7500,9 +7513,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n | ... | @@ -7500,9 +7513,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n |
| 7500 | values[len] = gen_const_val(g, type_entry->data.array.sentinel, ""); | 7513 | values[len] = gen_const_val(g, type_entry->data.array.sentinel, ""); |
| 7501 | } | 7514 | } |
| 7502 | if (make_unnamed_struct) { | 7515 | if (make_unnamed_struct) { |
| 7503 | return LLVMConstStruct(values, full_len, true); | 7516 | LLVMValueRef unnamed_struct = LLVMConstStruct(values, full_len, true); |
| | 7517 | heap::c_allocator.deallocate(values, full_len); |
| | 7518 | return unnamed_struct; |
| 7504 | } else { | 7519 | } else { |
| 7505 | return LLVMConstArray(element_type_ref, values, (unsigned)full_len); | 7520 | LLVMValueRef array = LLVMConstArray(element_type_ref, values, (unsigned)full_len); |
| | 7521 | heap::c_allocator.deallocate(values, full_len); |
| | 7522 | return array; |
| 7506 | } | 7523 | } |
| 7507 | } | 7524 | } |
| 7508 | case ConstArraySpecialBuf: { | 7525 | case ConstArraySpecialBuf: { |
| ... | @@ -7524,7 +7541,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n | ... | @@ -7524,7 +7541,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n |
| 7524 | ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; | 7541 | ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i]; |
| 7525 | values[i] = gen_const_val(g, elem_value, ""); | 7542 | values[i] = gen_const_val(g, elem_value, ""); |
| 7526 | } | 7543 | } |
| 7527 | return LLVMConstVector(values, len); | 7544 | LLVMValueRef vector = LLVMConstVector(values, len); |
| | 7545 | heap::c_allocator.deallocate(values, len); |
| | 7546 | return vector; |
| 7528 | } | 7547 | } |
| 7529 | case ConstArraySpecialBuf: { | 7548 | case ConstArraySpecialBuf: { |
| 7530 | Buf *buf = const_val->data.x_array.data.s_buf; | 7549 | Buf *buf = const_val->data.x_array.data.s_buf; |
| ... | @@ -7533,7 +7552,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n | ... | @@ -7533,7 +7552,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n |
| 7533 | for (uint64_t i = 0; i < len; i += 1) { | 7552 | for (uint64_t i = 0; i < len; i += 1) { |
| 7534 | values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false); | 7553 | values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false); |
| 7535 | } | 7554 | } |
| 7536 | return LLVMConstVector(values, len); | 7555 | LLVMValueRef vector = LLVMConstVector(values, len); |
| | 7556 | heap::c_allocator.deallocate(values, len); |
| | 7557 | return vector; |
| 7537 | } | 7558 | } |
| 7538 | } | 7559 | } |
| 7539 | zig_unreachable(); | 7560 | zig_unreachable(); |
| ... | @@ -7755,6 +7776,7 @@ static void generate_error_name_table(CodeGen *g) { | ... | @@ -7755,6 +7776,7 @@ static void generate_error_name_table(CodeGen *g) { |
| 7755 | } | 7776 | } |
| 7756 | | 7777 | |
| 7757 | LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length); | 7778 | LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length); |
| | 7779 | heap::c_allocator.deallocate(values, g->errors_by_index.length); |
| 7758 | | 7780 | |
| 7759 | g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init), | 7781 | g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init), |
| 7760 | get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table")))); | 7782 | get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table")))); |