@@ -328,13 +328,17 @@ pub(crate) fn save_temp_bitcode(
328
328
if !cgcx. save_temps {
329
329
return ;
330
330
}
331
+ let ext = format ! ( "{name}.bc" ) ;
332
+ let cgu = Some ( & module. name [ ..] ) ;
333
+ let path = cgcx. output_filenames . temp_path_ext ( & ext, cgu) ;
334
+ write_bitcode_to_file ( module, & path)
335
+ }
336
+
337
+ fn write_bitcode_to_file ( module : & ModuleCodegen < ModuleLlvm > , path : & Path ) {
331
338
unsafe {
332
- let ext = format ! ( "{name}.bc" ) ;
333
- let cgu = Some ( & module. name [ ..] ) ;
334
- let path = cgcx. output_filenames . temp_path_ext ( & ext, cgu) ;
335
- let cstr = path_to_c_string ( & path) ;
339
+ let path = path_to_c_string ( & path) ;
336
340
let llmod = module. module_llvm . llmod ( ) ;
337
- llvm:: LLVMWriteBitcodeToFile ( llmod, cstr . as_ptr ( ) ) ;
341
+ llvm:: LLVMWriteBitcodeToFile ( llmod, path . as_ptr ( ) ) ;
338
342
}
339
343
}
340
344
@@ -679,7 +683,6 @@ pub(crate) unsafe fn optimize(
679
683
) -> Result < ( ) , FatalError > {
680
684
let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
681
685
682
- let llmod = module. module_llvm . llmod ( ) ;
683
686
let llcx = & * module. module_llvm . llcx ;
684
687
let _handlers = DiagnosticHandlers :: new ( cgcx, dcx, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
685
688
@@ -688,8 +691,7 @@ pub(crate) unsafe fn optimize(
688
691
689
692
if config. emit_no_opt_bc {
690
693
let out = cgcx. output_filenames . temp_path_ext ( "no-opt.bc" , module_name) ;
691
- let out = path_to_c_string ( & out) ;
692
- unsafe { llvm:: LLVMWriteBitcodeToFile ( llmod, out. as_ptr ( ) ) } ;
694
+ write_bitcode_to_file ( module, & out)
693
695
}
694
696
695
697
// FIXME(ZuseZ4): support SanitizeHWAddress and prevent illegal/unsupported opts
0 commit comments