@@ -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
@@ -664,7 +668,6 @@ pub(crate) unsafe fn optimize(
664
668
) -> Result < ( ) , FatalError > {
665
669
let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
666
670
667
- let llmod = module. module_llvm . llmod ( ) ;
668
671
let llcx = & * module. module_llvm . llcx ;
669
672
let _handlers = DiagnosticHandlers :: new ( cgcx, dcx, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
670
673
@@ -673,8 +676,7 @@ pub(crate) unsafe fn optimize(
673
676
674
677
if config. emit_no_opt_bc {
675
678
let out = cgcx. output_filenames . temp_path_ext ( "no-opt.bc" , module_name) ;
676
- let out = path_to_c_string ( & out) ;
677
- unsafe { llvm:: LLVMWriteBitcodeToFile ( llmod, out. as_ptr ( ) ) } ;
679
+ write_bitcode_to_file ( module, & out)
678
680
}
679
681
680
682
// FIXME(ZuseZ4): support SanitizeHWAddress and prevent illegal/unsupported opts
0 commit comments