forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow assigning to initialized registers in
asm
blocks (FuelLabs…
…#3239) Closes FuelLabs#3155 This is needed due to `mem2reg` and some unclear semantics around initialized registers being passed as ref/mut ref. Besides, it's a good idea to restrict `asm` blocks as much as possible to avoid weird unwanted behavior. <img width="883" alt="image" src="https://user-images.githubusercontent.com/59666792/199332120-974d1821-680e-43a1-922d-1a32d491b3cd.png"> * I also removed the `disallow_opcodes` check because the parser takes care of that now. The parser only allows legal opcodes in `asm` blocks. * Finally, I update the parser to accept the correct storage opcodes with `fuel-core 0.13` and updates all the tests. Co-authored-by: Vaivaswatha N <[email protected]>
- Loading branch information
1 parent
cfecaf4
commit b83ad9b
Showing
16 changed files
with
163 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_fail/asm_assign_to_initialized_reg/Forc.lock
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,3 @@ | ||
[[package]] | ||
name = 'asm_assign_to_initialized_reg' | ||
source = 'root' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_fail/asm_assign_to_initialized_reg/Forc.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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
implicit-std = false | ||
license = "Apache-2.0" | ||
name = "asm_assign_to_initialized_reg" |
11 changes: 11 additions & 0 deletions
11
test/src/e2e_vm_tests/test_programs/should_fail/asm_assign_to_initialized_reg/src/main.sw
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,11 @@ | ||
script; | ||
|
||
fn main() -> u64 { | ||
asm(r1: 0, r2: 0, r3, r4) { | ||
move r1 r2; | ||
move r2 r1; | ||
move r3 r1; | ||
move r4 r2; | ||
}; | ||
0 | ||
} |
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_fail/asm_assign_to_initialized_reg/test.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,7 @@ | ||
category = "fail" | ||
|
||
# check: $()asm(r1: 0, r2: 0, r3, r4) { | ||
# nextln: $()Register "r1" is initialized and later reassigned which is not allowed. Consider assigning to a different register inside the ASM block. | ||
|
||
# check: $()asm(r1: 0, r2: 0, r3, r4) { | ||
# nextln: $()Register "r2" is initialized and later reassigned which is not allowed. Consider assigning to a different register inside the ASM block. |
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
test/src/e2e_vm_tests/test_programs/should_pass/language/asm_without_return/Forc.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,8 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "asm_without_return" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } |
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