[flang-commits] [flang] 2a005bf - [Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (#109265)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 27 19:42:33 PDT 2024
Author: chandan singh
Date: 2024-09-28T08:12:29+05:30
New Revision: 2a005bff183c6c02004fa61a7bc5ec87d5d88ad3
URL: https://github.com/llvm/llvm-project/commit/2a005bff183c6c02004fa61a7bc5ec87d5d88ad3
DIFF: https://github.com/llvm/llvm-project/commit/2a005bff183c6c02004fa61a7bc5ec87d5d88ad3.diff
LOG: [Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (#109265)
Fixes issue https://github.com/llvm/llvm-project/issues/80399
Added:
flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 2943ee5dd75526..51341b3faf3a45 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1837,9 +1837,23 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
const Symbol &varSymbol = vSyms.front();
for (const Symbol &symbol : evaluate::GetSymbolVector(*e)) {
if (varSymbol == symbol) {
- context_.Say(expr.source,
- "RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
- var.GetSource().ToString());
+ const Fortran::common::Indirection<Fortran::parser::Designator>
+ *designator = std::get_if<
+ Fortran::common::Indirection<Fortran::parser::Designator>>(
+ &expr.u);
+ if (designator) {
+ auto *z{var.typedExpr.get()};
+ auto *c{expr.typedExpr.get()};
+ if (z->v == c->v) {
+ context_.Say(expr.source,
+ "RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
+ var.GetSource());
+ }
+ } else {
+ context_.Say(expr.source,
+ "RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
+ var.GetSource());
+ }
}
}
}
diff --git a/flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90 b/flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90
new file mode 100644
index 00000000000000..6469b1bfb78471
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90
@@ -0,0 +1,41 @@
+! RUN: %flang_fc1 -fopenmp %s -o -
+
+integer :: x, vv(2), xx(2)
+type t1
+ integer :: v,y,yy(2)
+end type t1
+type(t1)::t,tt(2)
+x=1
+xx=1
+vv=1
+t%y=1
+t%yy=1
+tt(1)%y=1
+tt(1)%yy=1
+tt(2)%v=1
+tt(2)%y=1
+tt(2)%yy=1
+
+!$omp atomic read
+ vv(1) = vv(2)
+!$omp atomic read
+ t%v = t%y
+!$omp atomic read
+ t%v = t%yy(1)
+!$omp atomic read
+ tt(1)%v = tt(1)%y
+!$omp atomic read
+ tt(1)%v = tt(2)%v
+!$omp atomic read
+ tt(1)%v = tt(1)%yy(1)
+!$omp atomic read
+ t%yy(2) = t%y
+!$omp atomic read
+ t%yy(2) = t%yy(1)
+!$omp atomic read
+ tt(1)%yy(2) = tt(1)%y
+!$omp atomic read
+ tt(1)%yy(2) = tt(1)%yy(1)
+!$omp atomic read
+ tt(1)%yy(2) = tt(2)%yy(2)
+end
More information about the flang-commits
mailing list