<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57219>57219</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Parsing error in omp declare reduction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiranchandramohan
</td>
</tr>
</table>
<pre>
**Reproducer**
Compiling the following program with a `declare reduction`,
```
subroutine reduce_1 ( n, locs )
type :: loc
integer :: x
integer :: y
end type
integer :: n
type(loc) :: locs(n)
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
type(loc) :: diffp = loc( 0, 0 )
integer :: i
!ERROR: The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause.
!$omp parallel do reduction(- : diffp)
do i = 1, n
diffp%x = diffp%x - locs(i)%x
diffp%y = diffp%y - locs(i)%y
end do
end subroutine
```
produces the following error.
```
error: Could not parse ../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: error: expected 'LOGICAL'
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: in the context: intrinsic type spec
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: in the context: declaration type spec
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:3: in the context: specification construct
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:3: in the context: declaration construct
!$omp declare reduction(- : loc : omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:6:3: in the context: specification part
type :: loc
^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:5:1: in the context: SUBROUTINE subprogram
subroutine reduce_1 ( n, locs )
^
~
```
Note: Changing `loc` to `type(loc)` produces a semantics crash.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztl1uPmzoQgH-NebGCwCy5PPCQ5lKt1G6qdPe5MmASt46NbLNNzq8_YxMSdpeqPdKeVpU2QsB4xmbmmzEZclWeMkTmcGxZrVXZFEy3MoqWKJov1KHmgssdtnuGKyWE-u4ksN1pesDfud1jitE4KlkhqGZYM1jEciVhDJFFu4y7bw8vmibXqrFcns3ZlxgjMsUSJmChCgPSrDXF2J5qhlEyh8PpumGMubRsx3SnO_5Qc-o0TJZ-uU5-Zif7jwR_3NPIrPdsA4Py4lpnjUiMyA2Awi8ZkOkInyf7KwazLxA6CEsfDZmeRxBJj3jk9Vx6wcG4Kk995ck5Aa5xyS2ngv_jsuZXqjV_7C3uUhC1xk-dHgyx5FVV92ZjNx1H_Ww8Q8ZfoFhtt5utU91DwRy4bMwVB1Y109QqjbkBWLVmBbWsxIbLguFNzeTHTzgNCaaQKDCRymLT1LXSzopLX4Tb1fJhcX-7ucMAuzEsfJmHmmoqBBO4VAO58FH2QgIj7oOOXbTyWkadpcsFqK_SqCsG7tGmx4E5pydzTi_mPCnKUvU5upHrFhncQee9ap5tS6a10uHgDK9y4S9UI0qPFjAZhsMQkXUlqNzB1TIDxbb-zA5UWu78XbdpgRsgO2ornFr-yEYX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