Skip to content

Commit 2d5ef39

Browse files
committed
[flang] Apply the check for the constraint C1172 to more stmts
Apply the check for the constraint `C1172` to `unlock-stmt`, `change-team-stmt`, `end-team-stmt`, and `critical-stmt`, which all have `sync-stat-lists` and so `C1172` applies to them. Add a test to check the `sync-stat-lists` for these 4 statements. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D150745
1 parent df64272 commit 2d5ef39

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

flang/lib/Semantics/check-coarray.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ static void CheckEventVariable(
140140
void CoarrayChecker::Leave(const parser::ChangeTeamStmt &x) {
141141
CheckNamesAreDistinct(std::get<std::list<parser::CoarrayAssociation>>(x.t));
142142
CheckTeamType(context_, std::get<parser::TeamValue>(x.t));
143+
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
144+
}
145+
146+
void CoarrayChecker::Leave(const parser::EndChangeTeamStmt &x) {
147+
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
143148
}
144149

145150
void CoarrayChecker::Leave(const parser::SyncAllStmt &x) {
@@ -227,6 +232,14 @@ void CoarrayChecker::Leave(const parser::EventWaitStmt &x) {
227232
}
228233
}
229234

235+
void CoarrayChecker::Leave(const parser::UnlockStmt &x) {
236+
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
237+
}
238+
239+
void CoarrayChecker::Leave(const parser::CriticalStmt &x) {
240+
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
241+
}
242+
230243
void CoarrayChecker::Leave(const parser::ImageSelector &imageSelector) {
231244
haveStat_ = false;
232245
haveTeam_ = false;

flang/lib/Semantics/check-coarray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace Fortran::parser {
1616
class CharBlock;
1717
class MessageFixedText;
1818
struct ChangeTeamStmt;
19+
struct CriticalStmt;
1920
struct CoarrayAssociation;
21+
struct EndChangeTeamStmt;
2022
struct EventPostStmt;
2123
struct EventWaitStmt;
2224
struct FormTeamStmt;
@@ -25,6 +27,7 @@ struct SyncAllStmt;
2527
struct SyncImagesStmt;
2628
struct SyncMemoryStmt;
2729
struct SyncTeamStmt;
30+
struct UnlockStmt;
2831
} // namespace Fortran::parser
2932

3033
namespace Fortran::semantics {
@@ -33,12 +36,15 @@ class CoarrayChecker : public virtual BaseChecker {
3336
public:
3437
CoarrayChecker(SemanticsContext &context) : context_{context} {}
3538
void Leave(const parser::ChangeTeamStmt &);
39+
void Leave(const parser::EndChangeTeamStmt &);
3640
void Leave(const parser::SyncAllStmt &);
3741
void Leave(const parser::SyncImagesStmt &);
3842
void Leave(const parser::SyncMemoryStmt &);
3943
void Leave(const parser::SyncTeamStmt &);
4044
void Leave(const parser::EventPostStmt &);
4145
void Leave(const parser::EventWaitStmt &);
46+
void Leave(const parser::UnlockStmt &);
47+
void Leave(const parser::CriticalStmt &);
4248
void Leave(const parser::ImageSelector &);
4349
void Leave(const parser::FormTeamStmt &);
4450

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
! There are sync-stat-lists in critical-stmt, sync-all-stmt,
3+
! sync-images-stmt, sync-memory-stmt, sync-team-stmt,
4+
! event-post-stmt, unlock-stmt, change-team-stmt, and end-change-team-stmt.
5+
!
6+
! Some of these statements have their sync-stat-lists tested in other tests.
7+
! This test contains the statements that do not, namely critical-stmt, unlock-stmt,
8+
! change-team-stmt, and end-change-team-stmt.
9+
10+
program test_sync_stat_list
11+
use iso_fortran_env, only: team_type, lock_type
12+
13+
implicit none
14+
15+
integer coarray[*], sync_status, non_scalar(2), superfluous_stat, coindexed_integer[*]
16+
character(len=128) error_message, superfluous_errmsg, coindexed_character[*]
17+
logical invalid_type
18+
type(team_type) :: home
19+
type(lock_type) :: latch
20+
21+
! valid
22+
change team (home, stat=sync_status, errmsg=error_message)
23+
end team (stat=sync_status, errmsg=error_message)
24+
25+
!ERROR: Must be a scalar value, but is a rank-1 array
26+
change team (home, stat=non_scalar, errmsg=error_message)
27+
end team
28+
29+
!ERROR: Must have INTEGER type, but is LOGICAL(4)
30+
change team (home, stat=invalid_type, errmsg=error_message)
31+
end team
32+
33+
!ERROR: Must have CHARACTER type, but is LOGICAL(4)
34+
change team (home, stat=sync_status, errmsg=invalid_type)
35+
end team
36+
37+
change team (home)
38+
!ERROR: Must be a scalar value, but is a rank-1 array
39+
end team (stat=non_scalar, errmsg=error_message)
40+
41+
change team (home)
42+
!ERROR: Must have INTEGER type, but is LOGICAL(4)
43+
end team (stat=invalid_type, errmsg=error_message)
44+
45+
change team (home)
46+
!ERROR: Must have CHARACTER type, but is LOGICAL(4)
47+
end team (stat=sync_status, errmsg=invalid_type)
48+
49+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
50+
change team (home, stat=sync_status, errmsg=error_message, stat=superfluous_stat)
51+
end team
52+
53+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
54+
change team (home, stat=sync_status, errmsg=error_message, errmsg=superfluous_errmsg)
55+
end team
56+
57+
change team (home)
58+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
59+
end team (stat=sync_status, errmsg=error_message, stat=superfluous_stat)
60+
61+
change team (home)
62+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
63+
end team (stat=sync_status, errmsg=error_message, errmsg=superfluous_errmsg)
64+
65+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
66+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
67+
change team (home, stat=coindexed_integer[1], errmsg=coindexed_character[1])
68+
end team
69+
70+
change team (home)
71+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
72+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
73+
end team (stat=coindexed_integer[1], errmsg=coindexed_character[1])
74+
75+
! valid
76+
unlock (latch, stat=sync_status, errmsg=error_message)
77+
78+
!ERROR: Must be a scalar value, but is a rank-1 array
79+
unlock (latch, stat=non_scalar, errmsg=error_message)
80+
81+
!ERROR: Must have INTEGER type, but is LOGICAL(4)
82+
unlock (latch, stat=invalid_type, errmsg=error_message)
83+
84+
!ERROR: Must have CHARACTER type, but is LOGICAL(4)
85+
unlock (latch, stat=sync_status, errmsg=invalid_type)
86+
87+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
88+
unlock (latch, stat=sync_status, stat=superfluous_stat)
89+
90+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
91+
unlock (latch, stat=sync_status, errmsg=error_message, errmsg=superfluous_errmsg)
92+
93+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
94+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
95+
unlock (latch, stat=coindexed_integer[1], errmsg=coindexed_character[1])
96+
97+
! valid
98+
critical (stat=sync_status, errmsg=error_message)
99+
end critical
100+
101+
!ERROR: Must be a scalar value, but is a rank-1 array
102+
critical (stat=non_scalar, errmsg=error_message)
103+
end critical
104+
105+
!ERROR: Must have INTEGER type, but is LOGICAL(4)
106+
critical (stat=invalid_type, errmsg=error_message)
107+
end critical
108+
109+
!ERROR: Must have CHARACTER type, but is LOGICAL(4)
110+
critical (stat=sync_status, errmsg=invalid_type)
111+
end critical
112+
113+
!ERROR: The stat-variable in a sync-stat-list may not be repeated
114+
critical (stat=sync_status, errmsg=error_message, stat=superfluous_stat)
115+
end critical
116+
117+
!ERROR: The errmsg-variable in a sync-stat-list may not be repeated
118+
critical (stat=sync_status, errmsg=error_message, errmsg=superfluous_errmsg)
119+
end critical
120+
121+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
122+
!ERROR: The stat-variable or errmsg-variable in a sync-stat-list may not be a coindexed object
123+
critical (stat=coindexed_integer[1], errmsg=coindexed_character[1])
124+
end critical
125+
126+
end program test_sync_stat_list

0 commit comments

Comments
 (0)