Skip to content

Commit 1d157ce

Browse files
committed
Add codegen tests
1 parent c88b167 commit 1d157ce

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This test checks an optimization that is not guaranteed to work. This test case should not block
2+
// a future LLVM update.
3+
// compile-flags: -O
4+
// min-llvm-version: 11.0
5+
6+
#![crate_type = "lib"]
7+
8+
pub enum Bar {
9+
A = 1,
10+
B = 3,
11+
}
12+
13+
// CHECK-LABEL: @lookup_inc
14+
#[no_mangle]
15+
pub fn lookup_inc(buf: &[u8; 5], f: Bar) -> u8 {
16+
// CHECK-NOT: panic_bounds_check
17+
buf[f as usize + 1]
18+
}
19+
20+
// CHECK-LABEL: @lookup_dec
21+
#[no_mangle]
22+
pub fn lookup_dec(buf: &[u8; 5], f: Bar) -> u8 {
23+
// CHECK-NOT: panic_bounds_check
24+
buf[f as usize - 1]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test checks an optimization that is not guaranteed to work. This test case should not block
2+
// a future LLVM update.
3+
// compile-flags: -O
4+
// min-llvm-version: 11.0
5+
6+
#![crate_type = "lib"]
7+
8+
#[repr(u8)]
9+
pub enum Exception {
10+
Low = 5,
11+
High = 10,
12+
}
13+
14+
// CHECK-LABEL: @access
15+
#[no_mangle]
16+
pub fn access(array: &[usize; 12], exc: Exception) -> usize {
17+
// CHECK-NOT: panic_bounds_check
18+
array[(exc as u8 - 4) as usize]
19+
}

src/test/codegen/enum-bounds-check.rs

+12
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ pub fn lookup(buf: &[u8; 2], f: Foo) -> u8 {
1212
// CHECK-NOT: panic_bounds_check
1313
buf[f as usize]
1414
}
15+
16+
pub enum Bar {
17+
A = 2,
18+
B = 3
19+
}
20+
21+
// CHECK-LABEL: @lookup_unmodified
22+
#[no_mangle]
23+
pub fn lookup_unmodified(buf: &[u8; 5], f: Bar) -> u8 {
24+
// CHECK-NOT: panic_bounds_check
25+
buf[f as usize]
26+
}

0 commit comments

Comments
 (0)