-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
…f the common symbol llvm#80399 Fixes issue llvm#80399
@llvm/pr-subscribers-flang-openmp @llvm/pr-subscribers-flang-semantics Author: chandan singh (chandankds) ChangesFixes issue #80399 Full diff: https://github.com/llvm/llvm-project/pull/109265.diff 2 Files Affected:
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(); |
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.
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.
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.
Reverted this unnecessary change and also confirmed front symbol of the SymbolVector is working as expected in this case.
"RHS expression " | ||
"on atomic assignment statement" | ||
" cannot access '%s'"_err_en_US, |
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.
Can we have this in a single line so that it is easy to search for error messages?
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.
Done
"RHS expression " | ||
"on atomic assignment statement" | ||
" cannot access '%s'"_err_en_US, |
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.
Can we have this in a single line so that it is easy to search for error messages?
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.
Done
tt(1)%yy(2) = tt(1)%yy(1) | ||
!$omp atomic read | ||
tt(1)%yy(2) = tt(2)%yy(2) | ||
!CHECK: pass |
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.
What is this CHECK intended to do?
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.
Removed unnecessary check
@@ -0,0 +1,43 @@ | |||
! RUN: %python %S/../test_errors.py %s %flang -fopenmp |
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.
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.
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.
Removed usage of test_errors.py from the test case.
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.
LGTM.
Fixes issue #80399