mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Rollup merge of #83020 - hi-rustin:rustin-patch-enum, r=lcnr
Emit the enum range assumption if the range only contains one element close https://github.com/rust-lang/rust/issues/82871
This commit is contained in:
commit
04e24ae67e
@ -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
|
||||
|
16
src/test/codegen/enum-bounds-check-issue-82871.rs
Normal file
16
src/test/codegen/enum-bounds-check-issue-82871.rs
Normal 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]
|
||||
}
|
Loading…
Reference in New Issue
Block a user