Skip to content

heisenbug: debug builds Integer::repr_discr has transient ICE on compile-fail/enum-discrim-too-small2.rs #47381

Closed
@pnkfelix

Description

@pnkfelix

My config.toml:

[rust]
codegen-units = 8
debug = true
optimize = true
debug-assertions = true
debuginfo = true
debuginfo-lines = true

And my (odd?) build invocation:

% time python /Users/fklock/Dev/Mozilla/rust-mirborrowck/.git/../x.py test src/tools/tidy && \
  time python /Users/fklock/Dev/Mozilla/rust-mirborrowck/.git/../x.py build --stage 1 --incremental --keep-stage 0 src/libstd && \
  time python /Users/fklock/Dev/Mozilla/rust-mirborrowck/.git/../x.py test --stage 1 src/test/{mir-opt,compile-fail,run-pass}

Results in stage 1 binary where we get weirdness on this compile-fail test:

% ./objdir-dbgopt/build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/compile-fail/enum-discrim-too-small2.rs
error: literal out of range for i8
  --> src/test/compile-fail/enum-discrim-too-small2.rs:18:11
   |
18 |     Ci8 = 223, //~ ERROR literal out of range for i8
   |           ^^^
   |
note: lint level defined here
  --> src/test/compile-fail/enum-discrim-too-small2.rs:11:9
   |
11 | #![deny(overflowing_literals)]
   |         ^^^^^^^^^^^^^^^^^^^^

error: literal out of range for i16
  --> src/test/compile-fail/enum-discrim-too-small2.rs:25:12
   |
25 |     Ci16 = 55555, //~ ERROR literal out of range for i16
   |            ^^^^^

error: literal out of range for i32
  --> src/test/compile-fail/enum-discrim-too-small2.rs:32:12
   |
32 |     Ci32 = 3_000_000_000, //~ ERROR literal out of range for i32
   |            ^^^^^^^^^^^^^

error: internal compiler error: librustc/ty/layout.rs:553: Integer::repr_discr: `#[repr]` hint too small for discriminant range of enum `Ei64

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.25.0-dev running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:508:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I am pretty sure this is specific to debug builds. At least, that's my current best guess as to why this hasn't been caught by bors.

The code layout.rs looks like this:

       if let Some(ity) = repr.int {
            let discr = Integer::from_attr(tcx, ity);
            let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
            if discr < fit {
                bug!("Integer::repr_discr: `#[repr]` hint too small for \
                  discriminant range of enum `{}", ty)
            }
            return (discr, ity.is_signed());
        }

it should probably be signalling a proper error, or trusting that the lint will eventually fire and catch this, rather than just triggering a call to bug! (since this does not represent a bug in the compiler itself, right?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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