PSyclone
PSyclone copied to clipboard
Incorrect semantics of WHERE in some cases
For this program (with #2687 merged to support non-elementals and array notation):
program where_test
integer, dimension(10) :: a, b = 0, c = 0
a = (/1, 2, 3, 4, 5, 6, 7, 8, 9 ,10 /)
where(a > 5)
b = sum(a)
c = b(7) + 1
elsewhere(a > 5)
c = a
elsewhere
b = 1
c = b(7) + 1
end where
write(*,*) c
end program
compiled with gfortran prints:
./a.out
1 2 3 4 56 56 56 56 56 56
if I do psyclone->gfortran it prints:
./a.out
1 2 3 4 1 1 56 56 56 56
The reason I believe is that we always create the fused version of the where bodies, but the semantics imply that each array statement is evaluated one by one for each index before moving to the next, and the fusing is just an optimisation that most of the times can be done but not always.