@@ -309,6 +309,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
309
309
unfinished_type,
310
310
member_holding_stub,
311
311
member_descriptions,
312
+ None ,
312
313
) ;
313
314
MetadataCreationResult :: new ( metadata_stub, true )
314
315
}
@@ -1459,6 +1460,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
1459
1460
layout : TyAndLayout < ' tcx > ,
1460
1461
tag_type_metadata : Option < & ' ll DIType > ,
1461
1462
containing_scope : & ' ll DIScope ,
1463
+ common_members : Vec < Option < & ' ll DIType > > ,
1462
1464
span : Span ,
1463
1465
}
1464
1466
@@ -1523,6 +1525,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
1523
1525
self . enum_type ,
1524
1526
variant_type_metadata,
1525
1527
member_descriptions,
1528
+ Some ( & self . common_members ) ,
1526
1529
) ;
1527
1530
vec ! [ MemberDescription {
1528
1531
name: if fallback { String :: new( ) } else { variant_info. variant_name( ) } ,
@@ -1572,6 +1575,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
1572
1575
self . enum_type ,
1573
1576
variant_type_metadata,
1574
1577
member_descriptions,
1578
+ Some ( & self . common_members ) ,
1575
1579
) ;
1576
1580
1577
1581
MemberDescription {
@@ -1621,6 +1625,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
1621
1625
self . enum_type ,
1622
1626
variant_type_metadata,
1623
1627
variant_member_descriptions,
1628
+ Some ( & self . common_members ) ,
1624
1629
) ;
1625
1630
1626
1631
// Encode the information about the null variant in the union
@@ -1695,6 +1700,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
1695
1700
self . enum_type ,
1696
1701
variant_type_metadata,
1697
1702
member_descriptions,
1703
+ Some ( & self . common_members ) ,
1698
1704
) ;
1699
1705
1700
1706
let niche_value = if i == dataful_variant {
@@ -2102,6 +2108,7 @@ fn prepare_enum_metadata(
2102
2108
layout,
2103
2109
tag_type_metadata : discriminant_type_metadata,
2104
2110
containing_scope,
2111
+ common_members : vec ! [ ] ,
2105
2112
span,
2106
2113
} ) ,
2107
2114
) ;
@@ -2171,7 +2178,7 @@ fn prepare_enum_metadata(
2171
2178
}
2172
2179
} ;
2173
2180
2174
- let mut outer_fields = match layout. variants {
2181
+ let outer_fields = match layout. variants {
2175
2182
Variants :: Single { .. } => vec ! [ ] ,
2176
2183
Variants :: Multiple { .. } => {
2177
2184
let tuple_mdf = TupleMemberDescriptionFactory {
@@ -2210,11 +2217,14 @@ fn prepare_enum_metadata(
2210
2217
variant_part_unique_type_id_str. len ( ) ,
2211
2218
)
2212
2219
} ;
2213
- outer_fields. push ( Some ( variant_part) ) ;
2214
2220
2215
2221
let struct_wrapper = {
2216
2222
// The variant part must be wrapped in a struct according to DWARF.
2217
- let type_array = create_DIArray ( DIB ( cx) , & outer_fields) ;
2223
+ // All fields except the discriminant (including `outer_fields`)
2224
+ // should be put into structures inside the variant part, which gives
2225
+ // an equivalent layout but offers us much better integration with
2226
+ // debuggers.
2227
+ let type_array = create_DIArray ( DIB ( cx) , & [ Some ( variant_part) ] ) ;
2218
2228
2219
2229
let type_map = debug_context ( cx) . type_map . borrow ( ) ;
2220
2230
let unique_type_id_str = type_map. get_unique_type_id_as_string ( unique_type_id) ;
@@ -2251,6 +2261,7 @@ fn prepare_enum_metadata(
2251
2261
layout,
2252
2262
tag_type_metadata : None ,
2253
2263
containing_scope,
2264
+ common_members : outer_fields,
2254
2265
span,
2255
2266
} ) ,
2256
2267
)
@@ -2283,7 +2294,13 @@ fn composite_type_metadata(
2283
2294
DIFlags :: FlagZero ,
2284
2295
) ;
2285
2296
// ... and immediately create and add the member descriptions.
2286
- set_members_of_composite_type ( cx, composite_type, composite_type_metadata, member_descriptions) ;
2297
+ set_members_of_composite_type (
2298
+ cx,
2299
+ composite_type,
2300
+ composite_type_metadata,
2301
+ member_descriptions,
2302
+ None ,
2303
+ ) ;
2287
2304
2288
2305
composite_type_metadata
2289
2306
}
@@ -2293,6 +2310,7 @@ fn set_members_of_composite_type(
2293
2310
composite_type : Ty < ' tcx > ,
2294
2311
composite_type_metadata : & ' ll DICompositeType ,
2295
2312
member_descriptions : Vec < MemberDescription < ' ll > > ,
2313
+ common_members : Option < & Vec < Option < & ' ll DIType > > > ,
2296
2314
) {
2297
2315
// In some rare cases LLVM metadata uniquing would lead to an existing type
2298
2316
// description being used instead of a new one created in
@@ -2311,10 +2329,13 @@ fn set_members_of_composite_type(
2311
2329
}
2312
2330
}
2313
2331
2314
- let member_metadata: Vec < _ > = member_descriptions
2332
+ let mut member_metadata: Vec < _ > = member_descriptions
2315
2333
. into_iter ( )
2316
2334
. map ( |desc| Some ( desc. into_metadata ( cx, composite_type_metadata) ) )
2317
2335
. collect ( ) ;
2336
+ if let Some ( other_members) = common_members {
2337
+ member_metadata. extend ( other_members. iter ( ) ) ;
2338
+ }
2318
2339
2319
2340
let type_params = compute_type_parameters ( cx, composite_type) ;
2320
2341
unsafe {
0 commit comments