@@ -38,6 +38,7 @@ use rustc_session::config::{self, DebugInfo};
38
38
use rustc_span:: symbol:: Symbol ;
39
39
use rustc_span:: FileNameDisplayPreference ;
40
40
use rustc_span:: { self , SourceFile , SourceFileHash } ;
41
+ use rustc_target:: abi:: AddressSpace ;
41
42
use rustc_target:: abi:: { Align , Size } ;
42
43
use smallvec:: smallvec;
43
44
use tracing:: debug;
@@ -174,6 +175,9 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
174
175
cx. size_and_align_of ( cx. tcx . mk_imm_ptr ( cx. tcx . types . unit ) ) ;
175
176
let ptr_type_debuginfo_name = compute_debuginfo_type_name ( cx. tcx , ptr_type, true ) ;
176
177
178
+ let ptr_ty_layout = cx. layout_of ( ptr_type) ;
179
+ let address_space = address_space_of ( cx, ptr_ty_layout) ;
180
+
177
181
match fat_pointer_kind ( cx, pointee_type) {
178
182
None => {
179
183
// This is a thin pointer. Create a regular pointer type and give it the correct name.
@@ -191,7 +195,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
191
195
pointee_type_di_node,
192
196
thin_pointer_size. bits ( ) ,
193
197
thin_pointer_align. bits ( ) as u32 ,
194
- 0 , // Ignore DWARF address space.
198
+ address_space . as_ref ( ) ,
195
199
ptr_type_debuginfo_name. as_ptr ( ) . cast ( ) ,
196
200
ptr_type_debuginfo_name. len ( ) ,
197
201
)
@@ -212,9 +216,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
212
216
DIFlags :: FlagZero ,
213
217
) ,
214
218
|cx, owner| {
215
- let layout = cx. layout_of ( ptr_type) ;
216
- let addr_field = layout. field ( cx, abi:: FAT_PTR_ADDR ) ;
217
- let extra_field = layout. field ( cx, abi:: FAT_PTR_EXTRA ) ;
219
+ let addr_field = ptr_ty_layout. field ( cx, abi:: FAT_PTR_ADDR ) ;
220
+ let extra_field = ptr_ty_layout. field ( cx, abi:: FAT_PTR_EXTRA ) ;
218
221
219
222
let ( addr_field_name, extra_field_name) = match fat_pointer_kind {
220
223
FatPtrKind :: Dyn => ( "pointer" , "vtable" ) ,
@@ -232,7 +235,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
232
235
pointee_type_di_node,
233
236
addr_field. size . bits ( ) ,
234
237
addr_field. align . abi . bits ( ) as u32 ,
235
- 0 , // Ignore DWARF address space.
238
+ address_space . as_ref ( ) ,
236
239
std:: ptr:: null ( ) ,
237
240
0 ,
238
241
)
@@ -244,7 +247,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
244
247
owner,
245
248
addr_field_name,
246
249
( addr_field. size, addr_field. align. abi) ,
247
- layout . fields. offset( abi:: FAT_PTR_ADDR ) ,
250
+ ptr_ty_layout . fields. offset( abi:: FAT_PTR_ADDR ) ,
248
251
DIFlags :: FlagZero ,
249
252
data_ptr_type_di_node,
250
253
) ,
@@ -253,7 +256,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
253
256
owner,
254
257
extra_field_name,
255
258
( extra_field. size, extra_field. align. abi) ,
256
- layout . fields. offset( abi:: FAT_PTR_EXTRA ) ,
259
+ ptr_ty_layout . fields. offset( abi:: FAT_PTR_EXTRA ) ,
257
260
DIFlags :: FlagZero ,
258
261
type_di_node( cx, extra_field. ty) ,
259
262
) ,
@@ -318,6 +321,8 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
318
321
)
319
322
} ;
320
323
324
+ let address_space = address_space_of ( cx, cx. layout_of ( fn_ty) ) ;
325
+
321
326
// This is actually a function pointer, so wrap it in pointer DI.
322
327
let name = compute_debuginfo_type_name ( cx. tcx , fn_ty, false ) ;
323
328
let di_node = unsafe {
@@ -326,7 +331,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
326
331
fn_di_node,
327
332
cx. tcx . data_layout . pointer_size . bits ( ) ,
328
333
cx. tcx . data_layout . pointer_align . abi . bits ( ) as u32 ,
329
- 0 , // Ignore DWARF address space.
334
+ address_space . as_ref ( ) ,
330
335
name. as_ptr ( ) . cast ( ) ,
331
336
name. len ( ) ,
332
337
)
@@ -1479,3 +1484,19 @@ pub fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
1479
1484
. map ( |s| Cow :: from ( * s) )
1480
1485
. unwrap_or_else ( || Cow :: from ( format ! ( "__{}" , field_index) ) )
1481
1486
}
1487
+
1488
+ fn address_space_of < ' ll , ' tcx > (
1489
+ cx : & CodegenCx < ' ll , ' tcx > ,
1490
+ ptr_ty_layout : TyAndLayout < ' tcx > ,
1491
+ ) -> Option < c_uint > {
1492
+ ptr_ty_layout. pointee_info_at ( cx, Size :: ZERO ) . map ( |pi| pi. address_space ) . and_then (
1493
+ |address_space| {
1494
+ if address_space == AddressSpace :: DATA {
1495
+ // Don't emit the DW_AT_address_class attribute for things with AddressSpace::DATA
1496
+ None
1497
+ } else {
1498
+ Some ( address_space. 0 as c_uint )
1499
+ }
1500
+ } ,
1501
+ )
1502
+ }
0 commit comments