Skip to content

[flang][OpenMP] Catch threadprivate common block vars that appear in equivalence #127642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,20 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
}
}
},
[&](const parser::Name &) {}, // common block
[&](const parser::Name &name) {
if (name.symbol) {
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);
}
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Semantics/OpenMP/threadprivate02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down