llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.77k stars 11.44k forks source link

[flang] failed lowering for sequence association of derived-type #99065

Open bcornille opened 1 month ago

bcornille commented 1 month ago

Reproducer: (contained_subroutine_flatten.f90)

program flattening_test
  use iso_fortran_env, only : int32
  implicit none

  type mytype
    integer(int32) :: k
  end type mytype

  class(mytype), allocatable :: multidim_array(:,:)
  integer(int32), parameter :: num = 4
  integer(int32) :: i

  allocate(mytype :: multidim_array(num,num))
  call reinterpret_1d(multidim_array,num*num)

contains

  subroutine reinterpret_1d(array, n)
    integer(int32), intent(in) :: n
    type(mytype), intent(inout) :: array(n)
    integer(int32):: j
    do j = 1, n
      array(j)%k = j
    enddo
  end subroutine reinterpret_1d

end program flattening_test

Error:

>> flang-new contained_subroutine_flatten.f90
error: loc("/home/bcornill/Reproducers/SWDEV/temp/contained_subroutine_flatten.f90":14:3): 'fir.rebox' op result type and shape operand ranks must match
error: verification of lowering to FIR failed

Changing either class(mytype), allocatable :: multidim_array(:,:) to type(mytype), allocatable :: multidim_array(:,:) or type(mytype), intent(inout) :: array(n) to class(mytype), intent(inout) :: array(n) resolves the error.

llvmbot commented 1 month ago

@llvm/issue-subscribers-flang-ir

Author: Brian Cornille (bcornille)

Reproducer: (contained_subroutine_flatten.f90) ``` program flattening_test use iso_fortran_env, only : int32 implicit none type mytype integer(int32) :: k end type mytype class(mytype), allocatable :: multidim_array(:,:) integer(int32), parameter :: num = 4 integer(int32) :: i allocate(mytype :: multidim_array(num,num)) call reinterpret_1d(multidim_array,num*num) contains subroutine reinterpret_1d(array, n) integer(int32), intent(in) :: n type(mytype), intent(inout) :: array(n) integer(int32):: j do j = 1, n array(j)%k = j enddo end subroutine reinterpret_1d end program flattening_test ``` Error: ``` >> flang-new contained_subroutine_flatten.f90 error: loc("/home/bcornill/Reproducers/SWDEV/temp/contained_subroutine_flatten.f90":14:3): 'fir.rebox' op result type and shape operand ranks must match error: verification of lowering to FIR failed ``` Changing either `class(mytype), allocatable :: multidim_array(:,:)` to `type(mytype), allocatable :: multidim_array(:,:)` or `type(mytype), intent(inout) :: array(n)` to `class(mytype), intent(inout) :: array(n)` resolves the error.
klausler commented 1 month ago

https://github.com/llvm/llvm-project/pull/99294