Skip to content

[Flang][OpenMP] Parse and semantically analyze common blocks in map clauses correctly #89847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
[&](const auto &name) {},
},
ompObj.u);

ResolveOmpObject(ompObj, ompFlag);
}
}

Expand Down
11 changes: 10 additions & 1 deletion flang/test/Semantics/OpenMP/map-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
! Check OpenMP MAP clause validity. Section 5.8.3 OpenMP 5.2.

subroutine sb(arr)
implicit none
real(8) :: arr(*)
real :: a

integer:: b, c, i
common /var/ b, c

!ERROR: Assumed-size whole arrays may not appear on the MAP clause
!$omp target map(arr)
do i = 1, 100
a = 3.14
enddo
!$omp end target

!ERROR: Assumed-size array 'arr' must have explicit final subscript upper bound value
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying ping for you @mjklemm I think it's correct for us to emit an error in this case (OpenMP section syntax falls-back on fortran rules from my understanding and we also have the following OpenMP line: "The upper bound for the last dimension of an assumed-size dummy array must be specified", which I think covers this case but my Fortran and OpenMP knowledge is admittedly lacking), but just incase I thought I'd pester you for a double check!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F2023 C930: "The second subscript shall not be omitted from a subscript-triplet in the last dimension of an assumed-size array."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F2023 C930: "The second subscript shall not be omitted from a subscript-triplet in the last dimension of an assumed-size array."

Would it fall into any other ruling (my appologies I don't have access to a Fortran specification document in this case) as this seems to also be emitted elsewhere for regular Fortran e.g.:

subroutine s6(x)
  integer :: x(*)
!ERROR: Assumed-size array 'x' must have explicit final subscript upper bound value
  x(:) = [1, 2, 3]
end

And if not, does the OpenMP ruling apply in this case (e.g. "The upper bound for the last dimension of an assumed-size dummy array must be specified")?

Or is this syntax perfectly legal and should be supported by the compiler (even if other compilers seem to error out on it, although, considering they also seem to not be too friendly to the common block syntax, that might not be the best way to judge things)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, the OpenMP array section syntax does not extend any Fortran array section syntax. The OpenMP spec only restricts where (clause or directive) the array section can appear. So I think the restriction,

"The second subscript shall not be omitted from a subscript-triplet in the last dimension of an assumed-size array."

is repeating C930. I will double check on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @kkwli ! Just not wanting to accidentally increase restrictions incorrectly if it's avoidable.

!$omp target map(arr(:))
do i = 1, 100
a = 3.14
Expand All @@ -23,4 +27,9 @@ subroutine sb(arr)
a = 3.14
enddo
!$omp end target

!$omp target map(tofrom: /var/)
b = 1
c = 2
!$omp end target
end subroutine