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

Variable allocation internal error #607

Closed
sarranz opened this issue Oct 6, 2023 · 2 comments · Fixed by #611
Closed

Variable allocation internal error #607

sarranz opened this issue Oct 6, 2023 · 2 comments · Fixed by #611
Labels

Comments

@sarranz
Copy link
Collaborator

sarranz commented Oct 6, 2023

I have no clue what's going on here, so I don't know whether this is already covered by a different issue. The if (false) seems to be necessary.

fn f(reg ptr u64[1] a, reg u64 x) -> stack u64[1], reg u64 {
    stack ptr u64[1] s;
    s = a;
    a = s;
    return a, x;
}

export
fn main() {
    reg u64 x;
    x = 0;

    stack u64[1] a;
    a[0] = 0;

    if (false) {
        _, _ = f(a, x);
    }
}

gives

"ble.jazz", line 3 (4-10):
internal compilation error in function f:
  Variable allocation: a (defined at "ble.jazz", line 1 (20-21)) and RAX : variable already set
@sarranz sarranz added the bug label Oct 6, 2023
@vbgl
Copy link
Member

vbgl commented Oct 9, 2023

Do you hit this issue in an actual program? Here, all of the code is dead: no effect, no return value. Unfortunately, the f function survives too long. Eliminating dead functions after constant propagation might help.

@sarranz
Copy link
Collaborator Author

sarranz commented Oct 9, 2023

Yes, in libjade. This is halfway through a merge, so maybe it doesn't make much sense. The export function
jade_kem_kyber_kyber512_amd64_ref_keypair_derand calls __crypto_kem_keypair_derand_jazz, which calls __indcpa_keypair_derand, which calls

fn _poly_getnoise_eta1 ... {
  stack u8[KYBER_ETA1*KYBER_N/4 + (3 - KYBER_ETA1)*64] buf;
  ...
  if (KYBER_ETA1 == 2) {  // <-- This is false
    buf[0:KYBER_ETA2*KYBER_N/4], ms = _shake256_128_33(buf[0:KYBER_ETA2*KYBER_N/4], extseed, ms);
  } else {
    buf = _shake256_192_33(buf, extseed);
  }
  ...
  rp = __poly_cbd_eta1(rp, buf[0:KYBER_ETA1*KYBER_N/4]);
  return rp, ms;
}

and

fn _shake256_128_33(reg ptr u8[128] out ... {
  stack ptr u8[128] s_out;
  ...
  s_out = out;
  ...
  out = s_out;
  for i = 0 to 128 {
    c = state[u8 i];
    out[i] = c;
  }
  return out, ms;
}

vbgl added a commit that referenced this issue Oct 10, 2023
vbgl added a commit that referenced this issue Oct 10, 2023
vbgl added a commit that referenced this issue Oct 10, 2023
bgregoir pushed a commit that referenced this issue Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants