mirror of
https://github.com/ziglang/zig.git
synced 2025-02-10 22:50:18 +00:00
Merge pull request #6472 from alexnask/add_some_frees
Add a few missing deallocations of temporaries to stage1
This commit is contained in:
commit
939b4860ef
@ -3130,12 +3130,9 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
|
||||
bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);
|
||||
bool *covered_enum_fields;
|
||||
bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);
|
||||
ZigLLVMDIEnumerator **di_enumerators;
|
||||
if (create_enum_type) {
|
||||
occupied_tag_values.init(field_count);
|
||||
|
||||
di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
|
||||
|
||||
ZigType *tag_int_type;
|
||||
if (enum_type_node != nullptr) {
|
||||
tag_int_type = analyze_type_expr(g, scope, enum_type_node);
|
||||
@ -3279,7 +3276,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
|
||||
}
|
||||
|
||||
if (create_enum_type) {
|
||||
di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(union_field->name), i);
|
||||
union_field->enum_field = &tag_type->data.enumeration.fields[i];
|
||||
union_field->enum_field->name = union_field->name;
|
||||
union_field->enum_field->decl_index = i;
|
||||
@ -3346,6 +3342,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
|
||||
gen_field_index += 1;
|
||||
}
|
||||
}
|
||||
heap::c_allocator.deallocate(is_zero_bits, field_count);
|
||||
|
||||
bool src_have_tag = is_auto_enum || is_explicit_enum;
|
||||
|
||||
@ -3413,6 +3410,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
|
||||
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
|
||||
}
|
||||
}
|
||||
heap::c_allocator.deallocate(covered_enum_fields, tag_type->data.enumeration.src_field_count);
|
||||
}
|
||||
|
||||
if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) {
|
||||
|
@ -4384,6 +4384,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
|
||||
}
|
||||
}
|
||||
LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false);
|
||||
heap::c_allocator.deallocate(field_types, field_count);
|
||||
LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0);
|
||||
|
||||
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
|
||||
gen_assign_raw(g, arg_ptr, get_pointer_to_type(g, gen_param_types.at(arg_i), true),
|
||||
gen_param_values.at(arg_i));
|
||||
}
|
||||
gen_param_types.deinit();
|
||||
|
||||
if (instruction->modifier == CallModifierAsync) {
|
||||
gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
|
||||
@ -4475,6 +4477,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
|
||||
LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
|
||||
return LLVMBuildLoad(g->builder, result_ptr, "");
|
||||
}
|
||||
} else {
|
||||
gen_param_types.deinit();
|
||||
}
|
||||
|
||||
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
|
||||
ret_type = get_llvm_type(g, instruction->base.value->type);
|
||||
}
|
||||
LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);
|
||||
heap::c_allocator.deallocate(param_types, input_and_output_count);
|
||||
|
||||
bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0);
|
||||
LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template),
|
||||
buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT);
|
||||
|
||||
return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
|
||||
LLVMValueRef built_call = LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
|
||||
heap::c_allocator.deallocate(param_values, input_and_output_count);
|
||||
return built_call;
|
||||
}
|
||||
|
||||
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
|
||||
incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
|
||||
}
|
||||
LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count);
|
||||
heap::c_allocator.deallocate(incoming_values, instruction->incoming_count);
|
||||
heap::c_allocator.deallocate(incoming_blocks, instruction->incoming_count);
|
||||
return phi;
|
||||
}
|
||||
|
||||
@ -7472,10 +7481,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
|
||||
}
|
||||
}
|
||||
if (make_unnamed_struct) {
|
||||
return LLVMConstStruct(fields, type_entry->data.structure.gen_field_count,
|
||||
LLVMValueRef unnamed_struct = LLVMConstStruct(fields, type_entry->data.structure.gen_field_count,
|
||||
type_entry->data.structure.layout == ContainerLayoutPacked);
|
||||
heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count);
|
||||
return unnamed_struct;
|
||||
} else {
|
||||
return LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count);
|
||||
LLVMValueRef named_struct = LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count);
|
||||
heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count);
|
||||
return named_struct;
|
||||
}
|
||||
}
|
||||
case ZigTypeIdArray:
|
||||
@ -7500,9 +7513,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
|
||||
values[len] = gen_const_val(g, type_entry->data.array.sentinel, "");
|
||||
}
|
||||
if (make_unnamed_struct) {
|
||||
return LLVMConstStruct(values, full_len, true);
|
||||
LLVMValueRef unnamed_struct = LLVMConstStruct(values, full_len, true);
|
||||
heap::c_allocator.deallocate(values, full_len);
|
||||
return unnamed_struct;
|
||||
} else {
|
||||
return LLVMConstArray(element_type_ref, values, (unsigned)full_len);
|
||||
LLVMValueRef array = LLVMConstArray(element_type_ref, values, (unsigned)full_len);
|
||||
heap::c_allocator.deallocate(values, full_len);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
case ConstArraySpecialBuf: {
|
||||
@ -7524,7 +7541,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
|
||||
ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
|
||||
values[i] = gen_const_val(g, elem_value, "");
|
||||
}
|
||||
return LLVMConstVector(values, len);
|
||||
LLVMValueRef vector = LLVMConstVector(values, len);
|
||||
heap::c_allocator.deallocate(values, len);
|
||||
return vector;
|
||||
}
|
||||
case ConstArraySpecialBuf: {
|
||||
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
|
||||
for (uint64_t i = 0; i < len; i += 1) {
|
||||
values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
|
||||
}
|
||||
return LLVMConstVector(values, len);
|
||||
LLVMValueRef vector = LLVMConstVector(values, len);
|
||||
heap::c_allocator.deallocate(values, len);
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
zig_unreachable();
|
||||
@ -7755,6 +7776,7 @@ static void generate_error_name_table(CodeGen *g) {
|
||||
}
|
||||
|
||||
LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length);
|
||||
heap::c_allocator.deallocate(values, g->errors_by_index.length);
|
||||
|
||||
g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),
|
||||
get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table"))));
|
||||
|
@ -9656,6 +9656,7 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN
|
||||
ScopeRuntime *scope_runtime = runtime_scopes.at(i);
|
||||
ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
|
||||
}
|
||||
runtime_scopes.deinit();
|
||||
|
||||
IrBasicBlockSrc *dest_block = loop_scope->continue_block;
|
||||
if (!ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, nullptr, nullptr))
|
||||
@ -21594,6 +21595,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
|
||||
predecessor->instruction_list.append(instrs_to_move.pop());
|
||||
}
|
||||
predecessor->instruction_list.append(branch_instruction);
|
||||
instrs_to_move.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -21644,7 +21646,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
|
||||
}
|
||||
|
||||
if (new_incoming_blocks.length == 1) {
|
||||
return new_incoming_values.at(0);
|
||||
IrInstGen *incoming_value = new_incoming_values.at(0);
|
||||
new_incoming_blocks.deinit();
|
||||
new_incoming_values.deinit();
|
||||
return incoming_value;
|
||||
}
|
||||
|
||||
ZigType *resolved_type = nullptr;
|
||||
@ -24207,6 +24212,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
|
||||
first_non_const_instruction = result_loc;
|
||||
}
|
||||
}
|
||||
heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
|
||||
if (any_missing)
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
@ -24222,6 +24228,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
|
||||
}
|
||||
}
|
||||
|
||||
const_ptrs.deinit();
|
||||
IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
|
||||
|
||||
if (is_comptime && !instr_is_comptime(result)) {
|
||||
@ -30184,6 +30191,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
|
||||
buf_write_value_bytes(ira->codegen, buf, val);
|
||||
if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
heap::c_allocator.deallocate(buf, src_size_bytes);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -31221,6 +31229,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
|
||||
ira->codegen->is_big_endian,
|
||||
int_type->data.integral.is_signed);
|
||||
|
||||
heap::c_allocator.deallocate(comptime_buf, buf_size);
|
||||
heap::c_allocator.deallocate(result_buf, buf_size);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -605,6 +605,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
|
||||
|
||||
Buf return_value = BUF_INIT;
|
||||
buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
|
||||
heap::c_allocator.deallocate(result_ptr, result_len);
|
||||
return return_value;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user