From 7a111dd234645b0a4aee56ec485940836f5379b9 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Wed, 21 Jun 2023 15:29:27 -0700 Subject: [PATCH] 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. --- tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs | 3 ++- tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs index 159f26842704..36708f9a5eca 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/add_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs index ec5e2bd94279..973563bacce4 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/div_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs index aac284a08e26..d1915505ed57 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/div_zero_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs index 3e703724fd67..7f6c60646510 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/mul_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs index b2887a591174..5bed5ed6d346 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs index eec7db57e123..0fbcb84865ae 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/rem_zero_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs index adc5e0a5dff4..a1f5b8dfaa56 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/shl_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs index 77d1b44f91df..6bb68ff1f526 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/shr_fail.rs @@ -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) }); } diff --git a/tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs b/tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs index 695ae81f01e3..de5839b83ccf 100644 --- a/tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs +++ b/tests/kani/Intrinsics/Math/Arith/Unchecked/sub_fail.rs @@ -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) }); }