Skip to content

Commit c0033e5

Browse files
authored
Rollup merge of rust-lang#83020 - hi-rustin:rustin-patch-enum, r=lcnr
Emit the enum range assumption if the range only contains one element close rust-lang#82871
2 parents f55a5a3 + d180f91 commit c0033e5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
325325

326326
let er = scalar.valid_range_exclusive(bx.cx());
327327
if er.end != er.start
328-
&& scalar.valid_range.end() > scalar.valid_range.start()
328+
&& scalar.valid_range.end() >= scalar.valid_range.start()
329329
{
330330
// We want `table[e as usize ± k]` to not
331331
// have bound checks, and this is the most

Diff for: src/test/codegen/enum-bounds-check-issue-82871.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -O
2+
// min-llvm-version: 11.0
3+
4+
#![crate_type = "lib"]
5+
6+
#[repr(C)]
7+
pub enum E {
8+
A,
9+
}
10+
11+
// CHECK-LABEL: @index
12+
#[no_mangle]
13+
pub fn index(x: &[u32; 3], ind: E) -> u32{
14+
// CHECK-NOT: panic_bounds_check
15+
x[ind as usize]
16+
}

0 commit comments

Comments
 (0)