authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-09-30 19:59:49+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-09-30 19:59:49+03:00
log82f0ede3ad4150a80ab745419664f1dce4a6be9c
treed939c1a1e4999f70138a4a2e251399d9bca7619b
parentcb5d290f33d28ca3921d5a341be48a6d8099ce57

Added some c_allocator.deallocate calls


4 files changed, 34 insertions(+), 11 deletions(-)

src/stage1/analyze.cpp+2-4
...@@ -3120,12 +3120,9 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3120,12 +3120,9 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3120 bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);3120 bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety);
3121 bool *covered_enum_fields;3121 bool *covered_enum_fields;
3122 bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);3122 bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count);
3123 ZigLLVMDIEnumerator **di_enumerators;
3124 if (create_enum_type) {3123 if (create_enum_type) {
3125 occupied_tag_values.init(field_count);3124 occupied_tag_values.init(field_count);
31263125
3127 di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
3128
3129 ZigType *tag_int_type;3126 ZigType *tag_int_type;
3130 if (enum_type_node != nullptr) {3127 if (enum_type_node != nullptr) {
3131 tag_int_type = analyze_type_expr(g, scope, enum_type_node);3128 tag_int_type = analyze_type_expr(g, scope, enum_type_node);
...@@ -3269,7 +3266,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3269,7 +3266,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3269 }3266 }
32703267
3271 if (create_enum_type) {3268 if (create_enum_type) {
3272 di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(union_field->name), i);
3273 union_field->enum_field = &tag_type->data.enumeration.fields[i];3269 union_field->enum_field = &tag_type->data.enumeration.fields[i];
3274 union_field->enum_field->name = union_field->name;3270 union_field->enum_field->name = union_field->name;
3275 union_field->enum_field->decl_index = i;3271 union_field->enum_field->decl_index = i;
...@@ -3336,6 +3332,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3336,6 +3332,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3336 gen_field_index += 1;3332 gen_field_index += 1;
3337 }3333 }
3338 }3334 }
3335 heap::c_allocator.deallocate(is_zero_bits, field_count);
33393336
3340 bool src_have_tag = is_auto_enum || is_explicit_enum;3337 bool src_have_tag = is_auto_enum || is_explicit_enum;
33413338
...@@ -3403,6 +3400,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3403,6 +3400,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3403 union_type->data.unionation.resolve_status = ResolveStatusInvalid;3400 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
3404 }3401 }
3405 }3402 }
3403 heap::c_allocator.deallocate(covered_enum_fields, tag_type->data.enumeration.src_field_count);
3406 }3404 }
34073405
3408 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) {3406 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) {
src/stage1/codegen.cpp+26-7
...@@ -4414,6 +4414,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn...@@ -4414,6 +4414,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
4414 }4414 }
4415 }4415 }
4416 LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false);4416 LLVMTypeRef frame_with_args_type = LLVMStructType(field_types, field_count, false);
4417 heap::c_allocator.deallocate(field_types, field_count);
4417 LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0);4418 LLVMTypeRef ptr_frame_with_args_type = LLVMPointerType(frame_with_args_type, 0);
44184419
4419 casted_frame = LLVMBuildBitCast(g->builder, frame_result_loc, ptr_frame_with_args_type, "");4420 casted_frame = LLVMBuildBitCast(g->builder, frame_result_loc, ptr_frame_with_args_type, "");
...@@ -4825,12 +4826,15 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I...@@ -4825,12 +4826,15 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I
4825 ret_type = get_llvm_type(g, instruction->base.value->type);4826 ret_type = get_llvm_type(g, instruction->base.value->type);
4826 }4827 }
4827 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);4828 LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);
4829 heap::c_allocator.deallocate(param_types, input_and_output_count);
48284830
4829 bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0);4831 bool is_volatile = instruction->has_side_effects || (asm_expr->output_list.length == 0);
4830 LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template),4832 LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template),
4831 buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT);4833 buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT);
48324834
4833 return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");4835 LLVMValueRef built_call = LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
4836 heap::c_allocator.deallocate(param_values, input_and_output_count);
4837 return built_call;
4834}4838}
48354839
4836static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {4840static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
...@@ -5083,6 +5087,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns...@@ -5083,6 +5087,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
5083 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;5087 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
5084 }5088 }
5085 LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count);5089 LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count);
5090 heap::c_allocator.deallocate(incoming_values, instruction->incoming_count);
5091 heap::c_allocator.deallocate(incoming_blocks, instruction->incoming_count);
5086 return phi;5092 return phi;
5087}5093}
50885094
...@@ -7459,10 +7465,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -7459,10 +7465,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
7459 }7465 }
7460 }7466 }
7461 if (make_unnamed_struct) {7467 if (make_unnamed_struct) {
7462 return LLVMConstStruct(fields, type_entry->data.structure.gen_field_count,7468 LLVMValueRef unnamed_struct = LLVMConstStruct(fields, type_entry->data.structure.gen_field_count,
7463 type_entry->data.structure.layout == ContainerLayoutPacked);7469 type_entry->data.structure.layout == ContainerLayoutPacked);
7470 heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count);
7471 return unnamed_struct;
7464 } else {7472 } else {
7465 return LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count);7473 LLVMValueRef named_struct = LLVMConstNamedStruct(get_llvm_type(g, type_entry), fields, type_entry->data.structure.gen_field_count);
7474 heap::c_allocator.deallocate(fields, type_entry->data.structure.gen_field_count);
7475 return named_struct;
7466 }7476 }
7467 }7477 }
7468 case ZigTypeIdArray:7478 case ZigTypeIdArray:
...@@ -7487,9 +7497,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -7487,9 +7497,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
7487 values[len] = gen_const_val(g, type_entry->data.array.sentinel, "");7497 values[len] = gen_const_val(g, type_entry->data.array.sentinel, "");
7488 }7498 }
7489 if (make_unnamed_struct) {7499 if (make_unnamed_struct) {
7490 return LLVMConstStruct(values, full_len, true);7500 LLVMValueRef unnamed_struct = LLVMConstStruct(values, full_len, true);
7501 heap::c_allocator.deallocate(values, full_len);
7502 return unnamed_struct;
7491 } else {7503 } else {
7492 return LLVMConstArray(element_type_ref, values, (unsigned)full_len);7504 LLVMValueRef array = LLVMConstArray(element_type_ref, values, (unsigned)full_len);
7505 heap::c_allocator.deallocate(values, full_len);
7506 return array;
7493 }7507 }
7494 }7508 }
7495 case ConstArraySpecialBuf: {7509 case ConstArraySpecialBuf: {
...@@ -7511,7 +7525,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -7511,7 +7525,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
7511 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];7525 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
7512 values[i] = gen_const_val(g, elem_value, "");7526 values[i] = gen_const_val(g, elem_value, "");
7513 }7527 }
7514 return LLVMConstVector(values, len);7528 LLVMValueRef vector = LLVMConstVector(values, len);
7529 heap::c_allocator.deallocate(values, len);
7530 return vector;
7515 }7531 }
7516 case ConstArraySpecialBuf: {7532 case ConstArraySpecialBuf: {
7517 Buf *buf = const_val->data.x_array.data.s_buf;7533 Buf *buf = const_val->data.x_array.data.s_buf;
...@@ -7520,7 +7536,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -7520,7 +7536,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
7520 for (uint64_t i = 0; i < len; i += 1) {7536 for (uint64_t i = 0; i < len; i += 1) {
7521 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);7537 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
7522 }7538 }
7523 return LLVMConstVector(values, len);7539 LLVMValueRef vector = LLVMConstVector(values, len);
7540 heap::c_allocator.deallocate(values, len);
7541 return vector;
7524 }7542 }
7525 }7543 }
7526 zig_unreachable();7544 zig_unreachable();
...@@ -7742,6 +7760,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -7742,6 +7760,7 @@ static void generate_error_name_table(CodeGen *g) {
7742 }7760 }
77437761
7744 LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length);7762 LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length);
7763 heap::c_allocator.deallocate(values, g->errors_by_index.length);
77457764
7746 g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),7765 g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),
7747 get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table"))));7766 get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table"))));
src/stage1/ir.cpp+4
...@@ -24144,6 +24144,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -24144,6 +24144,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
24144 first_non_const_instruction = result_loc;24144 first_non_const_instruction = result_loc;
24145 }24145 }
24146 }24146 }
24147 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
24147 if (any_missing)24148 if (any_missing)
24148 return ira->codegen->invalid_inst_gen;24149 return ira->codegen->invalid_inst_gen;
2414924150
...@@ -29840,6 +29841,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -29840,6 +29841,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
29840 buf_write_value_bytes(ira->codegen, buf, val);29841 buf_write_value_bytes(ira->codegen, buf, val);
29841 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))29842 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
29842 return ira->codegen->invalid_inst_gen;29843 return ira->codegen->invalid_inst_gen;
29844 heap::c_allocator.deallocate(buf, src_size_bytes);
29843 return result;29845 return result;
29844 }29846 }
2984529847
...@@ -30877,6 +30879,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -30877,6 +30879,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
30877 ira->codegen->is_big_endian,30879 ira->codegen->is_big_endian,
30878 int_type->data.integral.is_signed);30880 int_type->data.integral.is_signed);
3087930881
30882 heap::c_allocator.deallocate(comptime_buf, buf_size);
30883 heap::c_allocator.deallocate(result_buf, buf_size);
30880 return result;30884 return result;
30881 }30885 }
3088230886
src/stage1/os.cpp+2
...@@ -127,6 +127,7 @@ static void os_spawn_process_posix(ZigList<const char *> &args, Termination *ter...@@ -127,6 +127,7 @@ static void os_spawn_process_posix(ZigList<const char *> &args, Termination *ter
127 int status;127 int status;
128 waitpid(pid, &status, 0);128 waitpid(pid, &status, 0);
129 populate_termination(term, status);129 populate_termination(term, status);
130 heap::c_allocator.deallocate(argv, args.length + 1);
130}131}
131#endif132#endif
132133
...@@ -748,6 +749,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {...@@ -748,6 +749,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
748749
749 Buf return_value = BUF_INIT;750 Buf return_value = BUF_INIT;
750 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);751 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
752 heap::c_allocator.deallocate(result_ptr, result_len);
751 return return_value;753 return return_value;
752}754}
753#endif755#endif