You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ lpython expr_16.py...declare void @_lfortran_printf(i8*, ...)declare void @_lcompilers_print_error(i8*, ...)declare void @exit(i32)define i32 @main(i32 %0, i8** %1) {.entry: call void @_lpython_set_argv(i32 %0, i8** %1) call void @__module__global_symbols__lpython_main_program() ret i32 0}declare void @_lpython_set_argv(i32, i8**)code generation error: asr_to_llvm: module failed verification. Error:Both operands to a binary operator are not of the same type! %20 = sub i64 %19, i32 0Both operands to a binary operator are not of the same type! %21 = add i64 %20, i32 1Stored value type does not match pointer operand type! store i64 %21, i32* %17, align 4 i32Both operands to a binary operator are not of the same type! %22 = mul i32 1, i64 %21Note: if any of the above error or warning messages are not clear or are lackingcontext please report it to us (we consider that a bug that must be fixed).
The issue above is caused by using i64 instead of i32 for array dimensions. That is a bug to be fixed: either give a compiler error, or work correctly.
I think the example you posted shouldn't work. t: Pointer[f64[:]] = c_p_pointer(xs_ptr, f64[:]) means we don't know the shape of t. For 1-D arrays this is fine but for multi-dimensional arrays this is not going to work. If t: Pointer[f64[:, :]] = c_p_pointer(xs_ptr, f64[:, :]) is used then its impossible to know the location of t[2, 3] in memory because for same length there can be multiple shapes possible. For example, length: i32 = 32, t can have t[16, 2], t[2, 16], t[4, 8] and so on. So I think we should change the signature of c_p_pointer to accept target shape as well, t: Pointer[f64[:, :] = c_p_pointer(xs_ptr, f64[:, :], [4, 8]) or otherwise, the same signature as Fortran's c_f_pointer i.e., c_p_pointer(xs_ptr, t, [4, 8]).
Activity
certik commentedon May 25, 2023
The issue above is caused by using i64 instead of i32 for array dimensions. That is a bug to be fixed: either give a compiler error, or work correctly.
After fixing the test in #1860 it now fails with:
There is some off by one error it seems, because the following diff makes it work:
@czgdp1807 I remember you mentioning that there is some issue with starting from 1 instead of 0, which likely is causing this issue here.
czgdp1807 commentedon May 30, 2023
I think the example you posted shouldn't work.
t: Pointer[f64[:]] = c_p_pointer(xs_ptr, f64[:])means we don't know the shape oft. For 1-D arrays this is fine but for multi-dimensional arrays this is not going to work. Ift: Pointer[f64[:, :]] = c_p_pointer(xs_ptr, f64[:, :])is used then its impossible to know the location oft[2, 3]in memory because for samelengththere can be multiple shapes possible. For example,length: i32 = 32,tcan havet[16, 2],t[2, 16],t[4, 8]and so on. So I think we should change the signature ofc_p_pointerto accept target shape as well,t: Pointer[f64[:, :] = c_p_pointer(xs_ptr, f64[:, :], [4, 8])or otherwise, the same signature as Fortran'sc_f_pointeri.e.,c_p_pointer(xs_ptr, t, [4, 8]).certik commentedon May 30, 2023
Here is the most general case: