jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Addition involving a stack variable fails

Open haselwarter opened this issue 3 years ago • 5 comments

The following program

u64 foo = 4;

export fn main () -> reg u64 {
    stack u64 y;
    reg u64 ret;
    y = 42;
    ret = y + foo;
    return ret;
}

fails with

line 7 (4-18):
internal compilation error in function main:
  asmgen: (compile_arg) not compatible asm_arg
Please report at https://github.com/jasmin-lang/jasmin/issues

Presumably this is because y is stack allocated and the program should be rejected more gracefully.

haselwarter avatar Feb 16 '22 09:02 haselwarter

Thanks for the report. This is indeed a bug (both in master and glob-array3).

The correct behavior of the compiler would be to reject this program with the following explanation: there is no addition instruction in the target architecture (x86-64) that takes two arguments in memory and put the result in a register.

vbgl avatar Feb 16 '22 10:02 vbgl

The compiler checks at some point that there is the right variant of the assembly instruction in the target architecture. But here it fails earlier than that. If I'm not mistaken, what fails here is a check that the result and the first argument of the addition are the same. So it is not clear to me that we can give an error message like the one Vincent suggests, but we can certainly improve the message. A sentence "the result and the k-th argument of the addition should be the same" could be a good first try.

eponier avatar Feb 16 '22 10:02 eponier

Here the error is raised by “asmgen”, the final pass of the compiler.

vbgl avatar Feb 16 '22 10:02 vbgl

Both checks that I mentioned are inside asmgen. The one checking that the argument must be the same is just earlier in the pass than the other.

eponier avatar Feb 16 '22 10:02 eponier

You’re right Jean-Christophe. However this particular error message is improved, it will remain a compiler bug. The instruction selection emitted an instruction that does not exist (without even a word of warning).

vbgl avatar Feb 16 '22 10:02 vbgl