Issue 168561
Summary [flang] invalid code for where
Labels flang
Assignees
Reporter MarDiehl
    I've encountered an issue with Flang 21.1.5 which generates invalid code for `where`. I could reproduce something similar with the following snippet. It should print the sequence of numbers from 1 to 33 but it prints `33 33 33 33 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33`. Note that I've disabled use of the random number generator because it always gives `2.2470951E-05`.

The same behavior is seen on [compiler explorer](https://godbolt.org/z/9Mnqfzf7s) which uses Flang trunk (commit cce852ff03be5da56a9dc3d102a142812b2008d1)

```fortran
program test

 implicit none
  integer, dimension(:), allocatable :: v
  real :: r
 integer :: i

  call random_number(r) ! does not work

  print*, 'r',r
 r = 0.32
  allocate(v(1+int(r*100.0)),source=0)

  print*, 'size(v)',size(v)

  do i = 1, size(v)
    where(x(size(v),i)) v=i
  end do

  print*, v
  contains

  function x(n,i)
    integer, intent(in) :: n,i
    logical, dimension(:), allocatable :: x

 allocate(x(n),source=.false.)
    x(i) = .true.

  end function x

end program test
```

Note: Also reported on [LLVM Discourse](https://discourse.llvm.org/t/invalid-code-for-where/88881)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to