generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 27
Add division-by-zero verification for Laurel via Core safe operators #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
37ce14b
Add Laurel-to-Laurel division-by-zero check transformation
tautschnig 4790f26
Remove unused helpers and fix IfThenElse/While branch check hoisting
tautschnig 1473189
Rewrite quantifier bodies to guard divisions in-scope
tautschnig e87560c
Add preconditions for functional procedures instead of assertions
tautschnig 0dd6024
Replace Laurel division-by-zero instrumentation with Core safe operators
tautschnig 7cdbbd5
Add dedicated CST nodes for truncating division/modulo operators
tautschnig 03c82e3
Merge remote-tracking branch 'origin/main' into tautschnig/division-b…
tautschnig 4692c96
Update pyAnalyzeLaurel expected output for safe division operator
tautschnig f37c246
Propagate source location to LocalVariable in Python-to-Laurel transl…
tautschnig 3942b50
Propagate source location to all statement types in Python-to-Laurel …
tautschnig 256952b
Add distinct CST nodes for unchecked truncating division/modulo
tautschnig cf22418
Use function-call syntax for unchecked truncating div/mod CST nodes
tautschnig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import StrataTest.Util.TestDiagnostics | ||
| import StrataTest.Languages.Laurel.TestExamples | ||
|
|
||
| open StrataTest.Util | ||
|
|
||
| namespace Strata.Laurel | ||
|
|
||
| /-! ## End-to-end test: safe division (no errors) and unsafe division (error) | ||
|
|
||
| Division and modulo in Laurel translate to Core's safe operators, which have | ||
| built-in preconditions (divisor ≠ 0). The PrecondElim transform automatically | ||
| generates verification conditions for these preconditions. | ||
| -/ | ||
|
|
||
| def e2eProgram := r" | ||
| procedure safeDivision() { | ||
| var x: int := 10; | ||
| var y: int := 2; | ||
| var z: int := x / y; | ||
| assert z == 5; | ||
| } | ||
|
|
||
| procedure unsafeDivision(x: int) { | ||
| var z: int := 10 / x; | ||
| // ^^^^^^ error: assertion does not hold | ||
| } | ||
|
|
||
| function pureDiv(x: int, y: int): int | ||
| requires y != 0 | ||
| { | ||
| x / y | ||
| } | ||
|
|
||
| procedure callPureDivSafe() { | ||
| var z: int := pureDiv(10, 2); | ||
| assert z == 5; | ||
| } | ||
|
|
||
| procedure callPureDivUnsafe(x: int) { | ||
| var z: int := pureDiv(10, x); | ||
| // ^^^^^^^^^^^^^^ error: assertion does not hold | ||
| } | ||
| " | ||
|
|
||
| #guard_msgs(drop info, error) in | ||
| #eval testInputWithOffset "DivByZeroE2E" e2eProgram 22 processLaurelFile | ||
tautschnig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| end Laurel | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.