@@ -63,8 +63,8 @@ pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
63
63
pub const UNKNOWN_COLUMN_NUMBER : c_uint = 0 ;
64
64
65
65
// ptr::null() doesn't work :(
66
- const UNKNOWN_FILE_METADATA : DIFile = ( 0 as DIFile ) ;
67
- const UNKNOWN_SCOPE_METADATA : DIScope = ( 0 as DIScope ) ;
66
+ const NO_FILE_METADATA : DIFile = ( 0 as DIFile ) ;
67
+ const NO_SCOPE_METADATA : DIScope = ( 0 as DIScope ) ;
68
68
69
69
const FLAGS_NONE : c_uint = 0 ;
70
70
@@ -566,7 +566,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
566
566
& slice_type_name[ ..] ,
567
567
unique_type_id,
568
568
& member_descriptions,
569
- UNKNOWN_SCOPE_METADATA ,
569
+ NO_SCOPE_METADATA ,
570
570
file_metadata,
571
571
span) ;
572
572
return MetadataCreationResult :: new ( metadata, false ) ;
@@ -611,7 +611,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
611
611
unsafe {
612
612
llvm:: LLVMDIBuilderCreateSubroutineType (
613
613
DIB ( cx) ,
614
- UNKNOWN_FILE_METADATA ,
614
+ NO_FILE_METADATA ,
615
615
create_DIArray ( DIB ( cx) , & signature_metadata[ ..] ) )
616
616
} ,
617
617
false ) ;
@@ -655,7 +655,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
655
655
unique_type_id,
656
656
& [ ] ,
657
657
containing_scope,
658
- UNKNOWN_FILE_METADATA ,
658
+ NO_FILE_METADATA ,
659
659
codemap:: DUMMY_SP )
660
660
}
661
661
@@ -851,13 +851,6 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
851
851
}
852
852
853
853
pub fn file_metadata ( cx : & CrateContext , full_path : & str ) -> DIFile {
854
- match debug_context ( cx) . created_files . borrow ( ) . get ( full_path) {
855
- Some ( file_metadata) => return * file_metadata,
856
- None => ( )
857
- }
858
-
859
- debug ! ( "file_metadata: {}" , full_path) ;
860
-
861
854
// FIXME (#9639): This needs to handle non-utf8 paths
862
855
let work_dir = cx. sess ( ) . working_dir . to_str ( ) . unwrap ( ) ;
863
856
let file_name =
@@ -867,6 +860,24 @@ pub fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
867
860
full_path
868
861
} ;
869
862
863
+ file_metadata_ ( cx, full_path, file_name, & work_dir)
864
+ }
865
+
866
+ pub fn unknown_file_metadata ( cx : & CrateContext ) -> DIFile {
867
+ // Regular filenames should not be empty, so we abuse an empty name as the
868
+ // key for the special unknown file metadata
869
+ file_metadata_ ( cx, "" , "<unknown>" , "" )
870
+
871
+ }
872
+
873
+ fn file_metadata_ ( cx : & CrateContext , key : & str , file_name : & str , work_dir : & str ) -> DIFile {
874
+ match debug_context ( cx) . created_files . borrow ( ) . get ( key) {
875
+ Some ( file_metadata) => return * file_metadata,
876
+ None => ( )
877
+ }
878
+
879
+ debug ! ( "file_metadata: file_name: {}, work_dir: {}" , file_name, work_dir) ;
880
+
870
881
let file_name = CString :: new ( file_name) . unwrap ( ) ;
871
882
let work_dir = CString :: new ( work_dir) . unwrap ( ) ;
872
883
let file_metadata = unsafe {
@@ -875,8 +886,8 @@ pub fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
875
886
} ;
876
887
877
888
let mut created_files = debug_context ( cx) . created_files . borrow_mut ( ) ;
878
- created_files. insert ( full_path . to_string ( ) , file_metadata) ;
879
- return file_metadata;
889
+ created_files. insert ( key . to_string ( ) , file_metadata) ;
890
+ file_metadata
880
891
}
881
892
882
893
/// Finds the scope metadata node for the given AST node.
@@ -1227,7 +1238,7 @@ fn prepare_tuple_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1227
1238
tuple_llvm_type,
1228
1239
& tuple_name[ ..] ,
1229
1240
unique_type_id,
1230
- UNKNOWN_SCOPE_METADATA ) ,
1241
+ NO_SCOPE_METADATA ) ,
1231
1242
tuple_llvm_type,
1232
1243
TupleMDF ( TupleMemberDescriptionFactory {
1233
1244
component_types : component_types. to_vec ( ) ,
@@ -1570,9 +1581,14 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1570
1581
-> RecursiveTypeDescription < ' tcx > {
1571
1582
let enum_name = compute_debuginfo_type_name ( cx, enum_type, false ) ;
1572
1583
1573
- let ( containing_scope, definition_span) = get_namespace_and_span_for_item ( cx, enum_def_id) ;
1574
- let loc = span_start ( cx, definition_span) ;
1575
- let file_metadata = file_metadata ( cx, & loc. file . name ) ;
1584
+ let ( containing_scope, _) = get_namespace_and_span_for_item ( cx, enum_def_id) ;
1585
+ // FIXME: This should emit actual file metadata for the enum, but we
1586
+ // currently can't get the necessary information when it comes to types
1587
+ // imported from other crates. Formerly we violated the ODR when performing
1588
+ // LTO because we emitted debuginfo for the same type with varying file
1589
+ // metadata, so as a workaround we pretend that the type comes from
1590
+ // <unknown>
1591
+ let file_metadata = unknown_file_metadata ( cx) ;
1576
1592
1577
1593
let variants = & enum_type. ty_adt_def ( ) . unwrap ( ) . variants ;
1578
1594
@@ -1613,7 +1629,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1613
1629
DIB ( cx) ,
1614
1630
containing_scope,
1615
1631
name. as_ptr ( ) ,
1616
- UNKNOWN_FILE_METADATA ,
1632
+ NO_FILE_METADATA ,
1617
1633
UNKNOWN_LINE_NUMBER ,
1618
1634
bytes_to_bits ( discriminant_size) ,
1619
1635
bytes_to_bits ( discriminant_align) ,
@@ -1765,7 +1781,7 @@ fn set_members_of_composite_type(cx: &CrateContext,
1765
1781
DIB ( cx) ,
1766
1782
composite_type_metadata,
1767
1783
member_name. as_ptr ( ) ,
1768
- UNKNOWN_FILE_METADATA ,
1784
+ NO_FILE_METADATA ,
1769
1785
UNKNOWN_LINE_NUMBER ,
1770
1786
bytes_to_bits ( member_size) ,
1771
1787
bytes_to_bits ( member_align) ,
@@ -1808,7 +1824,7 @@ fn create_struct_stub(cx: &CrateContext,
1808
1824
DIB ( cx) ,
1809
1825
containing_scope,
1810
1826
name. as_ptr ( ) ,
1811
- UNKNOWN_FILE_METADATA ,
1827
+ NO_FILE_METADATA ,
1812
1828
UNKNOWN_LINE_NUMBER ,
1813
1829
bytes_to_bits ( struct_size) ,
1814
1830
bytes_to_bits ( struct_align) ,
@@ -1869,7 +1885,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
1869
1885
let loc = span_start ( cx, span) ;
1870
1886
( file_metadata ( cx, & loc. file . name ) , loc. line as c_uint )
1871
1887
} else {
1872
- ( UNKNOWN_FILE_METADATA , UNKNOWN_LINE_NUMBER )
1888
+ ( NO_FILE_METADATA , UNKNOWN_LINE_NUMBER )
1873
1889
} ;
1874
1890
1875
1891
let is_local_to_unit = is_node_local_to_unit ( cx, node_id) ;
0 commit comments