Skip to content

Commit

Permalink
Change intrinsics tests to ensure the call is not removed by the comp…
Browse files Browse the repository at this point in the history
…iler (#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.
  • Loading branch information
celinval committed Jun 21, 2023
1 parent 49405b2 commit 7a111dd
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
fn main() {
let a: i32 = kani::any();
let b: i32 = kani::any();
unsafe { std::intrinsics::unchecked_add(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_add(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
fn main() {
let a: i32 = i32::MIN;
let b: i32 = -1;
unsafe { std::intrinsics::unchecked_div(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_div(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
fn main() {
let a: i32 = kani::any();
let b: i32 = 0;
unsafe { std::intrinsics::unchecked_div(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_div(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
fn main() {
let a: i32 = kani::any();
let b: i32 = kani::any();
unsafe { std::intrinsics::unchecked_mul(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_mul(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
fn main() {
let a: i32 = i32::MIN;
let b: i32 = -1;
unsafe { std::intrinsics::unchecked_rem(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_rem(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
fn main() {
let a: i32 = kani::any();
let b: i32 = 0;
unsafe { std::intrinsics::unchecked_rem(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_rem(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
fn main() {
let a: u32 = kani::any();
let b: u32 = kani::any();
unsafe { std::intrinsics::unchecked_shl(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_shl(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
fn main() {
let a: u32 = kani::any();
let b: u32 = kani::any();
unsafe { std::intrinsics::unchecked_shr(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_shr(a, b) });
}
3 changes: 2 additions & 1 deletion tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
fn main() {
let a: i32 = kani::any();
let b: i32 = kani::any();
unsafe { std::intrinsics::unchecked_sub(a, b) };
// Black box this so it doesn't get pruned by the compiler.
std::hint::black_box(unsafe { std::intrinsics::unchecked_sub(a, b) });
}

0 comments on commit 7a111dd

Please sign in to comment.