jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Late crash when using inline value as reg argument

Open vbgl opened this issue 1 year ago • 4 comments

Compiling the following program triggers an unfathomable internal error:

fn f(reg u32 x) -> reg u32 {
  return x;
}

export
fn main() -> reg u32 {
  inline u32 z;
  z = 42;
  reg u32 r;
  r = f(z);
  return r;
}

"get_pvar.jazz", line 10 (2-11): internal compilation error in function main: stack allocation: get_Pvar: variable expected Please report

Reported by @cos-imo.

vbgl avatar Jul 13 '24 14:07 vbgl

Indeed, stack alloc assumes that every function argument is a variable, and badly fails otherwise. During typing, we reject most programs where it is not the case (r = f(42) is rejected, for instance), but with inline it is possible to pass typing and reach stack alloc with an argument that is not a variable.

I don't know what the proper fix is. Having stack alloc emit a nicer error is easy to do, while detecting this problem during typing seems hard, so I'd fix stack alloc. What do you think?

eponier avatar Jul 29 '24 07:07 eponier

I think that a checker after type-checking and before compilation should be able to properly address this kind of errors.

vbgl avatar Jul 29 '24 08:07 vbgl

In general, do you think that we should remove everything not strictly related to typing from pretyping and put it in that pass?

eponier avatar Jul 29 '24 08:07 eponier

Precisely. That would also solve issues like #727.

vbgl avatar Jul 29 '24 09:07 vbgl