https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128682

--- Comment #17 from Harald Anlauf <anlauf at gcc dot gnu.org> ---
Steve's patch is now committed to trunk and to 16-branch.

In the meantime there appeared the review

https://gcc.sashiko.dev/#/patchset/888f3fa4-864a-47dd-8df5-409a83c35b80%40gmx.de

which points out possible remaining problems.  And indeed I found that
replacing reshape by a function of variable character length breaks the
compiler.

program p
  implicit none(type, external)
  character(len=6)   :: blk = 'ab#.#.'
  integer, parameter :: w = 2, h = 3
  integer :: i
  character, allocatable :: ref(:,:)
  ref = transpose (reshape ([(blk(i:i), i=1, len(blk))], [w, h]))
! call show ( transpose (reshape ([(blk(i:i), i=1, len(blk))], [w, h])))
  call show ( transpose (char1_array ()))  ! OK
  call show ( transpose (charn_array (1))) ! ICE
! call show ( transpose (char_array  ()))  ! ICE
  deallocate (ref)
contains
  function char1_array () result (res)
    character(len=1), allocatable :: res(:,:)
    integer :: i
    res = reshape ([(blk(i:i), i=1, len(blk))], [w, h])
  end function
  function charn_array (n) result (res)
    integer, intent(in)           :: n
    character(len=n), allocatable :: res(:,:)
    integer :: i
    res = reshape ([(blk(i:i), i=1, len(blk))], [w, h])
  end function
  function char_array () result (res)
    character(len=:), allocatable :: res(:,:)
    integer :: i
    res = reshape ([(blk(i:i), i=1, len(blk))], [w, h])
  end function
  subroutine show (g)
    character, intent(in) :: g(:, :)
    if (any (g /= ref)) then
       stop 1
       print '(a)', g
    end if
  end subroutine show
end program p

With the patched compiler this now produces

pr128682-z2.f90:1:9:

    1 | program p
      |         ^
internal compiler error: n from charn_array referenced in p
0x3fc97c1 internal_error(char const*, ...)
        ../../gcc-trunk/gcc/diagnostic-global-context.cc:787
0x1ec3172 convert_nonlocal_reference_op
        ../../gcc-trunk/gcc/tree-nested.cc:1209
0x225ee45 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ../../gcc-trunk/gcc/tree.cc:12018
[...]

Reply via email to