← 输入框|github.com|刷新
Skip to content

integration_tests/expr_16.py fails in LLVM #1859

Closed

Description

@certik
$ 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 0
Both operands to a binary operator are not of the same type!
  %21 = add i64 %20, i32 1
Stored 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 %21



Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that must be fixed).

Activity

  1. certik commented on May 25, 2023

    @certik
    ContributorAuthor

    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:

    $ lpython expr_16.py 
    0.00000000000000000e+00 3.00000000000000000e+00
    AssertionError

    There is some off by one error it seems, because the following diff makes it work:

    --- a/integration_tests/expr_16.py
    +++ b/integration_tests/expr_16.py
    @@ -14,8 +14,8 @@ def main() -> None:
         xs_ptr: CPtr = _lfortran_malloc(length * i32(sizeof(f64)))
         foo(xs_ptr, length)
         t: Pointer[f64[:]] = c_p_pointer(xs_ptr, f64[:])
    -    print(t[0], t[1])
    -    assert t[0] == 3.0
    -    assert t[1] == 4.0
    +    print(t[1], t[2])
    +    assert t[1] == 3.0
    +    assert t[2] == 4.0
     
     main()

    @czgdp1807 I remember you mentioning that there is some issue with starting from 1 instead of 0, which likely is causing this issue here.

  2. self-assigned this
    on May 26, 2023
  3. czgdp1807 commented on May 30, 2023

    @czgdp1807
    Collaborator

    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]).

  4. certik commented on May 30, 2023

    @certik
    ContributorAuthor

    Here is the most general case:

    t: Pointer[f64[:, :] = c_p_pointer(xs_ptr, f64[:, :], [n, m])
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions