Skip to content

Commit 928ce35

Browse files
authored
Unrolled build for rust-lang#136895
Rollup merge of rust-lang#136895 - maurer:fix-enum-discr, r=nikic debuginfo: Set bitwidth appropriately in enum variant tags Previously, we unconditionally set the bitwidth to 128-bits, the largest an enum would possibly be. Then, LLVM would cut down the constant by chopping off leading zeroes before emitting the DWARF. LLVM only supported 64-bit enumerators, so this would also have occasionally resulted in truncated data. LLVM added support for 128-bit enumerators in llvm/llvm-project#125578 That patchset trusts the constant to describe how wide the variant tag is, so the high 64-bits of zeros are considered potentially load-bearing. As a result, we went from emitting tags that looked like: DW_AT_discr_value (0xfe) (because `dwarf::BestForm` selected `data1`) to emitting tags that looked like: DW_AT_discr_value (<0x10> fe ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ) This makes the `DW_AT_discr_value` encode at the bitwidth of the tag, which: 1. Is probably closer to our intentions in terms of describing the data. 2. Doesn't invoke the 128-bit support which may not be supported by all debuggers / downstream tools. 3. Will result in smaller debug information.
2 parents a567209 + d82219a commit 928ce35

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
437437
.source_info
438438
.unwrap_or_else(|| (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER));
439439

440+
let discr = discr_value.opt_single_val().map(|value| {
441+
let tag_base_type = tag_base_type(cx.tcx, enum_type_and_layout);
442+
let size = cx.size_of(tag_base_type);
443+
cx.const_uint_big(cx.type_ix(size.bits()), value)
444+
});
445+
440446
unsafe {
441447
llvm::LLVMRustDIBuilderCreateVariantMemberType(
442448
DIB(cx),
@@ -448,7 +454,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
448454
enum_type_and_layout.size.bits(),
449455
enum_type_and_layout.align.abi.bits() as u32,
450456
Size::ZERO.bits(),
451-
discr_value.opt_single_val().map(|value| cx.const_u128(value)),
457+
discr,
452458
DIFlags::FlagZero,
453459
variant_member_info.variant_struct_type_di_node,
454460
)

tests/codegen/enum/enum-debug-niche-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//@ ignore-msvc
66
//
77
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
8-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
9-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
8+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i32 -1{{[,)].*}}
9+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i32 0{{[,)].*}}
1010
#![feature(never_type)]
1111

1212
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)