Skip to content

Commit 742d8eb

Browse files
[Flang][OpenMP] Dont add PreDetermined Flag if symbol is privatized already (#70931)
If the symbol is already privatized due to a user specification then it is not required to mark it as PreDetermined. This happens if there is a sequential loop in a parallel region that has the private specification for the index of the sequential loop. Fixes #63143
1 parent 5fc6913 commit 742d8eb

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
15211521

15221522
void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
15231523
const parser::Name &iv) {
1524+
// Find the parallel or task generating construct enclosing the
1525+
// sequential loop.
15241526
auto targetIt{dirContext_.rbegin()};
15251527
for (;; ++targetIt) {
15261528
if (targetIt == dirContext_.rend()) {
@@ -1531,12 +1533,21 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
15311533
break;
15321534
}
15331535
}
1536+
// If this symbol is already Private or Firstprivate in the enclosing
1537+
// OpenMP parallel or task then there is nothing to do here.
1538+
if (auto *symbol{targetIt->scope.FindSymbol(iv.source)}) {
1539+
if (symbol->owner() == targetIt->scope) {
1540+
if (symbol->test(Symbol::Flag::OmpPrivate) ||
1541+
symbol->test(Symbol::Flag::OmpFirstPrivate)) {
1542+
return;
1543+
}
1544+
}
1545+
}
1546+
// Otherwise find the symbol and make it Private for the entire enclosing
1547+
// parallel or task
15341548
if (auto *symbol{ResolveOmp(iv, Symbol::Flag::OmpPrivate, targetIt->scope)}) {
15351549
targetIt++;
1536-
// If this object already had a DSA then it is not predetermined
1537-
if (!IsObjectWithDSA(*symbol)) {
1538-
symbol->set(Symbol::Flag::OmpPreDetermined);
1539-
}
1550+
symbol->set(Symbol::Flag::OmpPreDetermined);
15401551
iv.symbol = symbol; // adjust the symbol within region
15411552
for (auto it{dirContext_.rbegin()}; it != targetIt; ++it) {
15421553
AddToContextObjectWithDSA(*symbol, Symbol::Flag::OmpPrivate, *it);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
2+
3+
! Generic tests
4+
! 1. subroutine or function calls should not be fixed for DSA or DMA
5+
6+
!DEF: /foo (Function) Subprogram REAL(4)
7+
!DEF: /foo/rnum ObjectEntity REAL(4)
8+
function foo(rnum)
9+
!REF: /foo/rnum
10+
real rnum
11+
!REF: /foo/rnum
12+
rnum = rnum+1.
13+
end function foo
14+
!DEF: /function_call_in_region EXTERNAL (Subroutine) Subprogram
15+
subroutine function_call_in_region
16+
implicit none
17+
!DEF: /function_call_in_region/foo (Function) ProcEntity REAL(4)
18+
real foo
19+
!DEF: /function_call_in_region/a ObjectEntity REAL(4)
20+
real :: a = 0.
21+
!DEF: /function_call_in_region/b ObjectEntity REAL(4)
22+
real :: b = 5.
23+
!$omp parallel default(none) private(a) shared(b)
24+
!DEF: /function_call_in_region/OtherConstruct1/a (OmpPrivate) HostAssoc REAL(4)
25+
!REF: /function_call_in_region/foo
26+
!REF: /function_call_in_region/b
27+
a = foo(b)
28+
!$omp end parallel
29+
!REF: /function_call_in_region/a
30+
!REF: /function_call_in_region/b
31+
print *, a, b
32+
end subroutine function_call_in_region
33+
!DEF: /mm MainProgram
34+
program mm
35+
!REF: /function_call_in_region
36+
call function_call_in_region
37+
end program mm

0 commit comments

Comments
 (0)