-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reachability checks for some auto-generated asserts (#838)
- Loading branch information
1 parent
e741b2c
commit e4aa490
Showing
34 changed files
with
337 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE | ||
Failed Checks: index out of bounds: the length is less than or equal to the given index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// index-out-of-bounds checks and that it reports ones that are unreachable. | ||
// The check in this test is reachable and doesn't hold, so should be reported | ||
// as FAILURE | ||
|
||
fn get(s: &[i16], index: usize) -> i16 { | ||
s[index] | ||
} | ||
|
||
fn main() { | ||
get(&[7, -83, 19], 15); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// index-out-of-bounds checks and that it reports ones that are unreachable. | ||
// The check in this test is reachable, so should be reported as SUCCESS | ||
|
||
fn get(s: &[i16], index: usize) -> i16 { | ||
if index < s.len() { s[index] } else { -1 } | ||
} | ||
|
||
fn main() { | ||
get(&[7, -83, 19], 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNREACHABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// index-out-of-bounds checks and that it reports ones that are unreachable. | ||
// The check in this test is unreachable, so should be reported as UNREACHABLE | ||
|
||
fn get(s: &[i16], index: usize) -> i16 { | ||
if index < s.len() { s[index] } else { -1 } | ||
} | ||
|
||
fn main() { | ||
//get(&[7, -83, 19], 2); | ||
get(&[5, 206, -46, 321, 8], 8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE | ||
Failed Checks: attempt to divide by zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// divide-by-zero checks and that it reports ones that are unreachable. | ||
// The check in this test is reachable and doesn't hold, so should be reported | ||
// as FAILURE | ||
|
||
fn div(x: u16, y: u16) -> u16 { | ||
x / y | ||
} | ||
|
||
fn main() { | ||
div(678, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// divide-by-zero checks and that it reports ones that are unreachable. | ||
// The check in this test is reachable, so should be reported as SUCCESS | ||
|
||
fn div(x: u16, y: u16) -> u16 { | ||
if y != 0 { x / y } else { 0 } | ||
} | ||
|
||
fn main() { | ||
div(11, 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNREACHABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular --no-default-checks | ||
|
||
// This test checks that kani injects a reachability check for | ||
// divide-by-zero checks and that it reports ones that are unreachable. | ||
// The check in this test is unreachable, so should be reported as UNREACHABLE | ||
|
||
fn div(x: u16, y: u16) -> u16 { | ||
if y != 0 { x / y } else { 0 } | ||
} | ||
|
||
fn main() { | ||
div(5, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE | ||
Failed Checks: attempt to negate with overflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for negation | ||
// overflow checks and that it reports ones that are unreachable | ||
// The negation overflow check in this test is reachable and doesn't hold, so | ||
// should be reported as FAILURE | ||
|
||
fn negate(x: i32) -> i32 { | ||
-x | ||
} | ||
|
||
fn main() { | ||
negate(std::i32::MIN); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for negation | ||
// overflow checks and that it reports ones that are unreachable | ||
// The negation overflow check in this test is reachable, so should be | ||
// reported as SUCCESS | ||
|
||
fn negate(x: i32) -> i32 { | ||
if x != std::i32::MIN { -x } else { std::i32::MAX } | ||
} | ||
|
||
fn main() { | ||
negate(7532); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNREACHABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for negation | ||
// overflow checks and that it reports ones that are unreachable | ||
// The negation overflow check in this test is unreachable, so should be | ||
// reported as UNREACHABLE | ||
|
||
fn negate(x: i32) -> i32 { | ||
if x != std::i32::MIN { -x } else { std::i32::MAX } | ||
} | ||
|
||
fn main() { | ||
negate(std::i32::MIN); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE | ||
Failed Checks: attempt to subtract with overflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for arithmetic | ||
// overflow checks and that it reports ones that are unreachable. | ||
// The arithmetic overflow check in this test is reachable but does not hold, so | ||
// should be reported as FAILURE | ||
|
||
fn cond_reduce(thresh: u32, x: u32) -> u32 { | ||
if x > thresh { x - 50 } else { x } | ||
} | ||
|
||
fn main() { | ||
cond_reduce(60, 70); | ||
cond_reduce(40, 42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for arithmetic | ||
// overflow checks and that it reports ones that are unreachable. | ||
// The arithmetic overflow check in this test is reachable, so should be | ||
// reported as SUCCESS | ||
|
||
fn reduce(x: u32) -> u32 { | ||
if x > 1000 { x - 1000 } else { x } | ||
} | ||
|
||
fn main() { | ||
reduce(7); | ||
reduce(33); | ||
reduce(728); | ||
reduce(1079); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNREACHABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: --assertion-reach-checks --output-format regular | ||
|
||
// This test checks that kani injects a reachability check for arithmetic | ||
// overflow checks and that it reports ones that are unreachable | ||
// The arithmetic overflow check in this test is unreachable, so should be | ||
// reported as UNREACHABLE | ||
|
||
fn reduce(x: u32) -> u32 { | ||
if x > 1000 { x - 1000 } else { x } | ||
} | ||
|
||
fn main() { | ||
reduce(7); | ||
reduce(33); | ||
reduce(728); | ||
} |
Oops, something went wrong.