@@ -6,7 +6,7 @@ use std::{iter, ptr};
66
77use libc:: { c_char, c_longlong, c_uint} ;
88use rustc_abi:: { Align , Size } ;
9- use rustc_codegen_ssa:: debuginfo:: type_names:: { VTableNameKind , cpp_like_debuginfo } ;
9+ use rustc_codegen_ssa:: debuginfo:: type_names:: { cpp_like_debuginfo , VTableNameKind } ;
1010use rustc_codegen_ssa:: traits:: * ;
1111use rustc_hir:: def:: { CtorKind , DefKind } ;
1212use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
@@ -23,15 +23,15 @@ use smallvec::smallvec;
2323use tracing:: { debug, instrument} ;
2424
2525use self :: type_map:: { DINodeCreationResult , Stub , UniqueTypeId } ;
26- use super :: CodegenUnitDebugContext ;
2726use super :: namespace:: mangled_name_of_instance;
2827use super :: type_names:: { compute_debuginfo_type_name, compute_debuginfo_vtable_name} ;
2928use super :: utils:: {
30- DIB , create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit,
29+ create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB ,
3130} ;
31+ use super :: CodegenUnitDebugContext ;
3232use crate :: common:: { AsCCharPtr , CodegenCx } ;
3333use crate :: debuginfo:: metadata:: type_map:: build_type_with_children;
34- use crate :: debuginfo:: utils:: { WidePtrKind , wide_pointer_kind } ;
34+ use crate :: debuginfo:: utils:: { wide_pointer_kind , WidePtrKind } ;
3535use crate :: llvm:: debuginfo:: {
3636 DIDescriptor , DIFile , DIFlags , DILexicalBlock , DIScope , DIType , DebugEmissionKind ,
3737 DebugNameTableKind ,
@@ -73,10 +73,14 @@ const DW_ATE_unsigned: c_uint = 0x07;
7373#[ allow( non_upper_case_globals) ]
7474const DW_ATE_UTF : c_uint = 0x10 ;
7575
76+ #[ allow( non_upper_case_globals) ]
77+ const DW_TAG_pointer_type : c_uint = 0xf ;
7678#[ allow( non_upper_case_globals) ]
7779const DW_TAG_reference_type : c_uint = 0x10 ;
7880#[ allow( non_upper_case_globals) ]
7981const DW_TAG_const_type : c_uint = 0x26 ;
82+ #[ allow( non_upper_case_globals) ]
83+ const DW_TAG_rvalue_reference_type : c_uint = 0x42 ;
8084
8185pub ( super ) const UNKNOWN_LINE_NUMBER : c_uint = 0 ;
8286pub ( super ) const UNKNOWN_COLUMN_NUMBER : c_uint = 0 ;
@@ -185,14 +189,43 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
185189 "ptr_type={ptr_type}, pointee_type={pointee_type}" ,
186190 ) ;
187191
188- // Immutable pointers/references will mark the data as `const`. For example:
189- // unsigned char & => &mut u8
190- // const unsigned char & => &u8
191- // unsigned char * => *mut u8
192- // const unsigned char * => *const u8
193- let di_node = match ptr_type. kind ( ) {
194- ty:: Ref ( _, _, mutability) => unsafe {
195- let pointee_type_di_node = if mutability. is_not ( ) {
192+ let di_node = match ( ptr_type. kind ( ) , pointee_type. kind ( ) ) {
193+ ( ty:: Ref ( _, _, ptr_mut) , ty:: Ref ( _, inner_type, ptee_mut) ) => unsafe {
194+ let inner_type_di_node = type_di_node ( cx, * inner_type) ;
195+ let inner_type_di_node = if ptee_mut. is_not ( ) {
196+ llvm:: LLVMRustDIBuilderCreateQualifiedType (
197+ DIB ( cx) ,
198+ DW_TAG_const_type ,
199+ inner_type_di_node,
200+ )
201+ } else {
202+ inner_type_di_node
203+ } ;
204+
205+ let ptr_wrapper = llvm:: LLVMRustDIBuilderCreateReferenceType (
206+ DIB ( cx) ,
207+ DW_TAG_pointer_type ,
208+ inner_type_di_node,
209+ ) ;
210+
211+ let ptr_wrapper = if ptr_mut. is_not ( ) {
212+ llvm:: LLVMRustDIBuilderCreateQualifiedType (
213+ DIB ( cx) ,
214+ DW_TAG_const_type ,
215+ ptr_wrapper,
216+ )
217+ } else {
218+ ptr_wrapper
219+ } ;
220+
221+ llvm:: LLVMRustDIBuilderCreateReferenceType (
222+ DIB ( cx) ,
223+ DW_TAG_rvalue_reference_type ,
224+ ptr_wrapper,
225+ )
226+ } ,
227+ ( ty:: Ref ( _, _, ptr_mut) , _) => unsafe {
228+ let pointee_type_di_node = if ptr_mut. is_not ( ) {
196229 llvm:: LLVMRustDIBuilderCreateQualifiedType (
197230 DIB ( cx) ,
198231 DW_TAG_const_type ,
@@ -208,8 +241,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
208241 pointee_type_di_node,
209242 )
210243 } ,
211- ty:: RawPtr ( _, mutability ) => unsafe {
212- let pointee_type_di_node = if mutability . is_not ( ) {
244+ ( ty:: RawPtr ( _, ptr_mut ) , _ ) => unsafe {
245+ let pointee_type_di_node = if ptr_mut . is_not ( ) {
213246 llvm:: LLVMRustDIBuilderCreateQualifiedType (
214247 DIB ( cx) ,
215248 DW_TAG_const_type ,
@@ -218,6 +251,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
218251 } else {
219252 pointee_type_di_node
220253 } ;
254+
221255 llvm:: LLVMRustDIBuilderCreatePointerType (
222256 DIB ( cx) ,
223257 pointee_type_di_node,
@@ -228,7 +262,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
228262 ptr_type_debuginfo_name. len ( ) ,
229263 )
230264 } ,
231- ty:: Adt ( _, _) => unsafe {
265+ ( ty:: Adt ( _, _ ) , _) => unsafe {
232266 llvm:: LLVMRustDIBuilderCreatePointerType (
233267 DIB ( cx) ,
234268 pointee_type_di_node,
@@ -239,9 +273,91 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
239273 ptr_type_debuginfo_name. len ( ) ,
240274 )
241275 } ,
242- _ => unreachable ! ( "Thin pointer not of type ty::RawPtr, ty::Ref, or ty::Adt" ) ,
276+ _ => todo ! ( ) ,
243277 } ;
244278
279+ // Immutable pointers/references will mark the data as `const`. For example:
280+ // unsigned char & => &mut u8
281+ // const unsigned char & => &u8
282+ // unsigned char * => *mut u8
283+ // const unsigned char * => *const u8
284+ // let di_node = match ptr_type.kind() {
285+ // ty::Ref(_, _, mutability) => unsafe {
286+ // let pointee_type_di_node = if mutability.is_not() {
287+ // llvm::LLVMRustDIBuilderCreateQualifiedType(
288+ // DIB(cx),
289+ // DW_TAG_const_type,
290+ // pointee_type_di_node,
291+ // )
292+ // } else {
293+ // pointee_type_di_node
294+ // };
295+
296+ // if let ty::Ref(_, pt_e, _) = pointee_type.kind() {
297+ // let pointee_type_di_node = type_di_node(cx, *pt_e);
298+ // let temp = llvm::LLVMRustDIBuilderCreateReferenceType(
299+ // DIB(cx),
300+ // 0xf,
301+ // pointee_type_di_node,
302+ // );
303+
304+ // let temp = if mutability.is_not() {
305+ // llvm::LLVMRustDIBuilderCreateQualifiedType(
306+ // DIB(cx),
307+ // DW_TAG_const_type,
308+ // temp,
309+ // )
310+ // } else {
311+ // temp
312+ // };
313+
314+ // llvm::LLVMRustDIBuilderCreateReferenceType(
315+ // DIB(cx),
316+ // DW_TAG_rvalue_reference_type,
317+ // temp,
318+ // )
319+ // } else {
320+ // llvm::LLVMRustDIBuilderCreateReferenceType(
321+ // DIB(cx),
322+ // DW_TAG_reference_type,
323+ // pointee_type_di_node,
324+ // )
325+ // }
326+ // },
327+ // ty::RawPtr(_, mutability) => unsafe {
328+ // let pointee_type_di_node = if mutability.is_not() {
329+ // llvm::LLVMRustDIBuilderCreateQualifiedType(
330+ // DIB(cx),
331+ // DW_TAG_const_type,
332+ // pointee_type_di_node,
333+ // )
334+ // } else {
335+ // pointee_type_di_node
336+ // };
337+ // llvm::LLVMRustDIBuilderCreatePointerType(
338+ // DIB(cx),
339+ // pointee_type_di_node,
340+ // data_layout.pointer_size.bits(),
341+ // data_layout.pointer_align.abi.bits() as u32,
342+ // 0, // Ignore DWARF address space.
343+ // ptr_type_debuginfo_name.as_c_char_ptr(),
344+ // ptr_type_debuginfo_name.len(),
345+ // )
346+ // },
347+ // ty::Adt(_, _) => unsafe {
348+ // llvm::LLVMRustDIBuilderCreatePointerType(
349+ // DIB(cx),
350+ // pointee_type_di_node,
351+ // data_layout.pointer_size.bits(),
352+ // data_layout.pointer_align.abi.bits() as u32,
353+ // 0, // Ignore DWARF address space.
354+ // ptr_type_debuginfo_name.as_c_char_ptr(),
355+ // ptr_type_debuginfo_name.len(),
356+ // )
357+ // },
358+ // _ => unreachable!("Thin pointer not of type ty::RawPtr, ty::Ref, or ty::Adt"),
359+ // };
360+
245361 DINodeCreationResult { di_node, already_stored_in_typemap : false }
246362 }
247363 Some ( wide_pointer_kind) => {
@@ -923,8 +1039,8 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
9231039 codegen_unit_name : & str ,
9241040 debug_context : & CodegenUnitDebugContext < ' ll , ' tcx > ,
9251041) -> & ' ll DIDescriptor {
926- use rustc_session:: RemapFileNameExt ;
9271042 use rustc_session:: config:: RemapPathScopeComponents ;
1043+ use rustc_session:: RemapFileNameExt ;
9281044 let mut name_in_debuginfo = tcx
9291045 . sess
9301046 . local_crate_source_file ( )
0 commit comments