diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 1795710ff53..629cb64d43e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -325,7 +325,7 @@ pub fn codegen_rvalue_operand( let er = scalar.valid_range_exclusive(bx.cx()); if er.end != er.start - && scalar.valid_range.end() > scalar.valid_range.start() + && scalar.valid_range.end() >= scalar.valid_range.start() { // We want `table[e as usize ± k]` to not // have bound checks, and this is the most diff --git a/src/test/codegen/enum-bounds-check-issue-82871.rs b/src/test/codegen/enum-bounds-check-issue-82871.rs new file mode 100644 index 00000000000..e779e2ef274 --- /dev/null +++ b/src/test/codegen/enum-bounds-check-issue-82871.rs @@ -0,0 +1,16 @@ +// compile-flags: -O +// min-llvm-version: 11.0 + +#![crate_type = "lib"] + +#[repr(C)] +pub enum E { + A, +} + +// CHECK-LABEL: @index +#[no_mangle] +pub fn index(x: &[u32; 3], ind: E) -> u32{ + // CHECK-NOT: panic_bounds_check + x[ind as usize] +}