@@ -34,7 +34,7 @@ use crate::builder::Builder;
3434use crate :: common:: { AsCCharPtr , CodegenCx } ;
3535use crate :: llvm;
3636use crate :: llvm:: debuginfo:: {
37- DIArray , DIBuilder , DIFile , DIFlags , DILexicalBlock , DILocation , DISPFlags , DIScope , DIType ,
37+ DIArray , DIBuilderBox , DIFile , DIFlags , DILexicalBlock , DILocation , DISPFlags , DIScope , DIType ,
3838 DIVariable ,
3939} ;
4040use crate :: value:: Value ;
@@ -56,26 +56,18 @@ const DW_TAG_arg_variable: c_uint = 0x101;
5656/// A context object for maintaining all state needed by the debuginfo module.
5757pub ( crate ) struct CodegenUnitDebugContext < ' ll , ' tcx > {
5858 llmod : & ' ll llvm:: Module ,
59- builder : & ' ll mut DIBuilder < ' ll > ,
59+ builder : DIBuilderBox < ' ll > ,
6060 created_files : RefCell < UnordMap < Option < ( StableSourceFileId , SourceFileHash ) > , & ' ll DIFile > > ,
6161
6262 type_map : metadata:: TypeMap < ' ll , ' tcx > ,
6363 namespace_map : RefCell < DefIdMap < & ' ll DIScope > > ,
6464 recursion_marker_type : OnceCell < & ' ll DIType > ,
6565}
6666
67- impl Drop for CodegenUnitDebugContext < ' _ , ' _ > {
68- fn drop ( & mut self ) {
69- unsafe {
70- llvm:: LLVMRustDIBuilderDispose ( & mut * ( self . builder as * mut _ ) ) ;
71- }
72- }
73- }
74-
7567impl < ' ll , ' tcx > CodegenUnitDebugContext < ' ll , ' tcx > {
7668 pub ( crate ) fn new ( llmod : & ' ll llvm:: Module ) -> Self {
7769 debug ! ( "CodegenUnitDebugContext::new" ) ;
78- let builder = unsafe { llvm :: LLVMRustDIBuilderCreate ( llmod) } ;
70+ let builder = DIBuilderBox :: new ( llmod) ;
7971 // DIBuilder inherits context from the module, so we'd better use the same one
8072 CodegenUnitDebugContext {
8173 llmod,
@@ -88,7 +80,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
8880 }
8981
9082 pub ( crate ) fn finalize ( & self , sess : & Session ) {
91- unsafe { llvm:: LLVMRustDIBuilderFinalize ( self . builder ) } ;
83+ unsafe { llvm:: LLVMRustDIBuilderFinalize ( self . builder . as_ref ( ) ) } ;
9284 if !sess. target . is_like_msvc {
9385 // Debuginfo generation in LLVM by default uses a higher
9486 // version of dwarf than macOS currently understands. We can
0 commit comments