[flang-commits] [flang] fa61f06 - Fix threadprivate variable scope inside BLOCK construct. (#88921)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 17 02:51:49 PDT 2024


Author: harishch4
Date: 2024-04-17T15:21:45+05:30
New Revision: fa61f062a515be92a98cac64a9193498918c1225

URL: https://github.com/llvm/llvm-project/commit/fa61f062a515be92a98cac64a9193498918c1225
DIFF: https://github.com/llvm/llvm-project/commit/fa61f062a515be92a98cac64a9193498918c1225.diff

LOG: Fix threadprivate variable scope inside BLOCK construct. (#88921)

When a local variable inside a BLOCK construct is used as threadprivate
variable, llvm-flang throws below error:

> error: The THREADPRIVATE directive and the common block or variable in
it must appear in the same declaration section of a scoping unit

Added: 
    flang/test/Semantics/OpenMP/threadprivate07.f90

Modified: 
    flang/lib/Semantics/check-omp-structure.cpp
    flang/test/Lower/OpenMP/threadprivate-hlfir.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index e85d8d1f7ab533..bafa242a79302a 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1048,7 +1048,7 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
                       name->symbol->GetUltimate().owner();
                   if (!curScope.IsTopLevel()) {
                     const semantics::Scope &declScope =
-                        GetProgramUnitContaining(curScope);
+                        GetProgramUnitOrBlockConstructContaining(curScope);
                     const semantics::Symbol *sym{
                         declScope.parent().FindSymbol(name->symbol->name())};
                     if (sym &&

diff  --git a/flang/test/Lower/OpenMP/threadprivate-hlfir.f90 b/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
index d39ae1e7011838..7d02987c5eadee 100644
--- a/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
@@ -24,3 +24,4 @@ subroutine sub()
     print *, a
   !$omp end parallel
 end subroutine
+

diff  --git a/flang/test/Semantics/OpenMP/threadprivate07.f90 b/flang/test/Semantics/OpenMP/threadprivate07.f90
new file mode 100644
index 00000000000000..c9a006ca0e0839
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/threadprivate07.f90
@@ -0,0 +1,15 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+! Check Threadprivate Directive with local variable of a BLOCK construct.
+
+program main
+  call sub1()
+  print *, 'pass'
+end program main
+
+subroutine sub1()
+  BLOCK
+    integer, save :: a
+    !$omp threadprivate(a)
+  END BLOCK
+end subroutine


        


More information about the flang-commits mailing list