-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Functions with assembly containing mcli
result in MemoryOverflow
when passed a literal
#1455
Comments
Here's a full repro showing that yep, the passed value must be in a local variable and not passed as a literal. script;
fn f(bits: b256) {
asm(r1: bits) {
mcli r1 i12;
};
}
fn main() {
// This works.
let b = 0xABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB;
f(b);
// This fails.
f(0xCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD);
} The second call is trying to use a literal which is referenced directly in the data section which is not stack memory and therefore causes the |
I wouldn't call this a bug, since it's expected behavior than you can't clear memory outside your owned stack or heap range. |
It's a bit tricky for Sway devs with the implicit by-reference semantics, versus having explicit references in the language. We tend to say anything that doesn't fit in a register is passed around by reference, but the Sway dev doesn't want to think about whether it was allocated somewhere on the stack by the compiler or not. So I think the above should work, and the inliner needs to put all args onto the stack by default, and later if we find that copying it is unnecessary we can optimise it away. Once we're back to non-critical work I'm very keen to update the memory model we currently use in the IR, and this fix fits into that scope of work. |
This is reasonable I think. If we do this, then only devs writing E.g.: script;
fn main() {
asm(r1: 0xCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD) {
mcli r1 i12;
};
} |
Ugh, even then I feel like |
Yes absolutely... I wanted to say that legal code should never panic (unless intentional, e.g.: |
Some updates from: #2217 (comment) I'm starting to think that this behavior should be disallowed by implementing mutability checking in |
That would work too. 🙂 |
For example, in order to call :
the parameter must first be assigned to a variable. :
otherwise a
MemoryOverflow
error occurs.The text was updated successfully, but these errors were encountered: