Skip to content

Commit

Permalink
[Flang][OpenMP] Fix for error in atomic read for different elements o…
Browse files Browse the repository at this point in the history
…f the common symbol #80399 (#109265)

Fixes issue #80399
  • Loading branch information
chandankds authored Sep 28, 2024
1 parent cca3217 commit 2a005bf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
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 @@ -1837,9 +1837,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

0 comments on commit 2a005bf

Please sign in to comment.