Skip to content

Commit 6a2676f

Browse files
committed
Rework to cover all the required scenarios, expand tests
1 parent 0b40d02 commit 6a2676f

File tree

10 files changed

+78
-27
lines changed

10 files changed

+78
-27
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ class Symbol {
756756
LocalityShared, // named in SHARED locality-spec
757757
InDataStmt, // initialized in a DATA statement, =>object, or /init/
758758
InNamelist, // in a Namelist group
759+
InCommonBlock, // referenced in a common block
759760
EntryDummyArgument,
760761
CompilerCreated, // A compiler created symbol
761762
// For compiler created symbols that are constant but cannot legally have

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,20 @@ static bool IsPrivatizable(const Symbol *sym) {
22172217
misc->kind() != MiscDetails::Kind::ConstructName));
22182218
}
22192219

2220+
static bool IsSymbolStaticStorageDuration(const Symbol &symbol) {
2221+
LLVM_DEBUG(llvm::dbgs() << "IsSymbolStaticStorageDuration(" << symbol.name()
2222+
<< "):\n");
2223+
auto ultSym = symbol.GetUltimate();
2224+
// Module-scope variable
2225+
return (ultSym.owner().kind() == Scope::Kind::Module) ||
2226+
// Data statement variable
2227+
(ultSym.flags().test(Symbol::Flag::InDataStmt)) ||
2228+
// Save attribute variable
2229+
(ultSym.attrs().test(Attr::SAVE)) ||
2230+
// Referenced in a common block
2231+
(ultSym.flags().test(Symbol::Flag::InCommonBlock));
2232+
}
2233+
22202234
void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
22212235
if (!IsPrivatizable(symbol)) {
22222236
return;
@@ -2310,8 +2324,7 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
23102324
bool targetDir = llvm::omp::allTargetSet.test(dirContext.directive);
23112325
bool parallelDir = llvm::omp::allParallelSet.test(dirContext.directive);
23122326
bool teamsDir = llvm::omp::allTeamsSet.test(dirContext.directive);
2313-
bool isStaticStorageDuration =
2314-
symbol->flags().test(Symbol::Flag::InDataStmt);
2327+
bool isStaticStorageDuration = IsSymbolStaticStorageDuration(*symbol);
23152328

23162329
if (dsa.any()) {
23172330
if (parallelDir || taskGenDir || teamsDir) {
@@ -2369,21 +2382,16 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
23692382
dsa = prevDSA;
23702383
} else if (taskGenDir) {
23712384
// TODO 5) dummy arg in orphaned taskgen construct -> firstprivate
2372-
if (prevDSA.test(Symbol::Flag::OmpShared)) {
2385+
if (prevDSA.test(Symbol::Flag::OmpShared) || isStaticStorageDuration) {
23732386
// 6) shared in enclosing context -> shared
23742387
dsa = {Symbol::Flag::OmpShared};
23752388
makeSymbol(dsa);
23762389
PRINT_IMPLICIT_RULE("6) taskgen: shared");
2377-
} else if (isStaticStorageDuration) {
2378-
// 7) variables with static storage duration are predetermined as shared
2379-
dsa = {Symbol::Flag::OmpShared};
2380-
makeSymbol(dsa);
2381-
PRINT_IMPLICIT_RULE("7) taskgen: shared (static storage duration)");
23822390
} else {
2383-
// 8) firstprivate
2391+
// 7) firstprivate
23842392
dsa = {Symbol::Flag::OmpFirstPrivate};
23852393
makeSymbol(dsa)->set(Symbol::Flag::OmpImplicit);
2386-
PRINT_IMPLICIT_RULE("8) taskgen: firstprivate");
2394+
PRINT_IMPLICIT_RULE("7) taskgen: firstprivate");
23872395
}
23882396
}
23892397
prevDSA = dsa;

flang/lib/Semantics/resolve-names.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,6 +6820,9 @@ bool DeclarationVisitor::Pre(const parser::CommonBlockObject &) {
68206820

68216821
void DeclarationVisitor::Post(const parser::CommonBlockObject &x) {
68226822
const auto &name{std::get<parser::Name>(x.t)};
6823+
if (auto *symbol{FindSymbol(name)}) {
6824+
symbol->set(Symbol::Flag::InCommonBlock);
6825+
}
68236826
DeclareObjectEntity(name);
68246827
auto pair{specPartState_.commonBlockObjects.insert(name.source)};
68256828
if (!pair.second) {

flang/test/Semantics/OpenMP/common-block.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
22

33
program main
4-
!CHECK: a size=4 offset=0: ObjectEntity type: REAL(4)
5-
!CHECK: b size=8 offset=4: ObjectEntity type: INTEGER(4) shape: 1_8:2_8
6-
!CHECK: c size=4 offset=12: ObjectEntity type: REAL(4)
4+
!CHECK: a (InCommonBlock) size=4 offset=0: ObjectEntity type: REAL(4)
5+
!CHECK: b (InCommonBlock) size=8 offset=4: ObjectEntity type: INTEGER(4) shape: 1_8:2_8
6+
!CHECK: c (InCommonBlock) size=4 offset=12: ObjectEntity type: REAL(4)
77
!CHECK: blk size=16 offset=0: CommonBlockDetails alignment=4: a b c
88
real :: a, c
99
integer :: b(2)

flang/test/Semantics/OpenMP/declare-target-common-block.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
22

33
PROGRAM main
4-
!CHECK: one (OmpDeclareTarget) size=4 offset=0: ObjectEntity type: REAL(4)
5-
!CHECK: two (OmpDeclareTarget) size=4 offset=4: ObjectEntity type: REAL(4)
4+
!CHECK: one (InCommonBlock, OmpDeclareTarget) size=4 offset=0: ObjectEntity type: REAL(4)
5+
!CHECK: two (InCommonBlock, OmpDeclareTarget) size=4 offset=4: ObjectEntity type: REAL(4)
66
!CHECK: numbers size=8 offset=0: CommonBlockDetails alignment=4: one two
77
REAL :: one, two
88
COMMON /numbers/ one, two

flang/test/Semantics/OpenMP/implicit-dsa.f90

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ subroutine implicit_dsa_test8
175175
module implicit_dsa_test9_mod
176176
!DEF: /implicit_dsa_test9_mod/tm3a PUBLIC (InDataStmt) ObjectEntity COMPLEX(4)
177177
complex tm3a/(0,0)/
178+
!DEF: /implicit_dsa_test9_mod/tm4a PUBLIC ObjectEntity COMPLEX(4)
179+
complex tm4a
178180
contains
179181
!DEF: /implicit_dsa_test9_mod/implict_dsa_test9 PUBLIC (Subroutine) Subprogram
180182
subroutine implict_dsa_test9
181183
!$omp task
182184
!$omp task
183185
!DEF: /implicit_dsa_test9_mod/implict_dsa_test9/OtherConstruct1/OtherConstruct1/tm3a (OmpShared) HostAssoc COMPLEX(4)
184186
tm3a = (1, 2)
187+
!DEF: /implicit_dsa_test9_mod/implict_dsa_test9/OtherConstruct1/OtherConstruct1/tm4a (OmpShared) HostAssoc COMPLEX(4)
188+
tm4a = (3, 4)
185189
!$omp end task
186190
!$omp end task
187191
!$omp taskwait
@@ -194,14 +198,49 @@ subroutine implict_dsa_test9
194198
!DEF: /implicit_dsa_test10 (Subroutine) Subprogram
195199
subroutine implicit_dsa_test10
196200
!DEF: /implicit_dsa_test10/tm3a (Implicit, InDataStmt) ObjectEntity REAL(4)
197-
data tm3a /(0, 2)/
201+
data tm3a /3/
198202
!$omp task
199203
!$omp task
200204
!DEF: /implicit_dsa_test10/OtherConstruct1/OtherConstruct1/tm3a (OmpShared) HostAssoc REAL(4)
201-
tm3a = (1, 2)
205+
tm3a = 5
202206
!$omp end task
203207
!$omp end task
204208
!$omp taskwait
205209
!REF: /implicit_dsa_test10/tm3a
206210
print *,tm3a
207211
end subroutine
212+
213+
! Test variables with the SAVE attrtibute default to shared DSA
214+
!DEF: /implicit_dsa_test_11 (Subroutine) Subprogram
215+
subroutine implicit_dsa_test_11
216+
!DEF: /implicit_dsa_test_11/tm3a SAVE ObjectEntity COMPLEX(4)
217+
complex, save :: tm3a
218+
!$omp task
219+
!$omp task
220+
!DEF: /implicit_dsa_test_11/OtherConstruct1/OtherConstruct1/tm3a (OmpShared) HostAssoc COMPLEX(4)
221+
tm3a = (1, 2)
222+
!$omp end task
223+
!$omp end task
224+
!$omp taskwait
225+
!REF: /implicit_dsa_test_11/tm3a
226+
print *,tm3a
227+
end subroutine
228+
229+
! Test variables referenced in a common block default to shared DSA
230+
!DEF: /implicit_dsa_test_12 (Subroutine) Subprogram
231+
subroutine implicit_dsa_test_12
232+
!DEF: /implicit_dsa_test_12/tm3a (InCommonBlock) ObjectEntity COMPLEX(4)
233+
complex tm3a
234+
!DEF: /implicit_dsa_test_12/tcom CommonBlockDetails
235+
!REF: /implicit_dsa_test_12/tm3a
236+
common /tcom/ tm3a
237+
!$omp task
238+
!$omp task
239+
!DEF: /implicit_dsa_test_12/OtherConstruct1/OtherConstruct1/tm3a (OmpShared) HostAssoc COMPLEX(4)
240+
tm3a = (1, 2)
241+
!$omp end task
242+
!$omp end task
243+
!$omp taskwait
244+
!REF: /implicit_dsa_test_12/tm3a
245+
print *,tm3a
246+
end subroutine

flang/test/Semantics/OpenMP/symbol01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ program mm
2121
!REF: /md
2222
use :: md
2323
!DEF: /mm/c CommonBlockDetails
24-
!DEF: /mm/x ObjectEntity REAL(4)
25-
!DEF: /mm/y ObjectEntity REAL(4)
24+
!DEF: /mm/x (InCommonBlock) ObjectEntity REAL(4)
25+
!DEF: /mm/y (InCommonBlock) ObjectEntity REAL(4)
2626
common /c/x, y
2727
!REF: /mm/x
2828
!REF: /mm/y

flang/test/Semantics/offsets03.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ subroutine mc !CHECK: Subprogram scope: mc size=12 alignment=1
3030
! Common block: objects are in order from COMMON statement and not part of module
3131
module md !CHECK: Module scope: md size=1 alignment=1
3232
integer(1) :: i
33-
integer(2) :: d1 !CHECK: d1, PUBLIC size=2 offset=8:
34-
integer(4) :: d2 !CHECK: d2, PUBLIC size=4 offset=4:
35-
integer(1) :: d3 !CHECK: d3, PUBLIC size=1 offset=0:
36-
real(2) :: d4 !CHECK: d4, PUBLIC size=2 offset=0:
33+
integer(2) :: d1 !CHECK: d1, PUBLIC (InCommonBlock) size=2 offset=8:
34+
integer(4) :: d2 !CHECK: d2, PUBLIC (InCommonBlock) size=4 offset=4:
35+
integer(1) :: d3 !CHECK: d3, PUBLIC (InCommonBlock) size=1 offset=0:
36+
real(2) :: d4 !CHECK: d4, PUBLIC (InCommonBlock) size=2 offset=0:
3737
common /common1/ d3,d2,d1 !CHECK: common1 size=10 offset=0: CommonBlockDetails alignment=4:
3838
common /common2/ d4 !CHECK: common2 size=2 offset=0: CommonBlockDetails alignment=2:
3939
end
@@ -71,7 +71,7 @@ module me
7171
subroutine host1
7272
contains
7373
subroutine internal
74-
common /b/ x(4) ! CHECK: x (Implicit) size=16 offset=0: ObjectEntity type: REAL(4) shape: 1_8:4_8
74+
common /b/ x(4) ! CHECK: x (Implicit, InCommonBlock) size=16 offset=0: ObjectEntity type: REAL(4) shape: 1_8:4_8
7575
equivalence(x,y) ! CHECK: y (Implicit) size=4 offset=0: ObjectEntity type: REAL(4)
7676
end
7777
end

flang/test/Semantics/resolve121.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ subroutine test3()
2525
! CHECK-LABEL: Subprogram scope: test3
2626
! CHECK: i1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4)
2727
! CHECK: j1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4)
28-
! CHECK: k1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4)
28+
! CHECK: k1, SAVE (InCommonBlock) size=4 offset=0: ObjectEntity type: INTEGER(4)
2929
integer :: i1
3030
integer :: j1, k1
3131
common /blk/ k1
@@ -37,7 +37,7 @@ subroutine test4()
3737
! CHECK-LABEL: Subprogram scope: test4
3838
! CHECK: i1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4) init:1_4
3939
! CHECK: j1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4)
40-
! CHECK: k1, SAVE size=4 offset=0: ObjectEntity type: INTEGER(4)
40+
! CHECK: k1, SAVE (InCommonBlock) size=4 offset=0: ObjectEntity type: INTEGER(4)
4141
integer :: i1 = 1
4242
integer :: j1, k1
4343
common /blk/ k1

flang/test/Semantics/symbol33.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
! array element reference still applies implicit typing, &c.
44
!DEF: /subr (Subroutine) Subprogram
55
subroutine subr
6-
!DEF: /subr/moo (Implicit) ObjectEntity INTEGER(4)
6+
!DEF: /subr/moo (Implicit, InCommonBlock) ObjectEntity INTEGER(4)
77
common //moo(1)
88
!DEF: /subr/a ObjectEntity REAL(4)
99
!REF: /subr/moo

0 commit comments

Comments
 (0)