-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly detect signed/unsigned integer overflows/underflows (#…
…5375) # Description ## Problem Resolves #5372 ## Summary Correctly detects overflows/underflows for basic integer types. The sign of a field element value is now also propagated to the ssa phase. But previously, the field value was applied some casting before reaching the ssa phase so checking that value like that was a bit strange. In this PR that conversion is delayed until the ssa phase, and the value can be checked prior to that conversion. ## Additional Context None. ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
14 changed files
with
105 additions
and
31 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
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
2 changes: 1 addition & 1 deletion
2
...ilure/integer_literal_overflow/Nargo.toml → ...igned_integer_literal_overflow/Nargo.toml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "integer_literal_overflow" | ||
name = "signed_integer_literal_overflow" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/signed_integer_literal_overflow/src/main.nr
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,5 @@ | ||
fn main() { | ||
foo(128) | ||
} | ||
|
||
fn foo(_x: i8) {} |
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/signed_integer_literal_underflow/Nargo.toml
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,5 @@ | ||
[package] | ||
name = "signed_integer_literal_underflow" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/signed_integer_literal_underflow/src/main.nr
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,5 @@ | ||
fn main() { | ||
foo(-129) | ||
} | ||
|
||
fn foo(_x: i8) {} |
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/unsigned_integer_literal_overflow/Nargo.toml
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,5 @@ | ||
[package] | ||
name = "unsigned_integer_literal_overflow" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/unsigned_integer_literal_underflow/Nargo.toml
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,5 @@ | ||
[package] | ||
name = "unsigned_integer_literal_underflow" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
5 changes: 5 additions & 0 deletions
5
test_programs/compile_failure/unsigned_integer_literal_underflow/src/main.nr
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,5 @@ | ||
fn main() { | ||
foo(-1) | ||
} | ||
|
||
fn foo(_x: u8) {} |