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

--- Comment #14 from anlauf at gcc dot gnu.org ---
I looked at cases with character arguments, and it appears that there is a
general issue with (lack or improper) generation of temporaries.  Consider:

program p
  implicit none
  character(4), allocatable :: a(:)
  integer :: k = -999

  a = ["aa","bb"]
! call assign_s (a, (a(2) // "")) ! OK
! call assign_s (a,  a(2) // "" ) ! OK
! call assign_s (a, (a(2)))       ! no proper temporary
! call assign_s (a,  a(2) )       ! invalid Fortran
  call assign_s (a, (a(2)(1:3)))  ! no proper temporary
  print *, allocated (a), k

contains

  subroutine assign_s (a, b)
    character(*), allocatable, intent(out) :: a(:) 
!   character(*),              value       :: b    ! rejected (-> pr110290)
    character(*)                           :: b
    k = len (b)
    print *, b
  end subroutine
end

The first two variants work as expected, the fourth is IMHO invalid because
of aliasing, but the third and fifth should work.

However, compiling with -fsanitize=address,undefined shows that they don't.

Inspecting the dump-tree suggests that there is no proper temporary for the
second argument, even though it is requested.  Also, running under gdb,
I see that the gfc_evaluate_now from the patch is called.

Do we need to do something special to get temporaries here?

Reply via email to