Skip to content

[Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 #109265

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

Merged
merged 4 commits into from
Sep 28, 2024

Conversation

chandankds
Copy link
Contributor

Fixes issue #80399

@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2024

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: chandan singh (chandankds)

Changes

Fixes issue #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 --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

@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some issues with using the front symbol of the SymbolVector in #108516 (review). Could you check whether it is OK here?

Some of the other comments in #108516 apply here as well regarding ToString() not required in the error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this unnecessary change and also confirmed front symbol of the SymbolVector is working as expected in this case.

Comment on lines 1811 to 1813
"RHS expression "
"on atomic assignment statement"
" cannot access '%s'"_err_en_US,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this in a single line so that it is easy to search for error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 1818 to 1820
"RHS expression "
"on atomic assignment statement"
" cannot access '%s'"_err_en_US,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this in a single line so that it is easy to search for error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tt(1)%yy(2) = tt(1)%yy(1)
!$omp atomic read
tt(1)%yy(2) = tt(2)%yy(2)
!CHECK: pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this CHECK intended to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unnecessary check

@@ -0,0 +1,43 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not testing for any errors here, I think you are just testing that flang will compiler this file correctly. Using the test_errors.py script is incorrect because it allows flang to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed usage of test_errors.py from the test case.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@chandankds chandankds merged commit 2a005bf into llvm:main Sep 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants