Skip to content

rustc fails to detect duplicate switch cases due to integer overflow #13727

Closed
@farcaller

Description

@farcaller

A small app to demonstrate the problem:

fn test(val: u8) {
  match val {
    256 => print!("0b1110\n"),
    512 => print!("0b1111\n"),
    _   => print!("fail\n"),
  }
}

fn main() {
  test(1);
}

Compilation fails in llvm:

% rustc test.rs
test.rs:3:5: 3:11 warning: literal out of range for its type, #[warn(type_overflow)] on by default
test.rs:3     256 => print!("0b1110\n"),
              ^~~~~~
test.rs:4:5: 4:11 warning: literal out of range for its type, #[warn(type_overflow)] on by default
test.rs:4     512 => print!("0b1111\n"),
              ^~~~~~
Duplicate integer as switch case
  switch i8 %1, label %match_else [
    i8 0, label %match_case
    i8 0, label %match_case3
  ]
i8 0
LLVM ERROR: Broken function found, compilation aborted!

Rustc should detect the double label due to overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-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