Attempted pointer arithmetic generates bad llvm IR
John-Titor opened this issue · comments
// pointer arithmetic generates bad llvm IR
proc test(arg: @[]_byte) : @[]_byte
{
return arg + 2;
}
➜ issues git:(master) ✗ ../src/eslc2 -L9.0.0 -m x86-64 02_pointer_arithmetic.esl > out.ll
➜ issues git:(master) ✗ ../src/llvm -m x86-64 -I out.ll
/usr/local/opt/llvm/bin/opt: out.ll:9:11: error: invalid operand type for instruction
%1 = add [0 x i8]* %0, inttoptr(i64 2 to [0 x i8]*)
^
I agree that's an ugly error message.
There is no explicit pointer arithmetic in ESL. What you are doing is return a pointer to a sub-array:
proc test(arg: @[]_byte) : @[]_byte
{
return arg[2:];
}
That's a much cleaner approach from the language perspective as well, thanks.