-
Notifications
You must be signed in to change notification settings - Fork 14k
[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
Conversation
…equivalence Semantics were not checking for variables appearing in equivalence statements when those were part of a threadprivate common block. Fixes llvm#122825
@llvm/pr-subscribers-flang-semantics Author: Leandro Lupori (luporl) ChangesSemantics were not checking for variables appearing in equivalence Fixes #122825 Full diff: https://github.com/llvm/llvm-project/pull/127642.diff 2 Files Affected:
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<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);
}
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)
|
@llvm/pr-subscribers-flang-openmp Author: Leandro Lupori (luporl) ChangesSemantics were not checking for variables appearing in equivalence Fixes #122825 Full diff: https://github.com/llvm/llvm-project/pull/127642.diff 2 Files Affected:
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<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);
}
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)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
The clang-format issue is caused by not breaking up the error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clang-format issue is caused by not breaking up the error message.
Will putting it in a single line help. Having the error message in a single line makes it easier to search for it in the code base.
It helped, clang-format didn't complain with the error message in a single line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG. Thanks @luporl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Hi @luporl , I think this change caused fujitsu tests 0685 0685_0007.f90 to change behavior. Before, it was compiling, executing, and matching the expected output. Now, there's a compile-time error:
I am not an expert in OpenMP semantics. Shall we update the test's expected output? |
I think @luporl is basing the change of this PR on the following points from the standard.
I see that gfortran also adopts this interpretation. But ifx and classic flang/nvfortran do not and allow the usage in https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0685/0685_0007.f90 |
@kiranchandramohan I agree. The idea is that |
Semantics were not checking for variables appearing in equivalence
statements when those were part of a threadprivate common block.
Fixes #122825