Skip to content

Commit c1260ef

Browse files
sayantnfolkertdev
andcommitted
Add tests
Co-Authored-By: folkertdev <[email protected]>
1 parent 1790258 commit c1260ef

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#![feature(fmt_internals)]
5151
#![feature(formatting_options)]
5252
#![feature(freeze)]
53+
#![feature(funnel_shifts)]
5354
#![feature(future_join)]
5455
#![feature(generic_assert_internals)]
5556
#![feature(hasher_prefixfree_extras)]

library/coretests/tests/num/uint_macros.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ macro_rules! uint_module {
104104
assert_eq_const_safe!($T: C.rotate_left(128), C);
105105
}
106106

107+
fn test_funnel_shift() {
108+
// Shifting by 0 should have no effect
109+
assert_eq_const_safe!($T: <$T>::funnel_shl(A, B, 0), A);
110+
assert_eq_const_safe!($T: <$T>::funnel_shr(A, B, 0), B);
111+
112+
assert_eq_const_safe!($T: <$T>::funnel_shl(_0, _1, 4), 0b1111);
113+
assert_eq_const_safe!($T: <$T>::funnel_shr(_0, _1, 4), _1 >> 4);
114+
assert_eq_const_safe!($T: <$T>::funnel_shl(_1, _0, 4), _1 << 4);
115+
116+
assert_eq_const_safe!($T: <$T>::funnel_shl(_1, _1, 4), <$T>::rotate_left(_1, 4));
117+
assert_eq_const_safe!($T: <$T>::funnel_shr(_1, _1, 4), <$T>::rotate_right(_1, 4));
118+
}
119+
107120
fn test_swap_bytes() {
108121
assert_eq_const_safe!($T: A.swap_bytes().swap_bytes(), A);
109122
assert_eq_const_safe!($T: B.swap_bytes().swap_bytes(), B);
@@ -150,6 +163,12 @@ macro_rules! uint_module {
150163
}
151164
}
152165

166+
#[test]
167+
#[should_panic = "attempt to funnel shift left with overflow"]
168+
fn test_funnel_shift_overflow() {
169+
let _ = <$T>::funnel_shl(A, B, 150);
170+
}
171+
153172
#[test]
154173
fn test_isolate_highest_one() {
155174
const BITS: $T = <$T>::MAX;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32); //~ ERROR: Undefined Behavior
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shl.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shl.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32); //~ ERROR: Undefined Behavior
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shr.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shr.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

src/tools/miri/tests/pass/intrinsics/integer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
33

4-
#![feature(core_intrinsics)]
4+
#![feature(core_intrinsics, funnel_shifts)]
55
use std::intrinsics::*;
66

77
pub fn main() {
@@ -143,5 +143,11 @@ pub fn main() {
143143

144144
assert_eq!(unchecked_mul(6u8, 7), 42);
145145
assert_eq!(unchecked_mul(13, -5), -65);
146+
147+
assert_eq!(unchecked_funnel_shl(1_u32, 2, 5), 32);
148+
assert_eq!(unchecked_funnel_shl(1_u32, 2, 31), 0x80000001);
149+
150+
assert_eq!(unchecked_funnel_shr(1_u32, 2, 5), 0x08000000);
151+
assert_eq!(unchecked_funnel_shr(1_u32, 2, 31), 2);
146152
}
147153
}

0 commit comments

Comments
 (0)