Issue 173585
Summary [Flang] Compilation error in the assignment statement for polymorphic entity within WHERE construct
Labels flang:frontend
Assignees
Reporter ohno-fj
    ```
Version of flang : 22.0.0(366f6eb607dab74b7be28d3bd72736273329d647)/AArch64
```

In the attached program (`sngg284r_3.f90`), within `WHERE construct`, an assignment statement involving `polymorphic entity` results in a compilation error.
Upon reviewing `WHERE construct` in `Fortran 2023 Standard`, I could not find any description of `polymorphic` restriction.
Is this error check valid?

Compilation completes successfully in the following cases:
- Remove the WHERE construct, or
  (The above is `sngg284r_31.f90`.)
- Use an older version of Flang
  Example: Use the following Flang
  `Version of Flang : 22.0.0(eef79c8b49aa45458bbaf895603385a7819cc182)/AArch64`
  The log is attached at the end.


The following are the test program, Flang, Gfortran and ifx compilation/execution results.

sngg284r_3.f90:
```fortran
program main
  type b
 integer::c
  end type b
  logical,parameter::t=.true.,f=.false.
 logical::mask(3)=[t,f,t]
  class(b),allocatable::u(:)
 type(b)::x(3)=b(1)
  allocate(u(3),source=b(0))

  where(mask)
     u=x
 end where
  print *,'pass'

  deallocate(u)
end program main
```

```
$ flang sngg284r_3.f90
error: Semantic errors in sngg284r_3.f90
./sngg284r_3.f90:12:6: error: Assignment to whole polymorphic allocatable 'u' may not be nested in a WHERE statement or construct
 u=x
       ^
$
```

```
$ gfortran sngg284r_3.f90; ./a.out
 pass
$
```

```
$ ifx sngg284r_3.f90; ./a.out
 pass
$
```


sngg284r_31.f90:
```fortran
program main
  type b
 integer::c
  end type b
  logical,parameter::t=.true.,f=.false.
 logical::mask(3)=[t,f,t]
  class(b),allocatable::u(:)
 type(b)::x(3)=b(1)
  allocate(u(3),source=b(0))

!  where(mask)
 u=x
!  end where
  print *,'pass'

  deallocate(u)
end program main
```

```
$ flang sngg284r_31.f90; ./a.out
 pass
$
```

```
$ flang --version
flang version 22.0.0git (https://github.com/llvm/llvm-project.git eef79c8b49aa45458bbaf895603385a7819cc182)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/llvm/aarch64/main-20250901-eef79c8b49aa/bin
Build config: +assertions
$
$ flang sngg284r_3.f90; ./a.out
 pass
$
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to