Skip to content

Commit 2a7ba97

Browse files
committed
fix nested references
1 parent 0c51c1c commit 2a7ba97

File tree

1 file changed

+134
-18
lines changed

1 file changed

+134
-18
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{iter, ptr};
66

77
use libc::{c_char, c_longlong, c_uint};
88
use 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};
1010
use rustc_codegen_ssa::traits::*;
1111
use rustc_hir::def::{CtorKind, DefKind};
1212
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
@@ -17,22 +17,22 @@ use rustc_middle::ty::{
1717
};
1818
use rustc_session::config::{self, DebugInfo, Lto};
1919
use rustc_span::symbol::Symbol;
20-
use rustc_span::{DUMMY_SP, FileName, FileNameDisplayPreference, SourceFile, hygiene};
20+
use rustc_span::{hygiene, FileName, FileNameDisplayPreference, SourceFile, DUMMY_SP};
2121
use rustc_symbol_mangling::typeid_for_trait_ref;
2222
use rustc_target::spec::DebuginfoKind;
2323
use smallvec::smallvec;
2424
use tracing::{debug, instrument};
2525

2626
use self::type_map::{DINodeCreationResult, Stub, UniqueTypeId};
27-
use super::CodegenUnitDebugContext;
2827
use super::namespace::mangled_name_of_instance;
2928
use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name};
3029
use super::utils::{
31-
DIB, create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit,
30+
create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB,
3231
};
32+
use super::CodegenUnitDebugContext;
3333
use crate::common::{AsCCharPtr, CodegenCx};
3434
use crate::debuginfo::metadata::type_map::build_type_with_children;
35-
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
35+
use crate::debuginfo::utils::{wide_pointer_kind, WidePtrKind};
3636
use crate::llvm::debuginfo::{
3737
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
3838
DebugNameTableKind,
@@ -74,10 +74,14 @@ const DW_ATE_unsigned: c_uint = 0x07;
7474
#[allow(non_upper_case_globals)]
7575
const DW_ATE_UTF: c_uint = 0x10;
7676

77+
#[allow(non_upper_case_globals)]
78+
const DW_TAG_pointer_type: c_uint = 0xf;
7779
#[allow(non_upper_case_globals)]
7880
const DW_TAG_reference_type: c_uint = 0x10;
7981
#[allow(non_upper_case_globals)]
8082
const DW_TAG_const_type: c_uint = 0x26;
83+
#[allow(non_upper_case_globals)]
84+
const DW_TAG_rvalue_reference_type: c_uint = 0x42;
8185

8286
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0;
8387
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
@@ -186,14 +190,43 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
186190
"ptr_type={ptr_type}, pointee_type={pointee_type}",
187191
);
188192

189-
// Immutable pointers/references will mark the data as `const`. For example:
190-
// unsigned char & => &mut u8
191-
// const unsigned char & => &u8
192-
// unsigned char * => *mut u8
193-
// const unsigned char * => *const u8
194-
let di_node = match ptr_type.kind() {
195-
ty::Ref(_, _, mutability) => unsafe {
196-
let pointee_type_di_node = if mutability.is_not() {
193+
let di_node = match (ptr_type.kind(), pointee_type.kind()) {
194+
(ty::Ref(_, _, ptr_mut), ty::Ref(_, inner_type, ptee_mut)) => unsafe {
195+
let inner_type_di_node = type_di_node(cx, *inner_type);
196+
let inner_type_di_node = if ptee_mut.is_not() {
197+
llvm::LLVMRustDIBuilderCreateQualifiedType(
198+
DIB(cx),
199+
DW_TAG_const_type,
200+
inner_type_di_node,
201+
)
202+
} else {
203+
inner_type_di_node
204+
};
205+
206+
let ptr_wrapper = llvm::LLVMRustDIBuilderCreateReferenceType(
207+
DIB(cx),
208+
DW_TAG_pointer_type,
209+
inner_type_di_node,
210+
);
211+
212+
let ptr_wrapper = if ptr_mut.is_not() {
213+
llvm::LLVMRustDIBuilderCreateQualifiedType(
214+
DIB(cx),
215+
DW_TAG_const_type,
216+
ptr_wrapper,
217+
)
218+
} else {
219+
ptr_wrapper
220+
};
221+
222+
llvm::LLVMRustDIBuilderCreateReferenceType(
223+
DIB(cx),
224+
DW_TAG_rvalue_reference_type,
225+
ptr_wrapper,
226+
)
227+
},
228+
(ty::Ref(_, _, ptr_mut), _) => unsafe {
229+
let pointee_type_di_node = if ptr_mut.is_not() {
197230
llvm::LLVMRustDIBuilderCreateQualifiedType(
198231
DIB(cx),
199232
DW_TAG_const_type,
@@ -209,8 +242,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
209242
pointee_type_di_node,
210243
)
211244
},
212-
ty::RawPtr(_, mutability) => unsafe {
213-
let pointee_type_di_node = if mutability.is_not() {
245+
(ty::RawPtr(_, ptr_mut), _) => unsafe {
246+
let pointee_type_di_node = if ptr_mut.is_not() {
214247
llvm::LLVMRustDIBuilderCreateQualifiedType(
215248
DIB(cx),
216249
DW_TAG_const_type,
@@ -219,6 +252,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
219252
} else {
220253
pointee_type_di_node
221254
};
255+
222256
llvm::LLVMRustDIBuilderCreatePointerType(
223257
DIB(cx),
224258
pointee_type_di_node,
@@ -229,7 +263,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
229263
ptr_type_debuginfo_name.len(),
230264
)
231265
},
232-
ty::Adt(_, _) => unsafe {
266+
(ty::Adt(_, _), _) => unsafe {
233267
llvm::LLVMRustDIBuilderCreatePointerType(
234268
DIB(cx),
235269
pointee_type_di_node,
@@ -240,9 +274,91 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
240274
ptr_type_debuginfo_name.len(),
241275
)
242276
},
243-
_ => unreachable!("Thin pointer not of type ty::RawPtr, ty::Ref, or ty::Adt"),
277+
_ => todo!(),
244278
};
245279

280+
// Immutable pointers/references will mark the data as `const`. For example:
281+
// unsigned char & => &mut u8
282+
// const unsigned char & => &u8
283+
// unsigned char * => *mut u8
284+
// const unsigned char * => *const u8
285+
// let di_node = match ptr_type.kind() {
286+
// ty::Ref(_, _, mutability) => unsafe {
287+
// let pointee_type_di_node = if mutability.is_not() {
288+
// llvm::LLVMRustDIBuilderCreateQualifiedType(
289+
// DIB(cx),
290+
// DW_TAG_const_type,
291+
// pointee_type_di_node,
292+
// )
293+
// } else {
294+
// pointee_type_di_node
295+
// };
296+
297+
// if let ty::Ref(_, pt_e, _) = pointee_type.kind() {
298+
// let pointee_type_di_node = type_di_node(cx, *pt_e);
299+
// let temp = llvm::LLVMRustDIBuilderCreateReferenceType(
300+
// DIB(cx),
301+
// 0xf,
302+
// pointee_type_di_node,
303+
// );
304+
305+
// let temp = if mutability.is_not() {
306+
// llvm::LLVMRustDIBuilderCreateQualifiedType(
307+
// DIB(cx),
308+
// DW_TAG_const_type,
309+
// temp,
310+
// )
311+
// } else {
312+
// temp
313+
// };
314+
315+
// llvm::LLVMRustDIBuilderCreateReferenceType(
316+
// DIB(cx),
317+
// DW_TAG_rvalue_reference_type,
318+
// temp,
319+
// )
320+
// } else {
321+
// llvm::LLVMRustDIBuilderCreateReferenceType(
322+
// DIB(cx),
323+
// DW_TAG_reference_type,
324+
// pointee_type_di_node,
325+
// )
326+
// }
327+
// },
328+
// ty::RawPtr(_, mutability) => unsafe {
329+
// let pointee_type_di_node = if mutability.is_not() {
330+
// llvm::LLVMRustDIBuilderCreateQualifiedType(
331+
// DIB(cx),
332+
// DW_TAG_const_type,
333+
// pointee_type_di_node,
334+
// )
335+
// } else {
336+
// pointee_type_di_node
337+
// };
338+
// llvm::LLVMRustDIBuilderCreatePointerType(
339+
// DIB(cx),
340+
// pointee_type_di_node,
341+
// data_layout.pointer_size.bits(),
342+
// data_layout.pointer_align.abi.bits() as u32,
343+
// 0, // Ignore DWARF address space.
344+
// ptr_type_debuginfo_name.as_c_char_ptr(),
345+
// ptr_type_debuginfo_name.len(),
346+
// )
347+
// },
348+
// ty::Adt(_, _) => unsafe {
349+
// llvm::LLVMRustDIBuilderCreatePointerType(
350+
// DIB(cx),
351+
// pointee_type_di_node,
352+
// data_layout.pointer_size.bits(),
353+
// data_layout.pointer_align.abi.bits() as u32,
354+
// 0, // Ignore DWARF address space.
355+
// ptr_type_debuginfo_name.as_c_char_ptr(),
356+
// ptr_type_debuginfo_name.len(),
357+
// )
358+
// },
359+
// _ => unreachable!("Thin pointer not of type ty::RawPtr, ty::Ref, or ty::Adt"),
360+
// };
361+
246362
DINodeCreationResult { di_node, already_stored_in_typemap: false }
247363
}
248364
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

Comments
 (0)