Skip to content
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

fix: redundant memory store statements for static variables #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mohammad-shahabadi
Copy link

Bug description :
Declaring static variables in the main function would result in WASM memory access out of bounds error.
In sourceacademy playground it would show index out of bounds
Sample code to reproduce the issue :

int main() {
    static int g = 12;
}

Root cause :
Compiler consider local scope static variables as normal variables and write memory store statements for each static variable declaration and attempt to store the assigned values into bp + address of that static variable which would result in out of bounds error in specific cases.
For instance, the example mentioned would have this line of code in WAT code which should not have been included in the code :
(i32.store (i32.add (global.get $bp) (i32.const 0))
0 is the address of the defined static variable.

Solution :
Adding condition in local declaration processes to pass data segment variable declarations for adding memory statements.

Test cases:
I already ran all the written test cases and all of them were passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant