From 1cbe00da9e987394bc414253df9c7c434c4a9837 Mon Sep 17 00:00:00 2001 From: Leandro Lupori Date: Tue, 18 Feb 2025 11:10:49 -0300 Subject: [PATCH 1/2] [flang][OpenMP] Catch threadprivate common block vars that appear in equivalence Semantics were not checking for variables appearing in equivalence statements when those were part of a threadprivate common block. Fixes #122825 --- flang/lib/Semantics/check-omp-structure.cpp | 17 ++++++++++++++++- flang/test/Semantics/OpenMP/threadprivate02.f90 | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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()}) { + 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) From b9c55a2494936b0babc2d9ef1180053abc06c2c4 Mon Sep 17 00:00:00 2001 From: Leandro Lupori Date: Wed, 19 Feb 2025 09:53:05 -0300 Subject: [PATCH 2/2] Fix style and format --- flang/lib/Semantics/check-omp-structure.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 62de902726c8b..1c4d9d7ac01d8 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -1480,17 +1480,15 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar( } }, [&](const parser::Name &name) { - if (!name.symbol) { - return; - } - if (auto *cb{name.symbol->detailsIf()}) { - 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()); + if (name.symbol) { + if (auto *cb{name.symbol->detailsIf()}) { + 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()); + } } } }