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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,9 +1800,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());
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt-read.f90
Original file line number Diff line number Diff line change
@@ -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
Loading