[Bug fortran/106071] single where run error

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Jun 26 18:36:32 GMT 2022


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

--- Comment #2 from kargl at gcc dot gnu.org ---
(In reply to han.wu from comment #0)
> two layer where work ok, why single where work error? 
> 
> example one:
> 
> program test
>   real :: x(3) = 1, y(3) = 2
>   logical :: m(3) = .true., m2(3) = .false.
>   where (m)
>     x = f1()
>   end where
>   if (any(x/=3)) then
>     print *, 'FAIL', x
>   else
>     print *,'ok'
>   end if
> contains
>   function f1()
>     m = .false.
>     !m2 = .true.
>     f1 = 3
>   end function
> end
> 
> gfortran-12:
> ASM generation compiler returned: 0
> Execution build compiler returned: 0
> Program returned: 0
>  FAIL   3.00000000       1.00000000       1.00000000   
> 

Well, this is simple to understand.  The WHERE is eventually translated by
gfc_trans_where_3() from trans-stmt.cc.  What is essentially happening is
that (in pseudo-code) the WHERE is converted to


do i = 1, size(m)
   if (m(i)) then
      m = .false.   ! This resets all elements of m!
      x(i) = 3
   end if
end do

where I have in-lined the function f1.  Looking in gfc_trans_where_3() we see
that gfortran should create a temporary when scalarizing the mask.  I don't
know how to do that.  When you come up with a patch, can you submit it?


More information about the Gcc-bugs mailing list