@@ -157,7 +157,7 @@ use syntax::parse::token::special_idents;
157
157
static DW_LANG_RUST : c_uint = 0x9000 ;
158
158
159
159
static DW_TAG_auto_variable : c_uint = 0x100 ;
160
- // static DW_TAG_arg_variable: c_uint = 0x101;
160
+ static DW_TAG_arg_variable : c_uint = 0x101 ;
161
161
162
162
static DW_ATE_boolean : c_uint = 0x02 ;
163
163
static DW_ATE_float : c_uint = 0x04 ;
@@ -980,11 +980,11 @@ fn declare_local(bcx: @Block,
980
980
let loc = span_start ( cx, span) ;
981
981
let type_metadata = type_metadata ( cx, variable_type, span) ;
982
982
983
- let argument_index = match variable_kind {
984
- ArgumentVariable ( index) => index,
983
+ let ( argument_index, dwarf_tag ) = match variable_kind {
984
+ ArgumentVariable ( index) => ( index as c_uint , DW_TAG_arg_variable ) ,
985
985
LocalVariable |
986
- CapturedVariable => 0
987
- } as c_uint ;
986
+ CapturedVariable => ( 0 , DW_TAG_auto_variable )
987
+ } ;
988
988
989
989
let ( var_alloca, var_metadata) = name. with_c_str ( |name| {
990
990
match variable_access {
@@ -993,7 +993,7 @@ fn declare_local(bcx: @Block,
993
993
unsafe {
994
994
llvm:: LLVMDIBuilderCreateLocalVariable (
995
995
DIB ( cx) ,
996
- DW_TAG_auto_variable ,
996
+ dwarf_tag ,
997
997
scope_metadata,
998
998
name,
999
999
file_metadata,
@@ -1009,7 +1009,7 @@ fn declare_local(bcx: @Block,
1009
1009
unsafe {
1010
1010
llvm:: LLVMDIBuilderCreateComplexVariable (
1011
1011
DIB ( cx) ,
1012
- DW_TAG_auto_variable ,
1012
+ dwarf_tag ,
1013
1013
scope_metadata,
1014
1014
name,
1015
1015
file_metadata,
@@ -1256,14 +1256,12 @@ impl RecursiveTypeDescription {
1256
1256
} => {
1257
1257
// Insert the stub into the cache in order to allow recursive references ...
1258
1258
{
1259
- let mut created_types = debug_context ( cx) . created_types
1260
- . borrow_mut ( ) ;
1259
+ let mut created_types = debug_context ( cx) . created_types . borrow_mut ( ) ;
1261
1260
created_types. get ( ) . insert ( cache_id, metadata_stub) ;
1262
1261
}
1263
1262
1264
1263
// ... then create the member descriptions ...
1265
- let member_descriptions = member_description_factory.
1266
- create_member_descriptions ( cx) ;
1264
+ let member_descriptions = member_description_factory. create_member_descriptions ( cx) ;
1267
1265
1268
1266
// ... and attach them to the stub to complete it.
1269
1267
set_members_of_composite_type ( cx,
@@ -1348,13 +1346,13 @@ impl MemberDescriptionFactory for GeneralMemberDescriptionFactory {
1348
1346
. enumerate ( )
1349
1347
. map ( |( i, struct_def) | {
1350
1348
let ( variant_type_metadata, variant_llvm_type, member_desc_factory) =
1351
- describe_variant ( cx,
1352
- struct_def,
1353
- self . variants [ i] ,
1354
- Some ( self . discriminant_type_metadata ) ,
1355
- self . containing_scope ,
1356
- self . file_metadata ,
1357
- self . span ) ;
1349
+ describe_enum_variant ( cx,
1350
+ struct_def,
1351
+ self . variants [ i] ,
1352
+ Some ( self . discriminant_type_metadata ) ,
1353
+ self . containing_scope ,
1354
+ self . file_metadata ,
1355
+ self . span ) ;
1358
1356
1359
1357
let member_descriptions =
1360
1358
member_desc_factory. create_member_descriptions ( cx) ;
@@ -1398,14 +1396,14 @@ impl MemberDescriptionFactory for EnumVariantMemberDescriptionFactory {
1398
1396
}
1399
1397
}
1400
1398
1401
- fn describe_variant ( cx : & CrateContext ,
1402
- struct_def : & adt:: Struct ,
1403
- variant_info : & ty:: VariantInfo ,
1404
- discriminant_type_metadata : Option < DIType > ,
1405
- containing_scope : DIScope ,
1406
- file_metadata : DIFile ,
1407
- span : Span )
1408
- -> ( DICompositeType , Type , @MemberDescriptionFactory ) {
1399
+ fn describe_enum_variant ( cx : & CrateContext ,
1400
+ struct_def : & adt:: Struct ,
1401
+ variant_info : & ty:: VariantInfo ,
1402
+ discriminant_type_metadata : Option < DIType > ,
1403
+ containing_scope : DIScope ,
1404
+ file_metadata : DIFile ,
1405
+ span : Span )
1406
+ -> ( DICompositeType , Type , @MemberDescriptionFactory ) {
1409
1407
let variant_name = token:: ident_to_str ( & variant_info. name ) ;
1410
1408
let variant_llvm_type = Type :: struct_ ( struct_def. fields . map ( |& t| type_of:: type_of ( cx, t) ) ,
1411
1409
struct_def. packed ) ;
@@ -1538,13 +1536,13 @@ fn prepare_enum_metadata(cx: &CrateContext,
1538
1536
assert ! ( variants. len( ) == 1 ) ;
1539
1537
let ( metadata_stub,
1540
1538
variant_llvm_type,
1541
- member_description_factory) = describe_variant ( cx,
1542
- struct_def,
1543
- variants[ 0 ] ,
1544
- None ,
1545
- containing_scope,
1546
- file_metadata,
1547
- span) ;
1539
+ member_description_factory) = describe_enum_variant ( cx,
1540
+ struct_def,
1541
+ variants[ 0 ] ,
1542
+ None ,
1543
+ containing_scope,
1544
+ file_metadata,
1545
+ span) ;
1548
1546
UnfinishedMetadata {
1549
1547
cache_id : cache_id_for_type ( enum_type) ,
1550
1548
metadata_stub : metadata_stub,
@@ -1557,21 +1555,25 @@ fn prepare_enum_metadata(cx: &CrateContext,
1557
1555
let discriminant_type_metadata = discriminant_type_metadata ( inttype) ;
1558
1556
let enum_llvm_type = type_of:: type_of ( cx, enum_type) ;
1559
1557
let ( enum_type_size, enum_type_align) = size_and_align_of ( cx, enum_llvm_type) ;
1558
+ let unique_id = generate_unique_type_id ( "DI_ENUM_" ) ;
1560
1559
1561
1560
let enum_metadata = enum_name. with_c_str ( |enum_name| {
1562
- unsafe {
1563
- llvm:: LLVMDIBuilderCreateUnionType (
1564
- DIB ( cx) ,
1565
- containing_scope,
1566
- enum_name,
1567
- file_metadata,
1568
- loc. line as c_uint ,
1569
- bytes_to_bits ( enum_type_size) ,
1570
- bytes_to_bits ( enum_type_align) ,
1571
- 0 , // Flags
1572
- ptr:: null ( ) ,
1573
- 0 ) // RuntimeLang
1574
- }
1561
+ unique_id. with_c_str ( |unique_id| {
1562
+ unsafe {
1563
+ llvm:: LLVMDIBuilderCreateUnionType (
1564
+ DIB ( cx) ,
1565
+ containing_scope,
1566
+ enum_name,
1567
+ file_metadata,
1568
+ loc. line as c_uint ,
1569
+ bytes_to_bits ( enum_type_size) ,
1570
+ bytes_to_bits ( enum_type_align) ,
1571
+ 0 , // Flags
1572
+ ptr:: null ( ) ,
1573
+ 0 , // RuntimeLang
1574
+ unique_id)
1575
+ }
1576
+ } )
1575
1577
} ) ;
1576
1578
1577
1579
UnfinishedMetadata {
@@ -1592,13 +1594,13 @@ fn prepare_enum_metadata(cx: &CrateContext,
1592
1594
adt:: NullablePointer { nonnull : ref struct_def, nndiscr, .. } => {
1593
1595
let ( metadata_stub,
1594
1596
variant_llvm_type,
1595
- member_description_factory) = describe_variant ( cx,
1596
- struct_def,
1597
- variants[ nndiscr] ,
1598
- None ,
1599
- containing_scope,
1600
- file_metadata,
1601
- span) ;
1597
+ member_description_factory) = describe_enum_variant ( cx,
1598
+ struct_def,
1599
+ variants[ nndiscr] ,
1600
+ None ,
1601
+ containing_scope,
1602
+ file_metadata,
1603
+ span) ;
1602
1604
UnfinishedMetadata {
1603
1605
cache_id : cache_id_for_type ( enum_type) ,
1604
1606
metadata_stub : metadata_stub,
@@ -1725,10 +1727,7 @@ fn create_struct_stub(cx: &CrateContext,
1725
1727
1726
1728
// We assign unique IDs to the type stubs so LLVM metadata uniquing does not reuse instances
1727
1729
// where we don't want it.
1728
- let unique_id = unsafe {
1729
- static mut unique_id_counter: atomics:: AtomicUint = atomics:: INIT_ATOMIC_UINT ;
1730
- format ! ( "DiStructStub{}" , unique_id_counter. fetch_add( 1 , atomics:: SeqCst ) )
1731
- } ;
1730
+ let unique_id = generate_unique_type_id ( "DI_STRUCT_" ) ;
1732
1731
1733
1732
return unsafe {
1734
1733
struct_type_name. with_c_str ( |name| {
@@ -2059,10 +2058,6 @@ fn trait_metadata(cx: &CrateContext,
2059
2058
definition_span) ;
2060
2059
}
2061
2060
2062
- fn cache_id_for_type ( t : ty:: t ) -> uint {
2063
- ty:: type_id ( t)
2064
- }
2065
-
2066
2061
fn type_metadata ( cx : & CrateContext ,
2067
2062
t : ty:: t ,
2068
2063
usage_site_span : Span )
@@ -2244,6 +2239,19 @@ fn set_debug_location(cx: &CrateContext, debug_location: DebugLocation) {
2244
2239
// Utility Functions
2245
2240
//=-------------------------------------------------------------------------------------------------
2246
2241
2242
+ fn cache_id_for_type ( t : ty:: t ) -> uint {
2243
+ ty:: type_id ( t)
2244
+ }
2245
+
2246
+ // Used to avoid LLVM metadata uniquing problems. See `create_struct_stub()` and
2247
+ // `prepare_enum_metadata()`.
2248
+ fn generate_unique_type_id ( prefix : & ' static str ) -> ~str {
2249
+ unsafe {
2250
+ static mut unique_id_counter: atomics:: AtomicUint = atomics:: INIT_ATOMIC_UINT ;
2251
+ format ! ( "{}{}" , prefix, unique_id_counter. fetch_add( 1 , atomics:: SeqCst ) )
2252
+ }
2253
+ }
2254
+
2247
2255
/// Return codemap::Loc corresponding to the beginning of the span
2248
2256
fn span_start ( cx : & CrateContext , span : Span ) -> codemap:: Loc {
2249
2257
cx. sess . codemap . lookup_char_pos ( span. lo )
0 commit comments