Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debuginfo does not describe enums with uninhabited variants correctly #109401

Open
wesleywiser opened this issue Mar 20, 2023 · 1 comment
Open
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wesleywiser
Copy link
Member

I tried this code:

enum Uninhabited { }

fn main() {
    let x = Option::<Uninhabited>::None;

    foo(x);
}

#[inline(never)]
fn foo<T>(_: T) { }

I expected to see this happen: gdb reports that x is None.

Instead, this happened: gdb reports that x is Some:

$ gdb ./uninhabited_enum_test
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
...
(gdb) break uninhabited_enum_test.rs:4
Breakpoint 1 at 0x8491: file uninhabited_enum_test.rs, line 6.
(gdb) r
Starting program: /tmp/uninhabited_enum_test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, uninhabited_enum_test::main () at uninhabited_enum_test.rs:6
6           foo(x);
(gdb) info locals
x = core::option::Option<uninhabited_enum_test::Uninhabited>::Some(uninhabited_enum_test::Uninhabited)

Meta

rustc --version --verbose:

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Also affects beta and nightly.

@wesleywiser wesleywiser added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. labels Mar 20, 2023
@wesleywiser wesleywiser self-assigned this Mar 20, 2023
@wesleywiser
Copy link
Member Author

DWARF is this which looks wrong as there is no way for a debugger to determine which variant is active:

< 3><0x000000a6>        DW_TAG_structure_type
                          DW_AT_name                  Option<uninhabited_enum_test::Uninhabited>
                          DW_AT_byte_size             0x00000000
                          DW_AT_alignment             0x00000001
< 4><0x000000ad>          DW_TAG_variant_part
< 5><0x000000ae>            DW_TAG_variant
< 6><0x000000af>              DW_TAG_member
                                DW_AT_name                  None
                                DW_AT_type                  <0x000000c9>
                                DW_AT_alignment             0x00000001
                                DW_AT_data_member_location  0
< 5><0x000000bb>            DW_TAG_variant
< 6><0x000000bc>              DW_TAG_member
                                DW_AT_name                  Some
                                DW_AT_type                  <0x000000da>
                                DW_AT_alignment             0x00000001
                                DW_AT_data_member_location  0
< 4><0x000000c9>          DW_TAG_structure_type
                            DW_AT_name                  None
                            DW_AT_byte_size             0x00000000
                            DW_AT_alignment             0x00000001
< 5><0x000000d0>            DW_TAG_template_type_parameter
                              DW_AT_type                  <0x00000092>
                              DW_AT_name                  T
< 4><0x000000da>          DW_TAG_structure_type
                            DW_AT_name                  Some
                            DW_AT_byte_size             0x00000000
                            DW_AT_alignment             0x00000001
< 5><0x000000e1>            DW_TAG_template_type_parameter
                              DW_AT_type                  <0x00000092>
                              DW_AT_name                  T
< 5><0x000000ea>            DW_TAG_member
                              DW_AT_name                  __0
                              DW_AT_type                  <0x00000092>
                              DW_AT_alignment             0x00000001
                              DW_AT_data_member_location  0

@Nilstrieb Nilstrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants