jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Unclear register allocation error (once again)

Open eponier opened this issue 2 years ago • 1 comments

If I try to compile

export fn f () -> reg u32 {
  reg u32 r;
  stack u32[1] s;
  r = 0;
  s = #randombytes(s);
  return r;
}

I get the error

"file.jazz", line 1 (0) to line 7 (1):
compilation error:
register allocation: variable r.191 must be allocated to register RAX due to architectural constaints; this register already holds conflicting variable: RAX.64

This is logical that there is an error, because the syscall to randombytes may have erased RAX and the result of function f must be in RAX, so there is no proper assignment for register r. But the error message mentions variable RAX.64 that does not appear anywhere in the program, so this is confusing. Here is what is printed when passing -debug:

Before REGALLOC:
export
fn f () -> (reg u32) {
  reg u64 RSP.60;
  reg u32 r.191;
  reg u64 __p__.192;
  reg mut ptr u64 __len__.193;
  reg u64 __p__.194;
  
  r.191 = #MOV_32(((32u) 0)); /*  */
  __p__.192 = #MOV_64(RSP.60); /* :r */
  __len__.193 = #MOV_64(((64u) 4)); /*  */
  __p__.194 = #randombytes(__p__.192, __len__.193);
  return (r.191);
}

(It was even more confusing for ARM, because the error message mentions r0.** and it is not clear that r0 is the name of the ARM register and has no link with the r I have in my program)

eponier avatar Oct 09 '23 17:10 eponier

Btw, there is a typo in the error message, constaints.

eponier avatar Oct 09 '23 17:10 eponier