/* If we have reached here with an intrinsic function, we do not
need a temporary except in the particular case that reallocation
- on assignment is active and the lhs is allocatable and a target. */
+ on assignment is active and the lhs is allocatable and a target,
+ or a pointer which may be a subref pointer. FIXME: The last
+ condition can go away when we use span in the intrinsics
+ directly.*/
if (expr2->value.function.isym)
- return (flag_realloc_lhs && sym->attr.allocatable && sym->attr.target);
+ return (flag_realloc_lhs && sym->attr.allocatable && sym->attr.target)
+ || (sym->attr.pointer && sym->attr.subref_array_pointer);
/* If the LHS is a dummy, we need a temporary if it is not
INTENT(OUT). */
--- /dev/null
+! { dg-do run }
+! PR fortran/94578
+! This used to give wrong results.
+program main
+ implicit none
+ type foo
+ integer :: x, y,z
+ end type foo
+ integer :: i
+ integer, dimension(:), pointer :: array1d
+ type(foo), dimension(2), target :: solution
+ integer, dimension(2,2) :: a
+ data a /1,2,3,4/
+ solution%x = -10
+ solution%y = -20
+ array1d => solution%x
+ array1d = maxval(a,dim=1)
+ if (any (array1d /= [2,4])) stop 1
+end program main
--- /dev/null
+! { dg-do run }
+! PR fortran/94578
+! This used to give wrong results. Original test case by Jan-Willem
+! Blokland.
+program main
+ implicit none
+ type foo
+ integer :: x, y
+ end type foo
+ integer :: i
+ integer, dimension (2,2) :: array2d
+ integer, dimension(:), pointer :: array1d
+ type(foo), dimension(2*2), target :: solution
+ data array2d /1,2,3,4/
+ array1d => solution%x
+ array1d = reshape (source=array2d, shape=shape(array1d))
+ if (any (array1d /= [1,2,3,4])) stop 1
+end program main