authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-05 04:56:58-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-05 04:56:58-04:00
log939b4860ef2990ba453842033475a18f14a5b72e
treeb8ba4896d4a77f5892766d60a6394e34243d49aa
parent22b5e47839cf34c1e4a7c5e6dc256e041b4bf8fc
parent23cd3b33312ea5fcae32dcb6cd53cbd502361ce9
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6472 from alexnask/add_some_frees

Add a few missing deallocations of temporaries to stage1

4 files changed, 43 insertions(+), 12 deletions(-)

src/stage1/analyze.cpp+2-4
...@@ -3130,12 +3130,9 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3130,12 +3130,9 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3130 bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);3130 bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);
3131 bool *covered_enum_fields;3131 bool *covered_enum_fields;
3132 bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);3132 bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);
3133 ZigLLVMDIEnumerator **di_enumerators;
3134 if (create_enum_type) {3133 if (create_enum_type) {
3135 occupied_tag_values.init(field_count);3134 occupied_tag_values.init(field_count);
31363135
3137 di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
3138
3139 ZigType *tag_int_type;3136 ZigType *tag_int_type;
3140 if (enum_type_node != nullptr) {3137 if (enum_type_node != nullptr) {
3141 tag_int_type = analyze_type_expr(g, scope, enum_type_node);3138 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) {...@@ -3279,7 +3276,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3279 }3276 }
32803277
3281 if (create_enum_type) {3278 if (create_enum_type) {
3282 di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(union_field->name), i);
3283 union_field->enum_field = &tag_type->data.enumeration.fields[i];3279 union_field->enum_field = &tag_type->data.enumeration.fields[i];
3284 union_field->enum_field->name = union_field->name;3280 union_field->enum_field->name = union_field->name;
3285 union_field->enum_field->decl_index = i;3281 union_field->enum_field->decl_index = i;
...@@ -3346,6 +3342,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3346,6 +3342,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3346 gen_field_index += 1;3342 gen_field_index += 1;
3347 }3343 }
3348 }3344 }
3345 heap::c_allocator.deallocate(is_zero_bits, field_count);
33493346
3350 bool src_have_tag = is_auto_enum || is_explicit_enum;3347 bool src_have_tag = is_auto_enum || is_explicit_enum;
33513348
...@@ -3413,6 +3410,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3413,6 +3410,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3413 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3410 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
3414 }3411 }
3415 }3412 }
3413 heap::c_allocator.deallocate(covered_enum_fields, tag_type->data.enumeration.src_field_count);
3416 }3414 }
34173415
3418 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) {3416 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) {
src/stage1/codegen.cpp+29-7
...@@ -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);
43884389
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();
44014403
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 }
44794483
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);
47954800
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);
47994804
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}
48024809
4803static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {4810static 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}
50555064
...@@ -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 }
77567777
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);
77587780
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"))));
src/stage1/ir.cpp+11-1
...@@ -9656,6 +9656,7 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN...@@ -9656,6 +9656,7 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN
9656 ScopeRuntime *scope_runtime = runtime_scopes.at(i);9656 ScopeRuntime *scope_runtime = runtime_scopes.at(i);
9657 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));9657 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
9658 }9658 }
9659 runtime_scopes.deinit();
96599660
9660 IrBasicBlockSrc *dest_block = loop_scope->continue_block;9661 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
9661 if (!ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, nullptr, nullptr))9662 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...@@ -21594,6 +21595,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
21594 predecessor->instruction_list.append(instrs_to_move.pop());21595 predecessor->instruction_list.append(instrs_to_move.pop());
21595 }21596 }
21596 predecessor->instruction_list.append(branch_instruction);21597 predecessor->instruction_list.append(branch_instruction);
21598 instrs_to_move.deinit();
21597 }21599 }
21598 }21600 }
2159921601
...@@ -21644,7 +21646,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -21644,7 +21646,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
21644 }21646 }
2164521647
21646 if (new_incoming_blocks.length == 1) {21648 if (new_incoming_blocks.length == 1) {
21647 return new_incoming_values.at(0);21649 IrInstGen *incoming_value = new_incoming_values.at(0);
21650 new_incoming_blocks.deinit();
21651 new_incoming_values.deinit();
21652 return incoming_value;
21648 }21653 }
2164921654
21650 ZigType *resolved_type = nullptr;21655 ZigType *resolved_type = nullptr;
...@@ -24207,6 +24212,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -24207,6 +24212,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
24207 first_non_const_instruction = result_loc;24212 first_non_const_instruction = result_loc;
24208 }24213 }
24209 }24214 }
24215 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
24210 if (any_missing)24216 if (any_missing)
24211 return ira->codegen->invalid_inst_gen;24217 return ira->codegen->invalid_inst_gen;
2421224218
...@@ -24222,6 +24228,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -24222,6 +24228,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
24222 }24228 }
24223 }24229 }
2422424230
24231 const_ptrs.deinit();
24225 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);24232 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
2422624233
24227 if (is_comptime && !instr_is_comptime(result)) {24234 if (is_comptime && !instr_is_comptime(result)) {
...@@ -30184,6 +30191,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -30184,6 +30191,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
30184 buf_write_value_bytes(ira->codegen, buf, val);30191 buf_write_value_bytes(ira->codegen, buf, val);
30185 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))30192 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
30186 return ira->codegen->invalid_inst_gen;30193 return ira->codegen->invalid_inst_gen;
30194 heap::c_allocator.deallocate(buf, src_size_bytes);
30187 return result;30195 return result;
30188 }30196 }
3018930197
...@@ -31221,6 +31229,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -31221,6 +31229,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
31221 ira->codegen->is_big_endian,31229 ira->codegen->is_big_endian,
31222 int_type->data.integral.is_signed);31230 int_type->data.integral.is_signed);
3122331231
31232 heap::c_allocator.deallocate(comptime_buf, buf_size);
31233 heap::c_allocator.deallocate(result_buf, buf_size);
31224 return result;31234 return result;
31225 }31235 }
3122631236
src/stage1/os.cpp+1
...@@ -605,6 +605,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {...@@ -605,6 +605,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
605605
606 Buf return_value = BUF_INIT;606 Buf return_value = BUF_INIT;
607 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);607 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
608 heap::c_allocator.deallocate(result_ptr, result_len);
608 return return_value;609 return return_value;
609}610}
610#endif611#endif