2 ! Check the fix for PR48462 in which the assignments involving matmul
3 ! seg faulted because a was automatically freed before the assignment.
4 ! Since it is related, the test for the fix of PR48746 has been added
5 ! as a subroutine by that name.
7 ! Contributed by John Nedney <ortp21@gmail.com>
11 integer, parameter :: dp = kind(0.0d0)
12 real(kind=dp), allocatable :: delta(:,:)
13 real(kind=dp), allocatable, target :: a(:,:)
14 real(kind=dp), pointer :: aptr(:,:)
20 if (.not. associated (aptr, a)) call abort () ! reallocated to same size - remains associated
22 if (.not. associated (aptr, a)) call abort () ! reallocated to smaller size - remains associated
24 if (associated (aptr, a)) call abort () ! reallocated to larger size - disassociates
29 ! Original reduced version from comment #2
32 real(kind=dp), allocatable :: b(:,:)
37 a = reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3])
38 b = reshape ([1d0, 0d0, 0d0, 0d0, 1d0, 0d0, 0d0, 0d0, 1d0], [3,3])
40 a = matmul( matmul( a, b ), b )
41 delta = (a - reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3]))**2
42 if (any (delta > 1d-12)) call abort
43 if (any (lbound (a) .ne. [1, 1])) call abort
46 ! Check that all is well when the shape of 'a' changes.
49 real(kind=dp), allocatable :: a(:,:)
50 real(kind=dp), allocatable :: b(:,:)
52 b = reshape ([1d0, 1d0, 1d0], [3,1])
53 a = reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3])
55 a = matmul( a, matmul( a, b ) )
57 delta = (a - reshape ([198d0, 243d0, 288d0], [3,1]))**2
58 if (any (delta > 1d-12)) call abort
59 if (any (lbound (a) .ne. [1, 1])) call abort
63 a = reshape ([(real(i, dp), i = 1, 100)],[10,10])
66 ! This is a further wrinkle on the original problem and came about
67 ! because the dtype field of the result argument, passed to matmul,
68 ! was not being set. This is needed by matmul for the rank.
70 ! Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>
73 integer, parameter :: m=10, n=12, count=4
74 real :: optmatmul(m, n)
75 real :: a(m, count), b(count, n), c(m, n)
76 real, dimension(:,:), allocatable :: tmp
80 if (any (lbound (tmp) .ne. [1,1])) call abort
81 if (any (ubound (tmp) .ne. [10,12])) call abort