1
Fork 0

Emit the enum range assumption if the range only contains one element

test: add test case

make tidy happy
This commit is contained in:
hi-rustin 2021-03-11 23:30:39 +08:00
parent 5c6d3bf389
commit d180f91824
2 changed files with 17 additions and 1 deletions

View file

@ -325,7 +325,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
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

View file

@ -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]
}