@@ -73,6 +73,11 @@ 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_reference_type : c_uint = 0x10 ;
78+ #[ allow( non_upper_case_globals) ]
79+ const DW_TAG_const_type : c_uint = 0x26 ;
80+
7681pub ( super ) const UNKNOWN_LINE_NUMBER : c_uint = 0 ;
7782pub ( super ) const UNKNOWN_COLUMN_NUMBER : c_uint = 0 ;
7883
@@ -180,16 +185,61 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
180185 "ptr_type={ptr_type}, pointee_type={pointee_type}" ,
181186 ) ;
182187
183- let di_node = unsafe {
184- llvm:: LLVMRustDIBuilderCreatePointerType (
185- DIB ( cx) ,
186- pointee_type_di_node,
187- data_layout. pointer_size . bits ( ) ,
188- data_layout. pointer_align . abi . bits ( ) as u32 ,
189- 0 , // Ignore DWARF address space.
190- ptr_type_debuginfo_name. as_c_char_ptr ( ) ,
191- ptr_type_debuginfo_name. len ( ) ,
192- )
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 ( ) {
196+ llvm:: LLVMRustDIBuilderCreateQualifiedType (
197+ DIB ( cx) ,
198+ DW_TAG_const_type ,
199+ pointee_type_di_node,
200+ )
201+ } else {
202+ pointee_type_di_node
203+ } ;
204+
205+ llvm:: LLVMRustDIBuilderCreateReferenceType (
206+ DIB ( cx) ,
207+ DW_TAG_reference_type ,
208+ pointee_type_di_node,
209+ )
210+ } ,
211+ ty:: RawPtr ( _, mutability) => unsafe {
212+ let pointee_type_di_node = if mutability. is_not ( ) {
213+ llvm:: LLVMRustDIBuilderCreateQualifiedType (
214+ DIB ( cx) ,
215+ DW_TAG_const_type ,
216+ pointee_type_di_node,
217+ )
218+ } else {
219+ pointee_type_di_node
220+ } ;
221+ llvm:: LLVMRustDIBuilderCreatePointerType (
222+ DIB ( cx) ,
223+ pointee_type_di_node,
224+ data_layout. pointer_size . bits ( ) ,
225+ data_layout. pointer_align . abi . bits ( ) as u32 ,
226+ 0 , // Ignore DWARF address space.
227+ ptr_type_debuginfo_name. as_c_char_ptr ( ) ,
228+ ptr_type_debuginfo_name. len ( ) ,
229+ )
230+ } ,
231+ ty:: Adt ( _, _) => unsafe {
232+ llvm:: LLVMRustDIBuilderCreatePointerType (
233+ DIB ( cx) ,
234+ pointee_type_di_node,
235+ data_layout. pointer_size . bits ( ) ,
236+ data_layout. pointer_align . abi . bits ( ) as u32 ,
237+ 0 , // Ignore DWARF address space.
238+ ptr_type_debuginfo_name. as_c_char_ptr ( ) ,
239+ ptr_type_debuginfo_name. len ( ) ,
240+ )
241+ } ,
242+ _ => unreachable ! ( "Thin pointer not of type ty::RawPtr, ty::Ref, or ty::Adt" ) ,
193243 } ;
194244
195245 DINodeCreationResult { di_node, already_stored_in_typemap : false }
0 commit comments