Skip to content

Re-introduce load-bearing assert, or fix niche debuginfo generation properly. #59509

Closed

Description

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>,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions