Skip to content

Commit fa61f06

Browse files
authored
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
1 parent 42d801d commit fa61f06

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
10481048
name->symbol->GetUltimate().owner();
10491049
if (!curScope.IsTopLevel()) {
10501050
const semantics::Scope &declScope =
1051-
GetProgramUnitContaining(curScope);
1051+
GetProgramUnitOrBlockConstructContaining(curScope);
10521052
const semantics::Symbol *sym{
10531053
declScope.parent().FindSymbol(name->symbol->name())};
10541054
if (sym &&

flang/test/Lower/OpenMP/threadprivate-hlfir.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ subroutine sub()
2424
print *, a
2525
!$omp end parallel
2626
end subroutine
27+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
! Check Threadprivate Directive with local variable of a BLOCK construct.
4+
5+
program main
6+
call sub1()
7+
print *, 'pass'
8+
end program main
9+
10+
subroutine sub1()
11+
BLOCK
12+
integer, save :: a
13+
!$omp threadprivate(a)
14+
END BLOCK
15+
end subroutine

0 commit comments

Comments
 (0)