-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[asmgen] pushing / popping registers for call should handle all def'd…
- Loading branch information
1 parent
9cd1b39
commit a67e9a9
Showing
5 changed files
with
86 additions
and
6 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
13 changes: 13 additions & 0 deletions
13
.../src/e2e_vm_tests/test_programs/should_pass/language/pusha_popa_multiple_defreg/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,13 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-B299C98691745B40" | ||
|
||
[[package]] | ||
name = "pusha_popa_multiple_defreg" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-B299C98691745B40" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
.../src/e2e_vm_tests/test_programs/should_pass/language/pusha_popa_multiple_defreg/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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "pusha_popa_multiple_defreg" | ||
|
||
[dependencies] | ||
std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } |
56 changes: 56 additions & 0 deletions
56
...rc/e2e_vm_tests/test_programs/should_pass/language/pusha_popa_multiple_defreg/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,56 @@ | ||
contract; | ||
|
||
abi IncorrectPushaPopa { | ||
#[storage(read)] | ||
fn incorrect_pusha_popa() -> (); | ||
} | ||
|
||
impl IncorrectPushaPopa for Contract { | ||
#[storage(read)] | ||
fn incorrect_pusha_popa() -> () { | ||
setup(); | ||
() | ||
} | ||
} | ||
|
||
#[storage(read)] | ||
fn setup() -> () { | ||
let a: u64 = 1; | ||
let b: u64 = 1; | ||
let c: u64 = 1; | ||
//call a few times to avoid inline | ||
store_read(); | ||
let r = asm(r, a: a, b: b, c: c, d: store_read()) { | ||
movi r i0; | ||
add r a b; // r = a + b = 2 | ||
add r r c; // r = a + b + c = 3 c value is overwritten by store_read, so we get 2 instead | ||
add r r d; // r = a + b + c + d = 3 d returns 0 | ||
r | ||
}; | ||
assert(r == 3); | ||
() | ||
} | ||
|
||
#[storage(read)] | ||
fn store_read() -> u64 { | ||
let a = asm(slot, a, b, c) { | ||
movi c i32; | ||
aloc c; | ||
move slot hp; | ||
srw a b slot; // somehow make b allocate to $r3 | ||
movi c i0; | ||
add a a slot; | ||
sub a a slot; | ||
add a a b; | ||
add a a c; | ||
a | ||
}; | ||
a - a // return 0 and make sure a is not dced | ||
} | ||
|
||
#[test] | ||
fn incorrect_pusha_popa() -> () { | ||
let c = abi(IncorrectPushaPopa, CONTRACT_ID); | ||
c.incorrect_pusha_popa(); | ||
() | ||
} |
3 changes: 3 additions & 0 deletions
3
.../src/e2e_vm_tests/test_programs/should_pass/language/pusha_popa_multiple_defreg/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,3 @@ | ||
category = "unit_tests_pass" | ||
validate_abi = false | ||
expected_warnings = 0 |