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

Bug C backend: Convert Cptr to c_p_pointer #1890

Closed

Description

@ronnuriel

Bug when converting Cptr to c_p_pointer (to work as array):

a: Pointer[u16[32768]] = c_p_pointer(vresult_l4, u16[32768])

code generation error: Type number '14' not supported

   --> /home/eamiel/tmp_cp_release_01/copperhead/demo-apps/belex-direct-fragment/device/../mat_vec_device.py:279:5

    |

279 |     a: Pointer[u16[32768]] = c_p_pointer(vresult_l4, u16[32768])

But i16 works:
a: Pointer[i16[32768]] = c_p_pointer(vresult_l4, i16[32768])

Activity

  1. added
    c
    on Jun 12, 2023
  2. self-assigned this
    on Jun 12, 2023
  3. certik commented on Jun 12, 2023

    @certik
    Contributor

    Thanks, that's a great bug report. We'll fix it quickly.

  4. certik commented on Jun 12, 2023

    @certik
    Contributor

    Looks like there are several related bugs, both in C and LLVM backends. The first minimal reproducible example to fix:

    from lpython import CPtr, c_p_pointer, empty_c_void_p, Pointer, u16            
    
    def test_tuple_return():
        e: CPtr = empty_c_void_p()
        iarray5: Pointer[u16[50]] = c_p_pointer(e, u16[50])         
    
    test_tuple_return()

    gives:

    $ lpython bindc_07.py           
    ; ModuleID = 'LFortran'
    source_filename = "LFortran"
    
    %array = type { i16*, i32, %dimension_descriptor*, i1, i32 }
    %dimension_descriptor = type { i32, i32, i32 }
    
    define void @__module__global_symbols__lpython_main_program() {
    .entry:
      call void @__module__global_symbols_test_tuple_return()
      br label %return
    
    return:                                           ; preds = %.entry
      ret void
    }
    
    define void @__module__global_symbols_test_tuple_return() {
    .entry:
      %e = alloca void*, align 8
      %iarray5 = alloca %array*, align 8
      store void* null, void** %e, align 8
      %0 = load void*, void** %e, align 8
      %1 = alloca <1 x i32>, align 4
      %2 = getelementptr <1 x i32>, <1 x i32>* %1, i32 0, i32 0
      store i32 50, i32* %2, align 4
      %3 = getelementptr <1 x i32>, <1 x i32>* %1, i32 0, i32 0
      %4 = alloca %array, align 8
      %5 = getelementptr %array, %array* %4, i32 0, i32 1
      store i32 0, i32* %5, align 4
      %6 = alloca %dimension_descriptor, align 8
      %7 = getelementptr %array, %array* %4, i32 0, i32 2
      store %dimension_descriptor* %6, %dimension_descriptor** %7, align 8
      %8 = getelementptr %array, %array* %4, i32 0, i32 4
      store i32 1, i32* %8, align 4
      store %array* %4, void* %0, align 8
      %9 = getelementptr %array, %array* %4, i32 0, i32 0
      %10 = getelementptr %array, %array* %4, i32 0, i32 2
      %11 = load %dimension_descriptor*, %dimension_descriptor** %10, align 8
      %12 = bitcast void* %0 to i16*
      store i16* %12, i16** %9, align 8
      %13 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %11, i32 0
      %14 = getelementptr %dimension_descriptor, %dimension_descriptor* %13, i32 0, i32 0
      %15 = getelementptr %dimension_descriptor, %dimension_descriptor* %13, i32 0, i32 1
      %16 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %11, i32 0
      %17 = getelementptr %dimension_descriptor, %dimension_descriptor* %16, i32 0, i32 2
      store i32 1, i32* %14, align 4
      %18 = getelementptr inbounds i32, i32* %3, i32 0
      %19 = load i32, i32* %18, align 4
      store i32 0, i32* %15, align 4
      %20 = sub i32 %19, 0
      %21 = add i32 %20, 1
      store i32 %21, i32* %17, align 4
      %22 = mul i32 1, %21
      br label %return
    
    return:                                           ; preds = %.entry
      ret void
    }
    
    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:
    Stored value type does not match pointer operand type!
      store %array* %4, void* %0, align 8
     void
    
    
    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).
  5. certik commented on Jun 12, 2023

    @certik
    Contributor

    @ronnuriel the issue should be now fixed, please go ahead and try the latest LPython version and see if it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions