Issue 184927
Summary [Flang][OpenMP] declare reduction on derived types fails: verifier error with initializer, abort without initializer
Labels flang
Assignees
Reporter nakazawa-fj
    ```
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 3f024d08355d40e935d89c19d799ccdd298e95a7)
```

When using OpenMP `declare reduction` in LLVM Flang to define a user-defined reduction for a derived type,
compilation fails in both cases: with an initializer clause and without an initializer clause.

sample.f90
```fortran
  implicit none
 type t
     integer::member
  end type t
  integer::i
  !$omp declare reduction(a:t:omp_out%member=omp_out%member+omp_in%member)
  !$omp initializer(omp_priv%member=0)
  type(t)::x1
  x1%member=0
  call omp_set_num_threads(2)
  !$omp parallel do reduction(a:x1)
  do i=1,10
 x1%member=x1%member+1
  end do
  !$omp end parallel do
  print *,"pass"
end program
```

### Actual Result (with initializer)

```
$ flang sample.f90 -fopenmp
error: loc("/work/home/suguro/bug-report/15401/sample.f90":1:3): 'omp.declare_reduction' op expects initializer region to yield a value of the reduction type
error: verification of lowering to FIR failed
```

### Behavior without the initializer clause

If the initializer clause is removed:

```fortran
!$omp declare reduction(a:t:omp_out%member = omp_out%member + omp_in%member)
```

the compilation fails with the following error:

```
$ flang sample.f90 -fopenmp
error: loc("/work/home/suguro/bug-report/15401/sample.f90":1:3): /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Lower/OpenMP/ClauseProcessor.cpp:471: not yet implemented: declare reduction without an initializer clause is not yet supported
LLVM ERROR: aborting
```
```
$ gfortran sample.f90 -fopenmp
sample.f90:6:26:

    6 |   !$omp declare reduction(a:t:omp_out%member=omp_out%member+omp_in%member)
          | 1
          Error: Missing INITIALIZER clause for !$OMP DECLARE REDUCTION of derived type without default initializer at (1)
```
```
$ ifx sample.f90 -fopenmp
$ ./a.out
 pass
```

With an initializer clause, flang attempts to handle `declare reduction`, but fails at the FIR verification stage, leading to a verification error.
Without an initializer clause, flang emits a diagnostic indicating that the feature is not yet implemented.

According to OpenMP 6.0, Section 7.6.14, a declare_reduction is fully identified by the reduction identifier and type-name list,
so the initializer clause is optional. However, compiler behavior differs in practice: some compilers (e.g., gfortran)
impose additional constraints, while others (ifx) accept this code.

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

Reply via email to