diff --git a/src/codegen.cpp b/src/codegen.cpp index 5168a55fab..e119b714a8 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -152,6 +152,10 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out return g; } +void codegen_destroy(CodeGen *codegen) { + LLVMDisposeTargetMachine(codegen->target_machine); +} + void codegen_set_output_h_path(CodeGen *g, Buf *h_path) { g->out_h_path = h_path; } diff --git a/src/codegen.hpp b/src/codegen.hpp index 824b82feb9..549891b107 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -16,6 +16,7 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, Buf *zig_lib_dir); +void codegen_destroy(CodeGen *codegen); void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); diff --git a/src/link.cpp b/src/link.cpp index 35b350df0f..475e42fd7b 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -65,6 +65,8 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) os_path_join(parent_gen->cache_dir, o_out_name, output_path); codegen_link(child_gen, buf_ptr(output_path)); + codegen_destroy(child_gen); + return output_path; } diff --git a/src/main.cpp b/src/main.cpp index 9cd185280d..6695ae4225 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -421,6 +421,7 @@ int main(int argc, char **argv) { g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg); codegen_build(g); codegen_link(g, buf_ptr(path_to_build_exe)); + codegen_destroy(g); Termination term; os_spawn_process(buf_ptr(path_to_build_exe), args, &term); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 5d8b34de10..f82b1d5423 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -165,7 +165,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM MPM.run(*module); - dest.flush(); + dest.close(); + return false; }