Skip to content

Commit 7a111dd

Browse files
authored
Change intrinsics tests to ensure the call is not removed by the compiler (#2552)
The tests below started failing as part of the latest toolchain update because the value produced by intrinsics is not used, and the compiler just removes them. To avoid that to happen, we now wrap those calls with the black_box std function to avoid compiler optimizations.
1 parent 49405b2 commit 7a111dd

File tree

9 files changed

+18
-9
lines changed

9 files changed

+18
-9
lines changed

tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
fn main() {
1010
let a: i32 = kani::any();
1111
let b: i32 = kani::any();
12-
unsafe { std::intrinsics::unchecked_add(a, b) };
12+
// Black box this so it doesn't get pruned by the compiler.
13+
std::hint::black_box(unsafe { std::intrinsics::unchecked_add(a, b) });
1314
}

tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
fn main() {
1111
let a: i32 = i32::MIN;
1212
let b: i32 = -1;
13-
unsafe { std::intrinsics::unchecked_div(a, b) };
13+
// Black box this so it doesn't get pruned by the compiler.
14+
std::hint::black_box(unsafe { std::intrinsics::unchecked_div(a, b) });
1415
}

tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
fn main() {
1111
let a: i32 = kani::any();
1212
let b: i32 = 0;
13-
unsafe { std::intrinsics::unchecked_div(a, b) };
13+
// Black box this so it doesn't get pruned by the compiler.
14+
std::hint::black_box(unsafe { std::intrinsics::unchecked_div(a, b) });
1415
}

tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
fn main() {
1010
let a: i32 = kani::any();
1111
let b: i32 = kani::any();
12-
unsafe { std::intrinsics::unchecked_mul(a, b) };
12+
// Black box this so it doesn't get pruned by the compiler.
13+
std::hint::black_box(unsafe { std::intrinsics::unchecked_mul(a, b) });
1314
}

tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
fn main() {
1111
let a: i32 = i32::MIN;
1212
let b: i32 = -1;
13-
unsafe { std::intrinsics::unchecked_rem(a, b) };
13+
// Black box this so it doesn't get pruned by the compiler.
14+
std::hint::black_box(unsafe { std::intrinsics::unchecked_rem(a, b) });
1415
}

tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
fn main() {
1111
let a: i32 = kani::any();
1212
let b: i32 = 0;
13-
unsafe { std::intrinsics::unchecked_rem(a, b) };
13+
// Black box this so it doesn't get pruned by the compiler.
14+
std::hint::black_box(unsafe { std::intrinsics::unchecked_rem(a, b) });
1415
}

tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
fn main() {
1010
let a: u32 = kani::any();
1111
let b: u32 = kani::any();
12-
unsafe { std::intrinsics::unchecked_shl(a, b) };
12+
// Black box this so it doesn't get pruned by the compiler.
13+
std::hint::black_box(unsafe { std::intrinsics::unchecked_shl(a, b) });
1314
}

tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
fn main() {
1010
let a: u32 = kani::any();
1111
let b: u32 = kani::any();
12-
unsafe { std::intrinsics::unchecked_shr(a, b) };
12+
// Black box this so it doesn't get pruned by the compiler.
13+
std::hint::black_box(unsafe { std::intrinsics::unchecked_shr(a, b) });
1314
}

tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
fn main() {
1010
let a: i32 = kani::any();
1111
let b: i32 = kani::any();
12-
unsafe { std::intrinsics::unchecked_sub(a, b) };
12+
// Black box this so it doesn't get pruned by the compiler.
13+
std::hint::black_box(unsafe { std::intrinsics::unchecked_sub(a, b) });
1314
}

0 commit comments

Comments
 (0)