Skip to content

Commit 6c2557f

Browse files
committed
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 also trusts the constant to describe how wide the variant tag is. As a result, we went from emitting tags that looked like: DW_AT_discr_value (0xfe) (`form1`) 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.
1 parent 8c61cd4 commit 6c2557f

File tree

1 file changed

+6
-1
lines changed
  • compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ 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 size = cx.size_of(tag_base_type);
442+
cx.const_uint_big(cx.type_ix(size.bits()), value)
443+
});
444+
440445
unsafe {
441446
llvm::LLVMRustDIBuilderCreateVariantMemberType(
442447
DIB(cx),
@@ -448,7 +453,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
448453
enum_type_and_layout.size.bits(),
449454
enum_type_and_layout.align.abi.bits() as u32,
450455
Size::ZERO.bits(),
451-
discr_value.opt_single_val().map(|value| cx.const_u128(value)),
456+
discr,
452457
DIFlags::FlagZero,
453458
variant_member_info.variant_struct_type_di_node,
454459
)

0 commit comments

Comments
 (0)