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.
Allow more than 12b (up to 18b now) stack offsets for local initializ…
…ation (FuelLabs#4515) ## Description When addressing locals (on the stack) for initialization, the address would be computed as `ADDi stack_base imm`, where `imm` is a 12 bit integer. That limits our stack size to 4096. This patch changes the codegen, in the case of a bigger stack offset, to use `MOVi reg imm` to load a 18b imm into a register, and then `ADD stack_base reg` to compute the address. Fixes FuelLabs#4450 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
1 parent
78dd331
commit b3cfea4
Showing
5 changed files
with
106 additions
and
15 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
test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/stack_indexing_overflow/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-6BF9CEE717879469' | ||
|
||
[[package]] | ||
name = 'script_multi_test' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-6BF9CEE717879469' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/stack_indexing_overflow/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 = "script_multi_test" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
45 changes: 45 additions & 0 deletions
45
...src/e2e_vm_tests/test_programs/should_pass/unit_tests/stack_indexing_overflow/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,45 @@ | ||
script; | ||
|
||
use std::u256::U256; | ||
|
||
struct M1 { | ||
a: U256, | ||
b: U256, | ||
c: U256, | ||
d: U256, | ||
} | ||
|
||
struct M2 { | ||
a: M1, | ||
b: M1, | ||
c: M1, | ||
d: M1, | ||
} | ||
|
||
const m1: M1 = M1 { a: U256::new(), b: U256::new(), c: U256::new(), d: U256::new() }; | ||
const m2: M2 = M2 { a: m1, b: m1, c: m1, d: m1 }; | ||
|
||
const MARR : [M2; 6] = | ||
[ | ||
m2, m2, m2, m2, m2, m2 | ||
]; | ||
|
||
fn bar() -> ([M2; 6], [M2; 6]) { | ||
let mut a = MARR; | ||
let mut b = MARR; | ||
a[0].a.b = U256::max(); | ||
(a, b) | ||
} | ||
|
||
fn main() -> [M2; 6] { | ||
let mut b = bar(); | ||
b.0 | ||
} | ||
|
||
#[test] | ||
fn test() -> [M2; 6] { | ||
let mut b = bar(); | ||
assert(b.0[0].a.a == U256::new()); | ||
assert(b.0[0].a.b == U256::max()); | ||
b.0 | ||
} |
1 change: 1 addition & 0 deletions
1
test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/stack_indexing_overflow/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 @@ | ||
category = "unit_tests_pass" |