@@ -62,8 +62,8 @@ pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
62
62
pub const UNKNOWN_COLUMN_NUMBER : c_uint = 0 ;
63
63
64
64
// ptr::null() doesn't work :(
65
- const UNKNOWN_FILE_METADATA : DIFile = ( 0 as DIFile ) ;
66
- const UNKNOWN_SCOPE_METADATA : DIScope = ( 0 as DIScope ) ;
65
+ const NO_FILE_METADATA : DIFile = ( 0 as DIFile ) ;
66
+ const NO_SCOPE_METADATA : DIScope = ( 0 as DIScope ) ;
67
67
68
68
const FLAGS_NONE : c_uint = 0 ;
69
69
@@ -565,7 +565,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
565
565
& slice_type_name[ ..] ,
566
566
unique_type_id,
567
567
& member_descriptions,
568
- UNKNOWN_SCOPE_METADATA ,
568
+ NO_SCOPE_METADATA ,
569
569
file_metadata,
570
570
span) ;
571
571
return MetadataCreationResult :: new ( metadata, false ) ;
@@ -610,7 +610,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
610
610
unsafe {
611
611
llvm:: LLVMDIBuilderCreateSubroutineType (
612
612
DIB ( cx) ,
613
- UNKNOWN_FILE_METADATA ,
613
+ NO_FILE_METADATA ,
614
614
create_DIArray ( DIB ( cx) , & signature_metadata[ ..] ) )
615
615
} ,
616
616
false ) ;
@@ -654,7 +654,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
654
654
unique_type_id,
655
655
& [ ] ,
656
656
containing_scope,
657
- UNKNOWN_FILE_METADATA ,
657
+ NO_FILE_METADATA ,
658
658
codemap:: DUMMY_SP )
659
659
}
660
660
@@ -850,13 +850,6 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
850
850
}
851
851
852
852
pub fn file_metadata ( cx : & CrateContext , full_path : & str ) -> DIFile {
853
- match debug_context ( cx) . created_files . borrow ( ) . get ( full_path) {
854
- Some ( file_metadata) => return * file_metadata,
855
- None => ( )
856
- }
857
-
858
- debug ! ( "file_metadata: {}" , full_path) ;
859
-
860
853
// FIXME (#9639): This needs to handle non-utf8 paths
861
854
let work_dir = cx. sess ( ) . working_dir . to_str ( ) . unwrap ( ) ;
862
855
let file_name =
@@ -866,6 +859,24 @@ pub fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
866
859
full_path
867
860
} ;
868
861
862
+ file_metadata_ ( cx, full_path, file_name, & work_dir)
863
+ }
864
+
865
+ pub fn unknown_file_metadata ( cx : & CrateContext ) -> DIFile {
866
+ // Regular filenames should not be empty, so we abuse an empty name as the
867
+ // key for the special unknown file metadata
868
+ file_metadata_ ( cx, "" , "<unknown>" , "" )
869
+
870
+ }
871
+
872
+ fn file_metadata_ ( cx : & CrateContext , key : & str , file_name : & str , work_dir : & str ) -> DIFile {
873
+ match debug_context ( cx) . created_files . borrow ( ) . get ( key) {
874
+ Some ( file_metadata) => return * file_metadata,
875
+ None => ( )
876
+ }
877
+
878
+ debug ! ( "file_metadata: file_name: {}, work_dir: {}" , file_name, work_dir) ;
879
+
869
880
let file_name = CString :: new ( file_name) . unwrap ( ) ;
870
881
let work_dir = CString :: new ( work_dir) . unwrap ( ) ;
871
882
let file_metadata = unsafe {
@@ -874,8 +885,8 @@ pub fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
874
885
} ;
875
886
876
887
let mut created_files = debug_context ( cx) . created_files . borrow_mut ( ) ;
877
- created_files. insert ( full_path . to_string ( ) , file_metadata) ;
878
- return file_metadata;
888
+ created_files. insert ( key . to_string ( ) , file_metadata) ;
889
+ file_metadata
879
890
}
880
891
881
892
/// Finds the scope metadata node for the given AST node.
@@ -1226,7 +1237,7 @@ fn prepare_tuple_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1226
1237
tuple_llvm_type,
1227
1238
& tuple_name[ ..] ,
1228
1239
unique_type_id,
1229
- UNKNOWN_SCOPE_METADATA ) ,
1240
+ NO_SCOPE_METADATA ) ,
1230
1241
tuple_llvm_type,
1231
1242
TupleMDF ( TupleMemberDescriptionFactory {
1232
1243
component_types : component_types. to_vec ( ) ,
@@ -1569,9 +1580,14 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1569
1580
-> RecursiveTypeDescription < ' tcx > {
1570
1581
let enum_name = compute_debuginfo_type_name ( cx, enum_type, false ) ;
1571
1582
1572
- let ( containing_scope, definition_span) = get_namespace_and_span_for_item ( cx, enum_def_id) ;
1573
- let loc = span_start ( cx, definition_span) ;
1574
- let file_metadata = file_metadata ( cx, & loc. file . name ) ;
1583
+ let ( containing_scope, _) = get_namespace_and_span_for_item ( cx, enum_def_id) ;
1584
+ // FIXME: This should emit actual file metadata for the enum, but we
1585
+ // currently can't get the necessary information when it comes to types
1586
+ // imported from other crates. Formerly we violated the ODR when performing
1587
+ // LTO because we emitted debuginfo for the same type with varying file
1588
+ // metadata, so as a workaround we pretend that the type comes from
1589
+ // <unknown>
1590
+ let file_metadata = unknown_file_metadata ( cx) ;
1575
1591
1576
1592
let variants = & enum_type. ty_adt_def ( ) . unwrap ( ) . variants ;
1577
1593
@@ -1612,7 +1628,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1612
1628
DIB ( cx) ,
1613
1629
containing_scope,
1614
1630
name. as_ptr ( ) ,
1615
- UNKNOWN_FILE_METADATA ,
1631
+ NO_FILE_METADATA ,
1616
1632
UNKNOWN_LINE_NUMBER ,
1617
1633
bytes_to_bits ( discriminant_size) ,
1618
1634
bytes_to_bits ( discriminant_align) ,
@@ -1758,7 +1774,7 @@ fn set_members_of_composite_type(cx: &CrateContext,
1758
1774
DIB ( cx) ,
1759
1775
composite_type_metadata,
1760
1776
member_name. as_ptr ( ) ,
1761
- UNKNOWN_FILE_METADATA ,
1777
+ NO_FILE_METADATA ,
1762
1778
UNKNOWN_LINE_NUMBER ,
1763
1779
bytes_to_bits ( member_size) ,
1764
1780
bytes_to_bits ( member_align) ,
@@ -1801,7 +1817,7 @@ fn create_struct_stub(cx: &CrateContext,
1801
1817
DIB ( cx) ,
1802
1818
containing_scope,
1803
1819
name. as_ptr ( ) ,
1804
- UNKNOWN_FILE_METADATA ,
1820
+ NO_FILE_METADATA ,
1805
1821
UNKNOWN_LINE_NUMBER ,
1806
1822
bytes_to_bits ( struct_size) ,
1807
1823
bytes_to_bits ( struct_align) ,
@@ -1862,7 +1878,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
1862
1878
let loc = span_start ( cx, span) ;
1863
1879
( file_metadata ( cx, & loc. file . name ) , loc. line as c_uint )
1864
1880
} else {
1865
- ( UNKNOWN_FILE_METADATA , UNKNOWN_LINE_NUMBER )
1881
+ ( NO_FILE_METADATA , UNKNOWN_LINE_NUMBER )
1866
1882
} ;
1867
1883
1868
1884
let is_local_to_unit = is_node_local_to_unit ( cx, node_id) ;
0 commit comments