diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 7fd4e3643be..351f82d3a0b 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -225,6 +225,8 @@ pub fn compile_input(sess: &Session, phase5_result); phase5_result?; + write::cleanup_llvm(&trans); + phase_6_link_output(sess, &trans, &outputs); Ok(()) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 1e5545b00b7..ec20381d189 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -616,11 +616,19 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext, } } - llvm::LLVMDisposeModule(llmod); - llvm::LLVMContextDispose(llcx); llvm::LLVMRustDisposeTargetMachine(tm); } + +pub fn cleanup_llvm(trans: &CrateTranslation) { + for module in trans.modules.iter() { + unsafe { + llvm::LLVMDisposeModule(module.llmod); + llvm::LLVMContextDispose(module.llcx); + } + } +} + pub fn run_passes(sess: &Session, trans: &CrateTranslation, output_types: &HashMap>,