[flang-commits] [flang] [Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (PR #109265)
via flang-commits
flang-commits at lists.llvm.org
Thu Sep 19 03:34:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: chandan singh (chandankds)
<details>
<summary>Changes</summary>
Fixes issue https://github.com/llvm/llvm-project/issues/80399
---
Full diff: https://github.com/llvm/llvm-project/pull/109265.diff
2 Files Affected:
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+22-5)
- (added) flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90 (+43)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 643b713b32e29d..e90c8d2bdb3a46 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1796,13 +1796,30 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
const auto *e{GetExpr(context_, expr)};
const auto *v{GetExpr(context_, var)};
if (e && v) {
- auto vSyms{evaluate::GetSymbolVector(*v)};
- const Symbol &varSymbol = vSyms.front();
+ const Symbol &varSymbol = evaluate::GetSymbolVector(*v).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().ToString());
+ }
+ } else {
+ context_.Say(expr.source,
+ "RHS expression "
+ "on atomic assignment statement"
+ " cannot access '%s'"_err_en_US,
+ var.GetSource().ToString());
+ }
}
}
}
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..2c8db296fc312e
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90
@@ -0,0 +1,43 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+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)
+!CHECK: pass
+print *,'pass'
+end
``````````
</details>
https://github.com/llvm/llvm-project/pull/109265
More information about the flang-commits
mailing list