[flang-commits] [flang] [flang][OpenMP] Catch threadprivate common block vars that appear in equivalence (PR #127642)

via flang-commits flang-commits at lists.llvm.org
Tue Feb 18 06:39:07 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Leandro Lupori (luporl)

<details>
<summary>Changes</summary>

Semantics were not checking for variables appearing in equivalence
statements when those were part of a threadprivate common block.

Fixes #<!-- -->122825


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


2 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+16-1) 
- (modified) flang/test/Semantics/OpenMP/threadprivate02.f90 (+6) 


``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index fd2893998205c..62de902726c8b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1479,7 +1479,22 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
                 }
               }
             },
-            [&](const parser::Name &) {}, // common block
+            [&](const parser::Name &name) {
+              if (!name.symbol) {
+                return;
+              }
+              if (auto *cb{name.symbol->detailsIf<CommonBlockDetails>()}) {
+                for (const auto &obj : cb->objects()) {
+                  if (FindEquivalenceSet(*obj)) {
+                    context_.Say(name.source,
+                        "A variable in a %s directive cannot appear in an EQUIVALENCE statement"
+                        " (variable '%s' from common block '/%s/')"_err_en_US,
+                        ContextDirectiveAsFortran(), obj->name(),
+                        name.symbol->name());
+                  }
+                }
+              }
+            },
         },
         ompObject.u);
   }
diff --git a/flang/test/Semantics/OpenMP/threadprivate02.f90 b/flang/test/Semantics/OpenMP/threadprivate02.f90
index 7f6e8dcc8e8ab..9dc031a8ce47e 100644
--- a/flang/test/Semantics/OpenMP/threadprivate02.f90
+++ b/flang/test/Semantics/OpenMP/threadprivate02.f90
@@ -7,6 +7,9 @@ program threadprivate02
   integer :: arr1(10)
   common /blk1/ a1
   real, save :: eq_a, eq_b, eq_c, eq_d
+  integer :: eq_e, eq_f
+  equivalence(eq_e, eq_f)
+  common /blk2/ eq_e
 
   !$omp threadprivate(arr1)
 
@@ -25,6 +28,9 @@ program threadprivate02
   !$omp threadprivate(eq_c)
   equivalence(eq_c, eq_d)
 
+  !ERROR: A variable in a THREADPRIVATE directive cannot appear in an EQUIVALENCE statement (variable 'eq_e' from common block '/blk2/')
+  !$omp threadprivate(/blk2/)
+
 contains
   subroutine func()
     integer :: arr2(10)

``````````

</details>


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


More information about the flang-commits mailing list