flang
flang copied to clipboard
minloc/maxloc output wrong results
program t1
integer square(3,6)
integer res(3)
square(1,:) = (/1,18,4,15,7,12/)
square(2,:) = (/2,17,5,14,8,11/)
square(3,:) = (/3,16,6,13,9,10/)
res = minloc(square(1:3,4:6),dim=1)
print *, res
end
output: 0 0 0
expect: 3 3 3
program t2
integer res(1), A(2,5)
A(1,:) = (/ 5,3,1,2,4 /)
print *, minloc(A(:,3:1:-1),dim=1)
end
output: 0: COPY_IN: actual argument length differs from dummy
expect: 2 2 2
program t3
integer, dimension(3) :: rslts
integer, dimension(2,4) :: m
m(1,:) = (/3,6,11,14/)
m(2,:) = (/4,5,12,13/)
rslts(2:3) = minloc(m(1:2,3:4),dim=1)
print *, rslts
end
output: 0 0 0
expect: 0 1 2
If the array section is stored into a temporary array, the result is correct. All the modified test cases below output correct results
program t1
integer :: square(3,6), temp(3,3)
square(1,:) = (/1,18,4,15,7,12/)
square(2,:) = (/2,17,5,14,8,11/)
square(3,:) = (/3,16,6,13,9,10/)
temp = square(1:3,4:6)
print *, minloc(temp,dim=1)
end
program t2
integer :: A(2,5), temp(2,3)
A(1,:) = (/5,3,1,2,4/)
temp = A(:,3:1:-1)
print *, minloc(temp,dim=1)
end
program t3
integer, allocatable :: temp(:,:)
temp = m(1:2,3:4)
rslts(2:3) = minloc(temp,dim=1)
print *, rslts
end
so adding a temporary allocatable array of the appropriate rank can be a workaround to fix these issues.
program main
integer,dimension(10,10) :: m_2
integer,dimension(4) :: res
m_2 = 0
m_2(1,:) = (/1,2,1,2,1,2,1,2,1,2/)
m_2(2,:) = (/2,1,2,1,2,1,2,1,2,1/)
m_2(3,:) = (/1,2,1,2,1,2,1,2,1,2/)
m_2(4,:) = (/2,1,2,1,2,1,2,1,2,1/)
m_2(5,:) = (/1,2,1,2,1,2,1,2,1,2/)
m_2(6,:) = (/2,1,2,1,2,1,2,1,2,1/)
m_2(7,:) = (/1,2,1,2,1,2,1,2,1,2/)
m_2(8,:) = (/2,1,2,1,2,1,2,1,2,1/)
m_2(9,:) = (/1,2,1,2,1,2,1,2,1,2/)
m_2(10,:) = (/2,1,2,1,2,1,2,1,2,1/)
res = minloc(m_2(:,7:),dim = 1)
print *,res
end
output: malloc.c:2399: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
expect: 1 2 1 2