Skip to content

ICE when casting float to integer (out-of-bounds) #45134

Closed
@samnardoni

Description

@samnardoni

The following program (with perhaps undefined behaviour) causes an ICE:

fn ice() {
    println!("{:?}", Some(257.0f32 as u8));
}

Interestingly, if not wrapping the result in a Some, then there's no ICE.

fn no_ice() {
    println!("{:?}", 257.0f32 as u8);
}

Here's the result from running it on the playground:

   Compiling playground v0.0.1 (file:///playground)
error: internal compiler error: unexpected panic

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.20.0 (f3d6973f4 2017-08-27) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'assertion failed: !is_undef(val)', /checkout/src/librustc_trans/mir/constant.rs:1083:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions