@@ -9,15 +9,15 @@ use libc::{c_char, c_int, c_void, size_t};
99use rustc_codegen_ssa:: back:: link:: ensure_removed;
1010use rustc_codegen_ssa:: back:: versioned_llvm_target;
1111use rustc_codegen_ssa:: back:: write:: {
12- BitcodeSection , CodegenContext , EmitObj , InlineAsmError , ModuleConfig ,
12+ BitcodeSection , CodegenContext , EmitObj , InlineAsmError , ModuleConfig , SharedEmitter ,
1313 TargetMachineFactoryConfig , TargetMachineFactoryFn ,
1414} ;
1515use rustc_codegen_ssa:: base:: wants_wasm_eh;
1616use rustc_codegen_ssa:: traits:: * ;
1717use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen , ModuleKind } ;
1818use rustc_data_structures:: profiling:: SelfProfilerRef ;
1919use rustc_data_structures:: small_c_str:: SmallCStr ;
20- use rustc_errors:: { DiagCtxtHandle , Level } ;
20+ use rustc_errors:: { DiagCtxt , DiagCtxtHandle , Level } ;
2121use rustc_fs_util:: { link_or_copy, path_to_c_string} ;
2222use rustc_middle:: ty:: TyCtxt ;
2323use rustc_session:: Session ;
@@ -356,15 +356,15 @@ pub(crate) enum CodegenDiagnosticsStage {
356356}
357357
358358pub ( crate ) struct DiagnosticHandlers < ' a > {
359- data : * mut ( & ' a CodegenContext < LlvmCodegenBackend > , DiagCtxtHandle < ' a > ) ,
359+ data : * mut ( & ' a CodegenContext < LlvmCodegenBackend > , & ' a SharedEmitter ) ,
360360 llcx : & ' a llvm:: Context ,
361361 old_handler : Option < & ' a llvm:: DiagnosticHandler > ,
362362}
363363
364364impl < ' a > DiagnosticHandlers < ' a > {
365365 pub ( crate ) fn new (
366366 cgcx : & ' a CodegenContext < LlvmCodegenBackend > ,
367- dcx : DiagCtxtHandle < ' a > ,
367+ shared_emitter : & ' a SharedEmitter ,
368368 llcx : & ' a llvm:: Context ,
369369 module : & ModuleCodegen < ModuleLlvm > ,
370370 stage : CodegenDiagnosticsStage ,
@@ -399,7 +399,7 @@ impl<'a> DiagnosticHandlers<'a> {
399399 . and_then ( |dir| dir. to_str ( ) . and_then ( |p| CString :: new ( p) . ok ( ) ) ) ;
400400
401401 let pgo_available = cgcx. module_config . pgo_use . is_some ( ) ;
402- let data = Box :: into_raw ( Box :: new ( ( cgcx, dcx ) ) ) ;
402+ let data = Box :: into_raw ( Box :: new ( ( cgcx, shared_emitter ) ) ) ;
403403 unsafe {
404404 let old_handler = llvm:: LLVMRustContextGetDiagnosticHandler ( llcx) ;
405405 llvm:: LLVMRustContextConfigureDiagnosticHandler (
@@ -461,12 +461,16 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
461461 if user. is_null ( ) {
462462 return ;
463463 }
464- let ( cgcx, dcx) =
465- unsafe { * ( user as * const ( & CodegenContext < LlvmCodegenBackend > , DiagCtxtHandle < ' _ > ) ) } ;
464+ let ( cgcx, shared_emitter) =
465+ unsafe { * ( user as * const ( & CodegenContext < LlvmCodegenBackend > , & SharedEmitter ) ) } ;
466+
467+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
468+ let dcx = dcx. handle ( ) ;
466469
467470 match unsafe { llvm:: diagnostic:: Diagnostic :: unpack ( info) } {
468471 llvm:: diagnostic:: InlineAsm ( inline) => {
469- cgcx. diag_emitter . inline_asm_error ( report_inline_asm (
472+ // FIXME use dcx
473+ shared_emitter. inline_asm_error ( report_inline_asm (
470474 cgcx,
471475 inline. message ,
472476 inline. level ,
@@ -777,14 +781,18 @@ pub(crate) unsafe fn llvm_optimize(
777781// Unsafe due to LLVM calls.
778782pub ( crate ) fn optimize (
779783 cgcx : & CodegenContext < LlvmCodegenBackend > ,
780- dcx : DiagCtxtHandle < ' _ > ,
784+ shared_emitter : & SharedEmitter ,
781785 module : & mut ModuleCodegen < ModuleLlvm > ,
782786 config : & ModuleConfig ,
783787) {
784788 let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
785789
790+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
791+ let dcx = dcx. handle ( ) ;
792+
786793 let llcx = & * module. module_llvm . llcx ;
787- let _handlers = DiagnosticHandlers :: new ( cgcx, dcx, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
794+ let _handlers =
795+ DiagnosticHandlers :: new ( cgcx, shared_emitter, llcx, module, CodegenDiagnosticsStage :: Opt ) ;
788796
789797 if config. emit_no_opt_bc {
790798 let out = cgcx. output_filenames . temp_path_ext_for_cgu (
@@ -865,19 +873,26 @@ pub(crate) fn optimize(
865873
866874pub ( crate ) fn codegen (
867875 cgcx : & CodegenContext < LlvmCodegenBackend > ,
876+ shared_emitter : & SharedEmitter ,
868877 module : ModuleCodegen < ModuleLlvm > ,
869878 config : & ModuleConfig ,
870879) -> CompiledModule {
871- let dcx = cgcx. create_dcx ( ) ;
880+ let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen" , & * module. name ) ;
881+
882+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter. clone ( ) ) ) ;
872883 let dcx = dcx. handle ( ) ;
873884
874- let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen" , & * module. name ) ;
875885 {
876886 let llmod = module. module_llvm . llmod ( ) ;
877887 let llcx = & * module. module_llvm . llcx ;
878888 let tm = & * module. module_llvm . tm ;
879- let _handlers =
880- DiagnosticHandlers :: new ( cgcx, dcx, llcx, & module, CodegenDiagnosticsStage :: Codegen ) ;
889+ let _handlers = DiagnosticHandlers :: new (
890+ cgcx,
891+ shared_emitter,
892+ llcx,
893+ & module,
894+ CodegenDiagnosticsStage :: Codegen ,
895+ ) ;
881896
882897 if cgcx. msvc_imps_needed {
883898 create_msvc_imps ( cgcx, llcx, llmod) ;
0 commit comments