Skip to content

Commit 2ac8530

Browse files
committed
[flang] Complete semantic checks for FORM TEAM
Add remaining checking for the FORM TEAM statement, complete and enable a test.
1 parent 016557f commit 2ac8530

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

flang/lib/Semantics/check-coarray.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ class CriticalBodyEnforce {
6464
};
6565

6666
template <typename T>
67-
static void CheckTeamType(SemanticsContext &context, const T &x) {
67+
static void CheckTeamType(
68+
SemanticsContext &context, const T &x, bool mustBeVariable = false) {
6869
if (const auto *expr{GetExpr(context, x)}) {
6970
if (!IsTeamType(evaluate::GetDerivedTypeSpec(expr->GetType()))) {
7071
context.Say(parser::FindSourceLocation(x), // C1114
7172
"Team value must be of type TEAM_TYPE from module ISO_FORTRAN_ENV"_err_en_US);
73+
} else if (mustBeVariable && !IsVariable(*expr)) {
74+
context.Say(parser::FindSourceLocation(x),
75+
"Team must be a variable in this context"_err_en_US);
7276
}
7377
}
7478
}
@@ -356,7 +360,15 @@ void CoarrayChecker::Leave(const parser::ImageSelector &imageSelector) {
356360
}
357361

358362
void CoarrayChecker::Leave(const parser::FormTeamStmt &x) {
359-
CheckTeamType(context_, std::get<parser::TeamVariable>(x.t));
363+
CheckTeamType(
364+
context_, std::get<parser::TeamVariable>(x.t), /*mustBeVariable=*/true);
365+
for (const auto &spec :
366+
std::get<std::list<parser::FormTeamStmt::FormTeamSpec>>(x.t)) {
367+
if (const auto *statOrErrmsg{std::get_if<parser::StatOrErrmsg>(&spec.u)}) {
368+
CheckCoindexedStatOrErrmsg(
369+
context_, *statOrErrmsg, "form-team-spec-list");
370+
}
371+
}
360372
}
361373

362374
void CoarrayChecker::Enter(const parser::CriticalConstruct &x) {

flang/test/Semantics/form_team01a.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
2-
! Check for semantic errors in form team statements
2+
! Check for parsing errors in form team statements
33
! This subtest contains syntactic tests that prevent the main tests from being emitted.
44

55
subroutine test
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
2-
! XFAIL: *
32
! Check for semantic errors in form team statements
43
! This subtest contains tests for unimplemented errors.
54

65
subroutine test
76
use, intrinsic :: iso_fortran_env, only: team_type
87
type(team_type) :: team
98
integer :: team_number
10-
integer, codimension[*] :: co_statvar
11-
character(len=50), codimension[*] :: co_errvar
12-
13-
! Semantically invalid invocations.
14-
! argument 'stat' shall not be a coindexed object
15-
!ERROR: to be determined
9+
integer, save, codimension[*] :: co_statvar
10+
character(len=50), save, codimension[*] :: co_errvar
11+
procedure(type(team_type)) teamfunc
12+
!ERROR: The stat-variable or errmsg-variable in a form-team-spec-list may not be a coindexed object
1613
FORM TEAM (team_number, team, STAT=co_statvar[this_image()])
17-
! argument 'errmsg' shall not be a coindexed object
18-
!ERROR: to be determined
14+
!ERROR: The stat-variable or errmsg-variable in a form-team-spec-list may not be a coindexed object
1915
FORM TEAM (team_number, team, ERRMSG=co_errvar[this_image()])
20-
16+
!ERROR: Team must be a variable in this context
17+
form team (team_number, teamfunc())
2118
end subroutine

0 commit comments

Comments
 (0)