Add codegen tests
This commit is contained in:
parent
c88b167f15
commit
1d157ce797
25
src/test/codegen/enum-bounds-check-derived-idx.rs
Normal file
25
src/test/codegen/enum-bounds-check-derived-idx.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// This test checks an optimization that is not guaranteed to work. This test case should not block
|
||||
// a future LLVM update.
|
||||
// compile-flags: -O
|
||||
// min-llvm-version: 11.0
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub enum Bar {
|
||||
A = 1,
|
||||
B = 3,
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @lookup_inc
|
||||
#[no_mangle]
|
||||
pub fn lookup_inc(buf: &[u8; 5], f: Bar) -> u8 {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
buf[f as usize + 1]
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @lookup_dec
|
||||
#[no_mangle]
|
||||
pub fn lookup_dec(buf: &[u8; 5], f: Bar) -> u8 {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
buf[f as usize - 1]
|
||||
}
|
19
src/test/codegen/enum-bounds-check-issue-13926.rs
Normal file
19
src/test/codegen/enum-bounds-check-issue-13926.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// This test checks an optimization that is not guaranteed to work. This test case should not block
|
||||
// a future LLVM update.
|
||||
// compile-flags: -O
|
||||
// min-llvm-version: 11.0
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum Exception {
|
||||
Low = 5,
|
||||
High = 10,
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @access
|
||||
#[no_mangle]
|
||||
pub fn access(array: &[usize; 12], exc: Exception) -> usize {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
array[(exc as u8 - 4) as usize]
|
||||
}
|
@ -12,3 +12,15 @@ pub fn lookup(buf: &[u8; 2], f: Foo) -> u8 {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
buf[f as usize]
|
||||
}
|
||||
|
||||
pub enum Bar {
|
||||
A = 2,
|
||||
B = 3
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @lookup_unmodified
|
||||
#[no_mangle]
|
||||
pub fn lookup_unmodified(buf: &[u8; 5], f: Bar) -> u8 {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
buf[f as usize]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user