<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/163336>163336</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][OpenMP] OpenMP Loop Directives missed for consecutive OpenMPLoopDirectives
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Stylie777
</td>
</tr>
</table>
<pre>
When a Fortran program has consecutive Do loops with OpenMP directives, flang is not processing the directives after the first loop. For example the following program:
```
subroutine s
integer :: a(2)
integer :: b(2)
!$omp do reduction (+: a(2))
do i = 1, 2
a(2) = a(2) + i
end do
!$omp end do
!omp do reduction (+: b(2))
do i = 1,5
b(2) = b(2) + 1
end do
!omp end do
end subroutine
```
Generates the following parse tree output (annotated with the location of the bug)
```
InternalSubprogram -> SubroutineSubprogram
| | | SubroutineStmt
| | | | Name = 's'
| | | SpecificationPart
| | | | ImplicitPart ->
| | | | DeclarationConstruct -> SpecificationConstruct -> TypeDeclarationStmt
| | | | | DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec ->
| | | | | EntityDecl
| | | | | | Name = 'a'
| | | | | | ArraySpec -> ExplicitShapeSpec
| | | | | | | SpecificationExpr -> Scalar -> Integer -> Expr = '2_4'
| | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | DeclarationConstruct -> SpecificationConstruct -> TypeDeclarationStmt
| | | | | DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec ->
| | | | | EntityDecl
| | | | | | Name = 'b'
| | | | | | ArraySpec -> ExplicitShapeSpec
| | | | | | | SpecificationExpr -> Scalar -> Integer -> Expr = '2_4'
| | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | ExecutionPart -> Block
| | | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct
| | | | | OmpBeginLoopDirective
| | | | | | OmpLoopDirective -> llvm::omp::Directive = do
| | | | | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause
| | | | | | | Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add
| | | | | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> ArrayElement
| | | | | | | | DataRef -> Name = 'a'
| | | | | | | | SectionSubscript -> Integer -> Expr = '2_4'
| | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | DoConstruct
| | | | | | NonLabelDoStmt
| | | | | | | LoopControl -> LoopBounds
| | | | | | | | Scalar -> Name = 'i'
| | | | | | | | Scalar -> Expr = '1_4'
| | | | | | | | | LiteralConstant -> IntLiteralConstant = '1'
| | | | | | | | Scalar -> Expr = '2_4'
| | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | | Block
| | | | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt = 'a(2_8)=a(2_8)+i'
| | | | | | | | Variable = 'a(2_8)'
| | | | | | | | | Designator -> DataRef -> ArrayElement
| | | | | | | | | | DataRef -> Name = 'a'
| | | | | | | | | | SectionSubscript -> Integer -> Expr = '2_4'
| | | | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | | | | Expr = 'a(2_8)+i'
| | | | | | | | | Add
| | | | | | | | | | Expr = 'a(2_8)'
| | | | | | | | | | | Designator -> DataRef -> ArrayElement
| | | | | | | | | | | | DataRef -> Name = 'a'
| | | | | | | | | | | | SectionSubscript -> Integer -> Expr = '2_4'
| | | | | | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | | | | | | Expr = 'i'
| | | | | | | | | | | Designator -> DataRef -> Name = 'i'
| | | | | | EndDoStmt ->
| | | | | OmpEndLoopDirective
| | | | | | OmpLoopDirective -> llvm::omp::Directive = do
| | | | | | OmpClauseList ->
| | | | ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct // <- This should be an OpenMPLoopConstruct not a DoConstruct.
| | | | | NonLabelDoStmt
| | | | | | LoopControl -> LoopBounds
| | | | | | | Scalar -> Name = 'i'
| | | | | | | Scalar -> Expr = '1_4'
| | | | | | | | LiteralConstant -> IntLiteralConstant = '1'
| | | | | | | Scalar -> Expr = '5_4'
| | | | | | | | LiteralConstant -> IntLiteralConstant = '5'
| | | | | Block
| | | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt = 'b(2_8)=b(2_8)+1_4'
| | | | | | | Variable = 'b(2_8)'
| | | | | | | | Designator -> DataRef -> ArrayElement
| | | | | | | | | DataRef -> Name = 'b'
| | | | | | | | | SectionSubscript -> Integer -> Expr = '2_4'
| | | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | | | Expr = 'b(2_8)+1_4'
| | | | | | | | Add
| | | | | | | | | Expr = 'b(2_8)'
| | | | | | | | | | Designator -> DataRef -> ArrayElement
| | | | | | | | | | | DataRef -> Name = 'b'
| | | | | | | | | | | SectionSubscript -> Integer -> Expr = '2_4'
| | | | | | | | | | | | LiteralConstant -> IntLiteralConstant = '2'
| | | | | | | | | Expr = '1_4'
| | | | | | | | | | LiteralConstant -> IntLiteralConstant = '1'
| | | | | EndDoStmt ->
| | | EndSubroutineStmt ->
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsGV1v2zbw19AvRAKJsiLnwQ925AwB0rloiu2xoKSTzY4iBZJqk38_kLI-7FiO3djZgA2o0PC-v3h3lqjWbCUApiicozAe0cqspZo-mRfOIIqiUSKzl-mfaxCY4nupjKICl0quFC3wmmqcSqEhrQz7ATiWmEtZavyTmTVeliA-fcYZU5BatEbkDuecihVmGgtprJwUtGZihc0aepSY5gaUA-ZMaePEXlv9GJ5pUXKocZJz-dOybyxCwQx5M3Tjbf55M4x1lShZGSYAawfAmAkDK1DYkgczTBGZEERu92OTDmsJEPERGcuixJnECrIqNUwKjMgEkfmWtFZgJjHDKIixbyNANlDcUjpcdyBzzDY0IDKcSXfo9LbABn7AmOSwMaEF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