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) {
31303130 bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);
31313131 bool *covered_enum_fields;
31323132 bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);
3133 ZigLLVMDIEnumerator **di_enumerators;
31343133 if (create_enum_type) {
31353134 occupied_tag_values.init(field_count);
31363135
3137 di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
3138
31393136 ZigType *tag_int_type;
31403137 if (enum_type_node != nullptr) {
31413138 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) {
32793276 }
32803277
32813278 if (create_enum_type) {
3282 di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(union_field->name), i);
32833279 union_field->enum_field = &tag_type->data.enumeration.fields[i];
32843280 union_field->enum_field->name = union_field->name;
32853281 union_field->enum_field->decl_index = i;
......@@ -3346,6 +3342,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
33463342 gen_field_index += 1;
33473343 }
33483344 }
3345 heap::c_allocator.deallocate(is_zero_bits, field_count);
33493346
33503347 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) {
34133410 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
34143411 }
34153412 }
3413 heap::c_allocator.deallocate(covered_enum_fields, tag_type->data.enumeration.src_field_count);
34163414 }
34173415
34183416 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
43844384 }
43854385 }
43864386 LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false);
4387 heap::c_allocator.deallocate(field_types, field_count);
43874388 LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0);
43884389
43894390 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
43984399 gen_assign_raw(g, arg_ptr, get_pointer_to_type(g, gen_param_types.at(arg_i), true),
43994400 gen_param_values.at(arg_i));
44004401 }
4402 gen_param_types.deinit();
44014403
44024404 if (instruction->modifier == CallModifierAsync) {
44034405 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
......@@ -4475,6 +4477,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
44754477 LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
44764478 return LLVMBuildLoad(g->builder, result_ptr, "");
44774479 }
4480 } else {
4481 gen_param_types.deinit();
44784482 }
44794483
44804484 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
47924796 ret_type = get_llvm_type(g, instruction->base.value->type);
47934797 }
47944798 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
47964801 bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0);
47974802 LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template),
47984803 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;
48014808}
48024809
48034810static 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
50505057 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
50515058 }
50525059 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);
50535062 return phi;
50545063}
50555064
......@@ -7472,10 +7481,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
74727481 }
74737482 }
74747483 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,
74767485 type_entry->data.structure.layout == ContainerLayoutPacked);
7486 heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count);
7487 return unnamed_struct;
74777488 } 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;
74797492 }
74807493 }
74817494 case ZigTypeIdArray:
......@@ -7500,9 +7513,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
75007513 values[len] = gen_const_val(g, type_entry->data.array.sentinel, "");
75017514 }
75027515 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;
75047519 } 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;
75067523 }
75077524 }
75087525 case ConstArraySpecialBuf: {
......@@ -7524,7 +7541,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
75247541 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
75257542 values[i] = gen_const_val(g, elem_value, "");
75267543 }
7527 return LLVMConstVector(values, len);
7544 LLVMValueRef vector = LLVMConstVector(values, len);
7545 heap::c_allocator.deallocate(values, len);
7546 return vector;
75287547 }
75297548 case ConstArraySpecialBuf: {
75307549 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
75337552 for (uint64_t i = 0; i < len; i += 1) {
75347553 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
75357554 }
7536 return LLVMConstVector(values, len);
7555 LLVMValueRef vector = LLVMConstVector(values, len);
7556 heap::c_allocator.deallocate(values, len);
7557 return vector;
75377558 }
75387559 }
75397560 zig_unreachable();
......@@ -7755,6 +7776,7 @@ static void generate_error_name_table(CodeGen *g) {
77557776 }
77567777
77577778 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
77597781 g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),
77607782 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
96569656 ScopeRuntime *scope_runtime = runtime_scopes.at(i);
96579657 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
96589658 }
9659 runtime_scopes.deinit();
96599660
96609661 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
96619662 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
2159421595 predecessor->instruction_list.append(instrs_to_move.pop());
2159521596 }
2159621597 predecessor->instruction_list.append(branch_instruction);
21598 instrs_to_move.deinit();
2159721599 }
2159821600 }
2159921601
......@@ -21644,7 +21646,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2164421646 }
2164521647
2164621648 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;
2164821653 }
2164921654
2165021655 ZigType *resolved_type = nullptr;
......@@ -24207,6 +24212,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2420724212 first_non_const_instruction = result_loc;
2420824213 }
2420924214 }
24215 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
2421024216 if (any_missing)
2421124217 return ira->codegen->invalid_inst_gen;
2421224218
......@@ -24222,6 +24228,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2422224228 }
2422324229 }
2422424230
24231 const_ptrs.deinit();
2422524232 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
2422624233
2422724234 if (is_comptime && !instr_is_comptime(result)) {
......@@ -30184,6 +30191,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
3018430191 buf_write_value_bytes(ira->codegen, buf, val);
3018530192 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
3018630193 return ira->codegen->invalid_inst_gen;
30194 heap::c_allocator.deallocate(buf, src_size_bytes);
3018730195 return result;
3018830196 }
3018930197
......@@ -31221,6 +31229,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
3122131229 ira->codegen->is_big_endian,
3122231230 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);
3122431234 return result;
3122531235 }
3122631236
src/stage1/os.cpp+1
......@@ -605,6 +605,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
605605
606606 Buf return_value = BUF_INIT;
607607 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
608 heap::c_allocator.deallocate(result_ptr, result_len);
608609 return return_value;
609610}
610611#endif