-
-
Notifications
You must be signed in to change notification settings - Fork 670
Strange output of memset polyfill #1785
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
Comments
Interesting. Actually all this correct but redundant. Like first version is equivalent to: store<u8>(16, 255, 0);
store<u8>(18, 255, 0);
store<u8>(17, 255, 0);
store<u8>(18, 255, 0);
store<u8>(17, 255, 0);
store<u8>(16, 255, 0); second version equivalent to: store<u8>(0, 0, 0);
store<u8>(-2, 0, 3); // which the same as store<u8>(1, 0, 0) All this optimizations performs by binaryen. And it seems will be great have Dead Store Elimination (DSE) pass for Binaryen. |
The following snippet fails in Chrome, Firefox, and Safari with OOB memory access. export function bar(): void {
memory.grow(1);
store<u8>(-2, 0, 3);
} |
Binaryen perform this transform only when memoryBase >= 1024 as I remember. |
Btw So I don't recommend rewrite to first 4 bytes of linear memory in any language. It should be reserved for |
The WebAssembly execution spec defines the effective address as Btw, this fails as well: export function bar(): void {
memory.grow(1);
store<u8>(-1, 0, 9);
} |
I guess most engines use bound checking which leave constant offset (last argument) out of scope. Not sure is it problem of engines or spec |
Even if it's a bug with engines, It's probably safe to assume that it will remain as-is (because some platforms no longer receive updates). For better compatibility, the compiler shouldn't knowingly produce negative offsets such as in the following case: export function foo(): void {
memory.grow(1);
memory.fill(8, 0, 9);
} |
Relevant code section: assemblyscript/std/assembly/util/memory.ts Lines 202 to 212 in 057ce46
Indeed looks like a bug, since offset operands do wrap around, while offset immediates do not, so a |
What does it mean? The spec defines offset as signed and seems to throw only on |
If I'm not mistaken, |
Just verified with The first offset value is indeed casted to u64 thus |
The PR linked above fixes invalid store offsets within |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions! |
All WAT snippets were taken from the editor on the AssemblyScript's front page.
Redundant operations
Negative offsets
The text was updated successfully, but these errors were encountered: