[flang-commits] [flang] [Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (PR #109265)

chandan singh via flang-commits flang-commits at lists.llvm.org
Thu Sep 19 05:57:22 PDT 2024


https://github.com/chandankds updated https://github.com/llvm/llvm-project/pull/109265

>From 9545773a9d865e8625f4134fe8f9e9430e82372b Mon Sep 17 00:00:00 2001
From: chandan singh <chandankds at gmail.com>
Date: Thu, 19 Sep 2024 15:58:55 +0530
Subject: [PATCH 1/2] [Flang][OpenMP] Fix for error in atomic read for
 different elements of the common symbol #80399

Fixes issue https://github.com/llvm/llvm-project/issues/80399
---
 flang/lib/Semantics/check-omp-structure.cpp   | 27 +++++++++---
 .../omp-atomic-assignment-stmt-read.f90       | 43 +++++++++++++++++++
 2 files changed, 65 insertions(+), 5 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90

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

>From 0585aa7392a79b216bd030da255df87609e374d2 Mon Sep 17 00:00:00 2001
From: chandan singh <chandankds at gmail.com>
Date: Thu, 19 Sep 2024 18:26:36 +0530
Subject: [PATCH 2/2] addressed changes related to code formatting

---
 flang/lib/Semantics/check-omp-structure.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index e90c8d2bdb3a46..24de5242a0cd08 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1808,17 +1808,13 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
           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());
+                "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().ToString());
+              "RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
+              var.GetSource());
         }
       }
     }



More information about the flang-commits mailing list