Commit 82f0ede3ad

Alexandros Naskos <alex_naskos@hotmail.com>
2020-09-30 18:59:49
Added some c_allocator.deallocate calls
1 parent cb5d290
Changed files (4)
src/stage1/analyze.cpp
@@ -3120,12 +3120,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);
@@ -3269,7 +3266,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;
@@ -3336,6 +3332,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;
 
@@ -3403,6 +3400,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) {
src/stage1/codegen.cpp
@@ -4414,6 +4414,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, "");
@@ -4825,12 +4826,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) {
@@ -5083,6 +5087,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;
 }
 
@@ -7459,10 +7465,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:
@@ -7487,9 +7497,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: {
@@ -7511,7 +7525,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;
@@ -7520,7 +7536,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();
@@ -7742,6 +7760,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"))));
src/stage1/ir.cpp
@@ -24144,6 +24144,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;
 
@@ -29840,6 +29841,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;
     }
 
@@ -30877,6 +30879,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;
     }
 
src/stage1/os.cpp
@@ -127,6 +127,7 @@ static void os_spawn_process_posix(ZigList<const char *> &args, Termination *ter
     int status;
     waitpid(pid, &status, 0);
     populate_termination(term, status);
+    heap::c_allocator.deallocate(argv, args.length + 1);
 }
 #endif
 
@@ -748,6 +749,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