Skip to content

Commit e032001

Browse files
committed
[flang] Add check for constraints on event-stmts
In the CoarrayChecker, add checks for the constraints C1177 and C1178 for event-wait-stmt. Add event-post-stmt to the check for the constraints for sync-stat-list. Add a check for the constraint C1176 on event-variable. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D137204
1 parent 49007a0 commit e032001

File tree

9 files changed

+181
-22
lines changed

9 files changed

+181
-22
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ bool IsLenTypeParameter(const Symbol &);
12011201
bool IsExtensibleType(const DerivedTypeSpec *);
12021202
bool IsBuiltinDerivedType(const DerivedTypeSpec *derived, const char *name);
12031203
bool IsBuiltinCPtr(const Symbol &);
1204+
bool IsEventType(const DerivedTypeSpec *);
1205+
bool IsLockType(const DerivedTypeSpec *);
12041206
// Is this derived type TEAM_TYPE from module ISO_FORTRAN_ENV?
12051207
bool IsTeamType(const DerivedTypeSpec *);
12061208
// Is this derived type TEAM_TYPE, C_PTR, or C_FUNPTR?

flang/lib/Evaluate/tools.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,14 @@ bool IsIsoCType(const DerivedTypeSpec *derived) {
15681568
IsBuiltinDerivedType(derived, "c_funptr");
15691569
}
15701570

1571+
bool IsEventType(const DerivedTypeSpec *derived) {
1572+
return IsBuiltinDerivedType(derived, "event_type");
1573+
}
1574+
1575+
bool IsLockType(const DerivedTypeSpec *derived) {
1576+
return IsBuiltinDerivedType(derived, "lock_type");
1577+
}
1578+
15711579
bool IsTeamType(const DerivedTypeSpec *derived) {
15721580
return IsBuiltinDerivedType(derived, "team_type");
15731581
}
@@ -1577,8 +1585,7 @@ bool IsBadCoarrayType(const DerivedTypeSpec *derived) {
15771585
}
15781586

15791587
bool IsEventTypeOrLockType(const DerivedTypeSpec *derivedTypeSpec) {
1580-
return IsBuiltinDerivedType(derivedTypeSpec, "event_type") ||
1581-
IsBuiltinDerivedType(derivedTypeSpec, "lock_type");
1588+
return IsEventType(derivedTypeSpec) || IsLockType(derivedTypeSpec);
15821589
}
15831590

15841591
int CountLenParameters(const DerivedTypeSpec &type) {

flang/lib/Semantics/check-coarray.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ static void CheckSyncStatList(
124124
}
125125
}
126126

127+
static void CheckEventVariable(
128+
SemanticsContext &context, const parser::EventVariable &eventVar) {
129+
if (const auto *expr{GetExpr(context, eventVar)}) {
130+
if (!IsEventType(evaluate::GetDerivedTypeSpec(expr->GetType()))) { // C1176
131+
context.Say(parser::FindSourceLocation(eventVar),
132+
"The event-variable must be of type EVENT_TYPE from module ISO_FORTRAN_ENV"_err_en_US);
133+
} else if (!evaluate::IsCoarray(*expr)) { // C1604
134+
context.Say(parser::FindSourceLocation(eventVar),
135+
"The event-variable must be a coarray"_err_en_US);
136+
}
137+
}
138+
}
139+
127140
void CoarrayChecker::Leave(const parser::ChangeTeamStmt &x) {
128141
CheckNamesAreDistinct(std::get<std::list<parser::CoarrayAssociation>>(x.t));
129142
CheckTeamType(context_, std::get<parser::TeamValue>(x.t));
@@ -156,6 +169,64 @@ void CoarrayChecker::Leave(const parser::SyncTeamStmt &x) {
156169
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
157170
}
158171

172+
void CoarrayChecker::Leave(const parser::EventPostStmt &x) {
173+
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
174+
CheckEventVariable(context_, std::get<parser::EventVariable>(x.t));
175+
}
176+
177+
void CoarrayChecker::Leave(const parser::EventWaitStmt &x) {
178+
const auto &eventVar{std::get<parser::EventVariable>(x.t)};
179+
180+
if (const auto *expr{GetExpr(context_, eventVar)}) {
181+
if (ExtractCoarrayRef(expr)) {
182+
context_.Say(parser::FindSourceLocation(eventVar), // C1177
183+
"A event-variable in a EVENT WAIT statement may not be a coindexed object"_err_en_US);
184+
} else {
185+
CheckEventVariable(context_, eventVar);
186+
}
187+
}
188+
189+
bool gotStat{false}, gotMsg{false}, gotUntil{false};
190+
using EventWaitSpec = parser::EventWaitStmt::EventWaitSpec;
191+
for (const EventWaitSpec &eventWaitSpec :
192+
std::get<std::list<EventWaitSpec>>(x.t)) {
193+
common::visit(
194+
common::visitors{
195+
[&](const parser::ScalarIntExpr &untilCount) {
196+
if (gotUntil) {
197+
context_.Say( // C1178
198+
"Until-spec in a event-wait-spec-list may not be repeated"_err_en_US);
199+
}
200+
gotUntil = true;
201+
},
202+
[&](const parser::StatOrErrmsg &statOrErrmsg) {
203+
common::visit(
204+
common::visitors{
205+
[&](const parser::StatVariable &stat) {
206+
if (gotStat) {
207+
context_.Say( // C1178
208+
"A stat-variable in a event-wait-spec-list may not be repeated"_err_en_US);
209+
}
210+
gotStat = true;
211+
},
212+
[&](const parser::MsgVariable &errmsg) {
213+
if (gotMsg) {
214+
context_.Say( // C1178
215+
"A errmsg-variable in a event-wait-spec-list may not be repeated"_err_en_US);
216+
}
217+
gotMsg = true;
218+
},
219+
},
220+
statOrErrmsg.u);
221+
CheckCoindexedStatOrErrmsg(
222+
context_, statOrErrmsg, "event-wait-spec-list");
223+
},
224+
225+
},
226+
eventWaitSpec.u);
227+
}
228+
}
229+
159230
void CoarrayChecker::Leave(const parser::ImageSelector &imageSelector) {
160231
haveStat_ = false;
161232
haveTeam_ = false;

flang/lib/Semantics/check-coarray.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class CharBlock;
1717
class MessageFixedText;
1818
struct ChangeTeamStmt;
1919
struct CoarrayAssociation;
20+
struct EventPostStmt;
21+
struct EventWaitStmt;
2022
struct FormTeamStmt;
2123
struct ImageSelector;
2224
struct SyncAllStmt;
@@ -35,6 +37,8 @@ class CoarrayChecker : public virtual BaseChecker {
3537
void Leave(const parser::SyncImagesStmt &);
3638
void Leave(const parser::SyncMemoryStmt &);
3739
void Leave(const parser::SyncTeamStmt &);
40+
void Leave(const parser::EventPostStmt &);
41+
void Leave(const parser::EventWaitStmt &);
3842
void Leave(const parser::ImageSelector &);
3943
void Leave(const parser::FormTeamStmt &);
4044

flang/test/Lower/pre-fir-tree04.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
Subroutine test_coarray
77
use iso_fortran_env, only: team_type, event_type, lock_type
88
type(team_type) :: t
9-
type(event_type) :: done
10-
type(lock_type) :: alock
9+
type(event_type) :: done[*]
10+
type(lock_type) :: alock[*]
1111
real :: y[10,*]
1212
integer :: counter[*]
1313
logical :: is_square

flang/test/Semantics/critical02.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ end subroutine test6
6161

6262
subroutine test7()
6363
use iso_fortran_env
64-
type(event_type) :: x, y
64+
type(event_type) :: x[*], y[*]
6565
critical
6666
!ERROR: An image control statement is not allowed in a CRITICAL construct
6767
event post (x)

flang/test/Semantics/doconcurrent01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end subroutine do_concurrent_test2
6666

6767
subroutine s1()
6868
use iso_fortran_env
69-
type(event_type) :: x
69+
type(event_type) :: x[*]
7070
do concurrent (i = 1:n)
7171
!ERROR: An image control statement is not allowed in DO CONCURRENT
7272
event post (x)
@@ -75,7 +75,7 @@ end subroutine s1
7575

7676
subroutine s2()
7777
use iso_fortran_env
78-
type(event_type) :: x
78+
type(event_type) :: x[*]
7979
do concurrent (i = 1:n)
8080
!ERROR: An image control statement is not allowed in DO CONCURRENT
8181
event wait (x)

flang/test/Semantics/event01b.f90

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ program test_event_post
2222
!______ invalid event-variable ____________________________
2323

2424
! event-variable must be event_type
25+
!ERROR: The event-variable must be of type EVENT_TYPE from module ISO_FORTRAN_ENV
2526
event post(non_event)
2627

2728
! event-variable must be a coarray
29+
!ERROR: The event-variable must be a coarray
2830
event post(non_coarray)
2931

3032
!ERROR: Must be a scalar value, but is a rank-1 array
@@ -48,18 +50,50 @@ program test_event_post
4850

4951
!______ invalid sync-stat-lists: redundant sync-stat-list ____________
5052

51-
! No specifier shall appear more than once in a given sync-stat-list
53+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
5254
event post(concert, stat=sync_status, stat=superfluous_stat)
5355

54-
! No specifier shall appear more than once in a given sync-stat-list
56+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
57+
event post(concert, errmsg=error_message, stat=sync_status, stat=superfluous_stat)
58+
59+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
60+
event post(concert, stat=sync_status, errmsg=error_message, stat=superfluous_stat)
61+
62+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
63+
event post(concert, stat=sync_status, stat=superfluous_stat, errmsg=error_message)
64+
65+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
5566
event post(concert, errmsg=error_message, errmsg=superfluous_errmsg)
5667

57-
!______ invalid sync-stat-lists: coindexed stat-variable ____________
68+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
69+
event post(concert, stat=sync_status, errmsg=error_message, errmsg=superfluous_errmsg)
70+
71+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
72+
event post(concert, errmsg=error_message, stat=sync_status, errmsg=superfluous_errmsg)
73+
74+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
75+
event post(concert, errmsg=error_message, errmsg=superfluous_errmsg, stat=sync_status)
5876

59-
! Check constraint C1173 from the Fortran 2018 standard
77+
!______ invalid sync-stat-lists: coindexed stat-variable - C1173____________
78+
79+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
6080
event post(concert, stat=co_indexed_integer[1])
6181

62-
! Check constraint C1173 from the Fortran 2018 standard
82+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
6383
event post(concert, errmsg=co_indexed_character[1])
6484

85+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
86+
event post(concert, stat=co_indexed_integer[1], errmsg=error_message)
87+
88+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
89+
event post(concert, stat=sync_status, errmsg=co_indexed_character[1])
90+
91+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
92+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
93+
event post(concert, stat=co_indexed_integer[1], errmsg=co_indexed_character[1])
94+
95+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
96+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
97+
event post(concert, errmsg=co_indexed_character[1], stat=co_indexed_integer[1])
98+
6599
end program test_event_post

flang/test/Semantics/event02b.f90

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ program test_event_wait
2121

2222
!_________________________ invalid event-variable ________________________________
2323

24-
! event-variable must be event_type
24+
!ERROR: The event-variable must be of type EVENT_TYPE from module ISO_FORTRAN_ENV
2525
event wait(non_event)
2626

27-
! event-variable must be a coarray
27+
!ERROR: The event-variable must be a coarray
2828
event wait(non_coarray)
2929

30-
! event-variable must not be coindexed
30+
!ERROR: A event-variable in a EVENT WAIT statement may not be a coindexed object
3131
event wait(concert[1])
3232

33-
! event-variable must not be coindexed
33+
!ERROR: A event-variable in a EVENT WAIT statement may not be a coindexed object
3434
event wait(occurrences(1)[1])
3535

3636
!ERROR: Must be a scalar value, but is a rank-1 array
@@ -62,21 +62,62 @@ program test_event_wait
6262

6363
!______ invalid event-wait-spec-lists: redundant event-wait-spec-list ____________
6464

65-
! No specifier shall appear more than once in a given event-wait-spec-list
65+
!ERROR: Until-spec in a event-wait-spec-list may not be repeated
6666
event wait(concert, until_count=threshold, until_count=indexed(1))
6767

68-
! No specifier shall appear more than once in a given event-wait-spec-list
68+
!ERROR: Until-spec in a event-wait-spec-list may not be repeated
69+
event wait(concert, until_count=threshold, stat=sync_status, until_count=indexed(1))
70+
71+
!ERROR: Until-spec in a event-wait-spec-list may not be repeated
72+
event wait(concert, until_count=threshold, errmsg=error_message, until_count=indexed(1))
73+
74+
!ERROR: Until-spec in a event-wait-spec-list may not be repeated
75+
event wait(concert, until_count=threshold, stat=sync_status, errmsg=error_message, until_count=indexed(1))
76+
77+
!ERROR: A stat-variable in a event-wait-spec-list may not be repeated
6978
event wait(concert, stat=sync_status, stat=superfluous_stat)
7079

71-
! No specifier shall appear more than once in a given event-wait-spec-list
80+
!ERROR: A stat-variable in a event-wait-spec-list may not be repeated
81+
event wait(concert, stat=sync_status, until_count=threshold, stat=superfluous_stat)
82+
83+
!ERROR: A stat-variable in a event-wait-spec-list may not be repeated
84+
event wait(concert, stat=sync_status, errmsg=error_message, stat=superfluous_stat)
85+
86+
!ERROR: A stat-variable in a event-wait-spec-list may not be repeated
87+
event wait(concert, stat=sync_status, until_count=threshold, errmsg=error_message, stat=superfluous_stat)
88+
89+
!ERROR: A errmsg-variable in a event-wait-spec-list may not be repeated
7290
event wait(concert, errmsg=error_message, errmsg=superfluous_errmsg)
7391

74-
!_____________ invalid sync-stat-lists: coindexed stat-variable __________________
92+
!ERROR: A errmsg-variable in a event-wait-spec-list may not be repeated
93+
event wait(concert, errmsg=error_message, until_count=threshold, errmsg=superfluous_errmsg)
94+
95+
!ERROR: A errmsg-variable in a event-wait-spec-list may not be repeated
96+
event wait(concert, errmsg=error_message, stat=superfluous_stat, errmsg=superfluous_errmsg)
7597

76-
! Check constraint C1173 from the Fortran 2018 standard
98+
!ERROR: A errmsg-variable in a event-wait-spec-list may not be repeated
99+
event wait(concert, errmsg=error_message, until_count=threshold, stat=superfluous_stat, errmsg=superfluous_errmsg)
100+
101+
!_____________ invalid sync-stat-lists: coindexed stat-variable - C1173 __________________
102+
103+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
77104
event wait(concert, stat=co_indexed_integer[1])
78105

79-
! Check constraint C1173 from the Fortran 2018 standard
106+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
80107
event wait(concert, errmsg=co_indexed_character[1])
81108

109+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
110+
event wait(concert, stat=co_indexed_integer[1], errmsg=error_message)
111+
112+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
113+
event wait(concert, stat=sync_status, errmsg=co_indexed_character[1])
114+
115+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
116+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
117+
event wait(concert, stat=co_indexed_integer[1], errmsg=co_indexed_character[1])
118+
119+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
120+
!ERROR: The stat-variable or errmsg-variable in a event-wait-spec-list may not be a coindexed object
121+
event wait(concert, errmsg=co_indexed_character[1], stat=co_indexed_integer[1])
122+
82123
end program test_event_wait

0 commit comments

Comments
 (0)