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

protect prevents unspill #935

Open
Rixxc opened this issue Oct 18, 2024 · 1 comment
Open

protect prevents unspill #935

Rixxc opened this issue Oct 18, 2024 · 1 comment

Comments

@Rixxc
Copy link
Contributor

Rixxc commented Oct 18, 2024

Hello, I have the following (boiled down) example code:

export fn main() -> reg u64 {
    reg u64 t t2;
    reg u64 msf;
    reg bool c;

    msf = #init_msf();

    () = #spill(t);

    c = t == 0;
    if (c) {
        msf = #update_msf(c, msf);
        t = #protect(t, msf);
        t2 = (u64)[t];
    }

    () = #unspill(t);

    reg u64 ret;
    ret = 0;
    return ret;
}

This fails with the following error:

"test.jazz", line 17 (4-21):
compilation error in function main:
lower spilling instructions:
The variable t (defined at "test.jazz", line 2 (12-13))
needs to be spilled before (maybe the variable has been written since the last spill)

This is caused by the assignment due to the #protect expression.

I think there should be an exception for assignments with #protect, since they do not change the contents of the variable, to allow this code to compile.

@bgregoir
Copy link
Contributor

First, your program is unsafe : you use t before initialising it.
Second the if set the value of t (invalidating its spilled value).
This explain the error (and it is exactly said in the error message)

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

No branches or pull requests

2 participants