@@ -211,6 +211,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
211
211
Stub :: Struct ,
212
212
unique_type_id,
213
213
& ptr_type_debuginfo_name,
214
+ None ,
214
215
cx. size_and_align_of ( ptr_type) ,
215
216
NO_SCOPE_METADATA ,
216
217
DIFlags :: FlagZero ,
@@ -264,6 +265,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
264
265
layout. fields. offset( abi:: FAT_PTR_ADDR ) ,
265
266
DIFlags :: FlagZero ,
266
267
data_ptr_type_di_node,
268
+ None ,
267
269
) ,
268
270
build_field_di_node(
269
271
cx,
@@ -273,6 +275,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
273
275
layout. fields. offset( abi:: FAT_PTR_EXTRA ) ,
274
276
DIFlags :: FlagZero ,
275
277
type_di_node( cx, extra_field. ty) ,
278
+ None ,
276
279
) ,
277
280
]
278
281
} ,
@@ -376,6 +379,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
376
379
Stub :: Struct ,
377
380
unique_type_id,
378
381
& type_name,
382
+ None ,
379
383
cx. size_and_align_of ( dyn_type) ,
380
384
NO_SCOPE_METADATA ,
381
385
DIFlags :: FlagZero ,
@@ -798,6 +802,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
798
802
Stub :: Struct ,
799
803
unique_type_id,
800
804
& compute_debuginfo_type_name ( cx. tcx , t, false ) ,
805
+ None ,
801
806
cx. size_and_align_of ( t) ,
802
807
Some ( get_namespace_for_item ( cx, def_id) ) ,
803
808
DIFlags :: FlagZero ,
@@ -969,15 +974,22 @@ fn build_field_di_node<'ll, 'tcx>(
969
974
offset : Size ,
970
975
flags : DIFlags ,
971
976
type_di_node : & ' ll DIType ,
977
+ def_id : Option < DefId > ,
972
978
) -> & ' ll DIType {
979
+ let ( file_metadata, line_number) = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers
980
+ {
981
+ file_metadata_from_def_id ( cx, def_id)
982
+ } else {
983
+ ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
984
+ } ;
973
985
unsafe {
974
986
llvm:: LLVMRustDIBuilderCreateMemberType (
975
987
DIB ( cx) ,
976
988
owner,
977
989
name. as_ptr ( ) . cast ( ) ,
978
990
name. len ( ) ,
979
- unknown_file_metadata ( cx ) ,
980
- UNKNOWN_LINE_NUMBER ,
991
+ file_metadata ,
992
+ line_number ,
981
993
size_and_align. 0 . bits ( ) ,
982
994
size_and_align. 1 . bits ( ) as u32 ,
983
995
offset. bits ( ) ,
@@ -1021,6 +1033,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1021
1033
let containing_scope = get_namespace_for_item ( cx, adt_def. did ( ) ) ;
1022
1034
let struct_type_and_layout = cx. layout_of ( struct_type) ;
1023
1035
let variant_def = adt_def. non_enum_variant ( ) ;
1036
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1037
+ Some ( file_metadata_from_def_id ( cx, Some ( adt_def. did ( ) ) ) )
1038
+ } else {
1039
+ None
1040
+ } ;
1024
1041
1025
1042
type_map:: build_type_with_children (
1026
1043
cx,
@@ -1029,6 +1046,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1029
1046
Stub :: Struct ,
1030
1047
unique_type_id,
1031
1048
& compute_debuginfo_type_name ( cx. tcx , struct_type, false ) ,
1049
+ def_location,
1032
1050
size_and_align_of ( struct_type_and_layout) ,
1033
1051
Some ( containing_scope) ,
1034
1052
visibility_di_flags ( cx, adt_def. did ( ) , adt_def. did ( ) ) ,
@@ -1048,6 +1066,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1048
1066
Cow :: Borrowed ( f. name . as_str ( ) )
1049
1067
} ;
1050
1068
let field_layout = struct_type_and_layout. field ( cx, i) ;
1069
+ let def_id = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1070
+ Some ( f. did )
1071
+ } else {
1072
+ None
1073
+ } ;
1051
1074
build_field_di_node (
1052
1075
cx,
1053
1076
owner,
@@ -1056,6 +1079,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1056
1079
struct_type_and_layout. fields . offset ( i) ,
1057
1080
visibility_di_flags ( cx, f. did , adt_def. did ( ) ) ,
1058
1081
type_di_node ( cx, field_layout. ty ) ,
1082
+ def_id,
1059
1083
)
1060
1084
} )
1061
1085
. collect ( )
@@ -1107,6 +1131,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
1107
1131
layout. fields . offset ( index) ,
1108
1132
DIFlags :: FlagZero ,
1109
1133
type_di_node ( cx, up_var_ty) ,
1134
+ None ,
1110
1135
)
1111
1136
} )
1112
1137
. collect ( )
@@ -1132,6 +1157,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
1132
1157
Stub :: Struct ,
1133
1158
unique_type_id,
1134
1159
& type_name,
1160
+ None ,
1135
1161
size_and_align_of ( tuple_type_and_layout) ,
1136
1162
NO_SCOPE_METADATA ,
1137
1163
DIFlags :: FlagZero ,
@@ -1150,6 +1176,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
1150
1176
tuple_type_and_layout. fields . offset ( index) ,
1151
1177
DIFlags :: FlagZero ,
1152
1178
type_di_node ( cx, component_type) ,
1179
+ None ,
1153
1180
)
1154
1181
} )
1155
1182
. collect ( )
@@ -1171,13 +1198,20 @@ fn build_closure_env_di_node<'ll, 'tcx>(
1171
1198
let containing_scope = get_namespace_for_item ( cx, def_id) ;
1172
1199
let type_name = compute_debuginfo_type_name ( cx. tcx , closure_env_type, false ) ;
1173
1200
1201
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1202
+ Some ( file_metadata_from_def_id ( cx, Some ( def_id) ) )
1203
+ } else {
1204
+ None
1205
+ } ;
1206
+
1174
1207
type_map:: build_type_with_children (
1175
1208
cx,
1176
1209
type_map:: stub (
1177
1210
cx,
1178
1211
Stub :: Struct ,
1179
1212
unique_type_id,
1180
1213
& type_name,
1214
+ def_location,
1181
1215
cx. size_and_align_of ( closure_env_type) ,
1182
1216
Some ( containing_scope) ,
1183
1217
DIFlags :: FlagZero ,
@@ -1201,6 +1235,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
1201
1235
let containing_scope = get_namespace_for_item ( cx, union_def_id) ;
1202
1236
let union_ty_and_layout = cx. layout_of ( union_type) ;
1203
1237
let type_name = compute_debuginfo_type_name ( cx. tcx , union_type, false ) ;
1238
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1239
+ Some ( file_metadata_from_def_id ( cx, Some ( union_def_id) ) )
1240
+ } else {
1241
+ None
1242
+ } ;
1204
1243
1205
1244
type_map:: build_type_with_children (
1206
1245
cx,
@@ -1209,6 +1248,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
1209
1248
Stub :: Union ,
1210
1249
unique_type_id,
1211
1250
& type_name,
1251
+ def_location,
1212
1252
size_and_align_of ( union_ty_and_layout) ,
1213
1253
Some ( containing_scope) ,
1214
1254
DIFlags :: FlagZero ,
@@ -1221,6 +1261,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
1221
1261
. enumerate ( )
1222
1262
. map ( |( i, f) | {
1223
1263
let field_layout = union_ty_and_layout. field ( cx, i) ;
1264
+ let def_id = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1265
+ Some ( f. did )
1266
+ } else {
1267
+ None
1268
+ } ;
1224
1269
build_field_di_node (
1225
1270
cx,
1226
1271
owner,
@@ -1229,6 +1274,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
1229
1274
Size :: ZERO ,
1230
1275
DIFlags :: FlagZero ,
1231
1276
type_di_node ( cx, field_layout. ty ) ,
1277
+ def_id,
1232
1278
)
1233
1279
} )
1234
1280
. collect ( )
@@ -1300,14 +1346,7 @@ pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, glo
1300
1346
// We may want to remove the namespace scope if we're in an extern block (see
1301
1347
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
1302
1348
let var_scope = get_namespace_for_item ( cx, def_id) ;
1303
- let span = tcx. def_span ( def_id) ;
1304
-
1305
- let ( file_metadata, line_number) = if !span. is_dummy ( ) {
1306
- let loc = cx. lookup_debug_loc ( span. lo ( ) ) ;
1307
- ( file_metadata ( cx, & loc. file ) , loc. line )
1308
- } else {
1309
- ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
1310
- } ;
1349
+ let ( file_metadata, line_number) = file_metadata_from_def_id ( cx, Some ( def_id) ) ;
1311
1350
1312
1351
let is_local_to_unit = is_node_local_to_unit ( cx, def_id) ;
1313
1352
@@ -1397,6 +1436,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
1397
1436
Stub :: VTableTy { vtable_holder } ,
1398
1437
unique_type_id,
1399
1438
& vtable_type_name,
1439
+ None ,
1400
1440
( size, pointer_align) ,
1401
1441
NO_SCOPE_METADATA ,
1402
1442
DIFlags :: FlagArtificial ,
@@ -1434,6 +1474,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
1434
1474
field_offset,
1435
1475
DIFlags :: FlagZero ,
1436
1476
field_type_di_node,
1477
+ None ,
1437
1478
) )
1438
1479
} )
1439
1480
. collect ( )
@@ -1589,3 +1630,20 @@ pub fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
1589
1630
. map ( |s| Cow :: from ( * s) )
1590
1631
. unwrap_or_else ( || Cow :: from ( format ! ( "__{field_index}" ) ) )
1591
1632
}
1633
+
1634
+ pub type DefinitionLocation < ' ll > = ( & ' ll DIFile , c_uint ) ;
1635
+
1636
+ pub fn file_metadata_from_def_id < ' ll > (
1637
+ cx : & CodegenCx < ' ll , ' _ > ,
1638
+ def_id : Option < DefId > ,
1639
+ ) -> DefinitionLocation < ' ll > {
1640
+ if let Some ( def_id) = def_id
1641
+ && let span = cx. tcx . def_span ( def_id)
1642
+ && !span. is_dummy ( )
1643
+ {
1644
+ let loc = cx. lookup_debug_loc ( span. lo ( ) ) ;
1645
+ ( file_metadata ( cx, & loc. file ) , loc. line )
1646
+ } else {
1647
+ ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
1648
+ }
1649
+ }
0 commit comments