Skip to content

Commit 2a005bf

Browse files
authored
[Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (#109265)
Fixes issue #80399
1 parent cca3217 commit 2a005bf

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,9 +1837,23 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
18371837
const Symbol &varSymbol = vSyms.front();
18381838
for (const Symbol &symbol : evaluate::GetSymbolVector(*e)) {
18391839
if (varSymbol == symbol) {
1840-
context_.Say(expr.source,
1841-
"RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
1842-
var.GetSource().ToString());
1840+
const Fortran::common::Indirection<Fortran::parser::Designator>
1841+
*designator = std::get_if<
1842+
Fortran::common::Indirection<Fortran::parser::Designator>>(
1843+
&expr.u);
1844+
if (designator) {
1845+
auto *z{var.typedExpr.get()};
1846+
auto *c{expr.typedExpr.get()};
1847+
if (z->v == c->v) {
1848+
context_.Say(expr.source,
1849+
"RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
1850+
var.GetSource());
1851+
}
1852+
} else {
1853+
context_.Say(expr.source,
1854+
"RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
1855+
var.GetSource());
1856+
}
18431857
}
18441858
}
18451859
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
! RUN: %flang_fc1 -fopenmp %s -o -
2+
3+
integer :: x, vv(2), xx(2)
4+
type t1
5+
integer :: v,y,yy(2)
6+
end type t1
7+
type(t1)::t,tt(2)
8+
x=1
9+
xx=1
10+
vv=1
11+
t%y=1
12+
t%yy=1
13+
tt(1)%y=1
14+
tt(1)%yy=1
15+
tt(2)%v=1
16+
tt(2)%y=1
17+
tt(2)%yy=1
18+
19+
!$omp atomic read
20+
vv(1) = vv(2)
21+
!$omp atomic read
22+
t%v = t%y
23+
!$omp atomic read
24+
t%v = t%yy(1)
25+
!$omp atomic read
26+
tt(1)%v = tt(1)%y
27+
!$omp atomic read
28+
tt(1)%v = tt(2)%v
29+
!$omp atomic read
30+
tt(1)%v = tt(1)%yy(1)
31+
!$omp atomic read
32+
t%yy(2) = t%y
33+
!$omp atomic read
34+
t%yy(2) = t%yy(1)
35+
!$omp atomic read
36+
tt(1)%yy(2) = tt(1)%y
37+
!$omp atomic read
38+
tt(1)%yy(2) = tt(1)%yy(1)
39+
!$omp atomic read
40+
tt(1)%yy(2) = tt(2)%yy(2)
41+
end

0 commit comments

Comments
 (0)