diff options
| author | hi-rustin <rustin.liu@gmail.com> | 2021-03-11 23:30:39 +0800 |
|---|---|---|
| committer | hi-rustin <rustin.liu@gmail.com> | 2021-03-12 12:06:10 +0800 |
| commit | d180f918240d2f8bd3d6f7292b63194f45901759 (patch) | |
| tree | 036c6a6ed4ae43467af16a28e621e3f752475cf6 | |
| parent | 5c6d3bf3896b465e15550f49c2861e3d18102270 (diff) | |
| download | rust-d180f918240d2f8bd3d6f7292b63194f45901759.tar.gz rust-d180f918240d2f8bd3d6f7292b63194f45901759.zip | |
Emit the enum range assumption if the range only contains one element
test: add test case make tidy happy
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 | ||||
| -rw-r--r-- | src/test/codegen/enum-bounds-check-issue-82871.rs | 16 |
2 files changed, 17 insertions, 1 deletions
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 @@ 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 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] +} |
