See #55701 (comment), this is just one-line addition for the assert.
Currently, this example:
#![feature(repr128)]
#[repr(u128)]
pub enum Foo {
Lo,
Hi = 1 << 64,
Bar = 18_446_745_000_000_000_123,
}
pub fn foo() -> Option<Foo> {
None
}
has this in its LLVM IR (in debug mode):
!22 = !DIDerivedType(tag: DW_TAG_member, name: "None", scope: !20, file: !6, baseType: !23, size: 128, align: 64, extraData: i64 926290448508)
Note the extraData, which indicates the discriminant (niche, in this case), it should be the same value as Foo::Bar, plus 1, but is instead the truncated value (see below).
The debuginfo for Foo is also wrong, but that is caused elsewhere in the codebase (in a spot where no assertion was ever added AFAIK. also see #59509 (comment)):
!10 = !DIEnumerator(name: "Lo", value: 0)
!11 = !DIEnumerator(name: "Hi", value: 0)
!12 = !DIEnumerator(name: "Bar", value: 926290448507)
The compiler should ICE, instead, to avoid generating the wrong debuginfo.
Alternatively, if LLVM and DWARF support it, we should encode the 128-bit discriminant, by employing const_uint_big instead of const_u64 here:
|
Some(value) => Some(cx.const_u64(value)), |
Also, this field would need to become
Option<u128>:
|
discriminant: Option<u64>, |
See #55701 (comment), this is just one-line addition for the assert.
Currently, this example:
has this in its LLVM IR (in debug mode):
Note the
extraData, which indicates the discriminant (niche, in this case), it should be the same value asFoo::Bar, plus1, but is instead the truncated value (see below).The debuginfo for
Foois also wrong, but that is caused elsewhere in the codebase (in a spot where no assertion was ever added AFAIK. also see #59509 (comment)):The compiler should ICE, instead, to avoid generating the wrong debuginfo.
Alternatively, if LLVM and DWARF support it, we should encode the 128-bit discriminant, by employing
const_uint_biginstead ofconst_u64here:rust/src/librustc_codegen_llvm/debuginfo/metadata.rs
Line 1817 in 237bf32
Also, this field would need to become
Option<u128>:rust/src/librustc_codegen_llvm/debuginfo/metadata.rs
Line 924 in 237bf32