[flang-commits] [flang] [Flang][OpenMP] Parse and semantically analyze common blocks in map clauses correctly (PR #89847)

via flang-commits flang-commits at lists.llvm.org
Tue Apr 23 16:57:28 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: None (agozillon)

<details>
<summary>Changes</summary>

Currently, you cannot provide the common block syntax that you should be able to provide for map clauses (and that you can for declare target) e.g.:

` !$omp target map(tofrom: /var/)`

This PR seeks to change that and allow this syntax via a small tweak, which may also allow a wider range of types to be provided without issue as well via the utilisation of ResolveOmpObject a helper function used by the majority of other OmpObject handling clauses.

A by product of this change, is that we now emit an error for the following syntax, when provided to map clauses with an assumed size array:

`!$omp target map(arr(:))`

This seems inline with the specification from what I understand of it (do feel free to correct me if that is not your reading or I am incorrect!) and other OpenMP compilers i.e. gfortran, ifx, ifort.

---
Full diff: https://github.com/llvm/llvm-project/pull/89847.diff


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+2) 
- (modified) flang/test/Semantics/OpenMP/map-clause.f90 (+10-1) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 318687508ff1f5..c99b1c413970ef 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -633,6 +633,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
               [&](const auto &name) {},
           },
           ompObj.u);
+
+      ResolveOmpObject(ompObj, ompFlag);
     }
   }
 
diff --git a/flang/test/Semantics/OpenMP/map-clause.f90 b/flang/test/Semantics/OpenMP/map-clause.f90
index b46b2550b04eda..a7430c3edeb949 100644
--- a/flang/test/Semantics/OpenMP/map-clause.f90
+++ b/flang/test/Semantics/OpenMP/map-clause.f90
@@ -2,9 +2,12 @@
 ! 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
@@ -12,6 +15,7 @@ subroutine sb(arr)
   enddo
   !$omp end target
 
+  !ERROR: Assumed-size array 'arr' must have explicit final subscript upper bound value
   !$omp target map(arr(:))
   do i = 1, 100
      a = 3.14
@@ -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

``````````

</details>


https://github.com/llvm/llvm-project/pull/89847


More information about the flang-commits mailing list