[flang-commits] [flang] [Flang][OpenMP] Issue error if reduction clause has proc-pointer (PR #88999)

via flang-commits flang-commits at lists.llvm.org
Tue Apr 16 15:55:20 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

<details>
<summary>Changes</summary>

OpenMP 5.2: Section 5.5.5: A procedure pointer must not appear in a reduction clause.

Fixes #<!-- -->87915

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


2 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+12) 
- (added) flang/test/Semantics/OpenMP/reduction12.f90 (+16) 


``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index e85d8d1f7ab533..ec853de4b5ca74 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2285,7 +2285,19 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
   if (CheckReductionOperators(x)) {
     CheckReductionTypeList(x);
   }
+
+  SymbolSourceMap symbols;
+  const auto &ompObjectList{std::get<parser::OmpObjectList>(x.v.t)};
+  GetSymbolsInObjectList(ompObjectList, symbols);
+  for (auto &[symbol, source] : symbols) {
+    if (IsProcedurePointer(*symbol)) {
+      context_.Say(source,
+          "A procedure pointer '%s' must not appear in a REDUCTION clause."_err_en_US,
+          symbol->name());
+    }
+  }
 }
+
 bool OmpStructureChecker::CheckReductionOperators(
     const parser::OmpClause::Reduction &x) {
 
diff --git a/flang/test/Semantics/OpenMP/reduction12.f90 b/flang/test/Semantics/OpenMP/reduction12.f90
new file mode 100644
index 00000000000000..f896ca4aa60b67
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/reduction12.f90
@@ -0,0 +1,16 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+! OpenMP 5.2: Section 5.5.5 : A procedure pointer must not appear in a
+! reduction clause.
+
+  procedure(foo), pointer :: ptr
+  integer :: i
+  ptr => foo
+!ERROR: A procedure pointer 'ptr' must not appear in a REDUCTION clause.
+!$omp do reduction (+ : ptr)
+  do i = 1, 10
+  end do
+contains
+  subroutine foo
+  end subroutine
+end

``````````

</details>


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


More information about the flang-commits mailing list