Skip to content

Commit d7784a6

Browse files
authored
[flang][OpenMP] Catch threadprivate common block vars that appear in equivalence (#127642)
Semantics were not checking for variables appearing in equivalence statements when those were part of a threadprivate common block. Fixes #122825
1 parent 367ecc6 commit d7784a6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,20 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
14771477
}
14781478
}
14791479
},
1480-
[&](const parser::Name &) {}, // common block
1480+
[&](const parser::Name &name) {
1481+
if (name.symbol) {
1482+
if (auto *cb{name.symbol->detailsIf<CommonBlockDetails>()}) {
1483+
for (const auto &obj : cb->objects()) {
1484+
if (FindEquivalenceSet(*obj)) {
1485+
context_.Say(name.source,
1486+
"A variable in a %s directive cannot appear in an EQUIVALENCE statement (variable '%s' from common block '/%s/')"_err_en_US,
1487+
ContextDirectiveAsFortran(), obj->name(),
1488+
name.symbol->name());
1489+
}
1490+
}
1491+
}
1492+
}
1493+
},
14811494
},
14821495
ompObject.u);
14831496
}

flang/test/Semantics/OpenMP/threadprivate02.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ program threadprivate02
77
integer :: arr1(10)
88
common /blk1/ a1
99
real, save :: eq_a, eq_b, eq_c, eq_d
10+
integer :: eq_e, eq_f
11+
equivalence(eq_e, eq_f)
12+
common /blk2/ eq_e
1013

1114
!$omp threadprivate(arr1)
1215

@@ -25,6 +28,9 @@ program threadprivate02
2528
!$omp threadprivate(eq_c)
2629
equivalence(eq_c, eq_d)
2730

31+
!ERROR: A variable in a THREADPRIVATE directive cannot appear in an EQUIVALENCE statement (variable 'eq_e' from common block '/blk2/')
32+
!$omp threadprivate(/blk2/)
33+
2834
contains
2935
subroutine func()
3036
integer :: arr2(10)

0 commit comments

Comments
 (0)