Skip to content

Commit 3f04fb4

Browse files
authored
[flang] Complete semantic checks for FORM TEAM (llvm#131022)
Add remaining checking for the FORM TEAM statement, complete and enable a test.
1 parent 1dc397d commit 3f04fb4

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
@@ -97,11 +97,15 @@ class ChangeTeamBodyEnforce {
9797
};
9898

9999
template <typename T>
100-
static void CheckTeamType(SemanticsContext &context, const T &x) {
100+
static void CheckTeamType(
101+
SemanticsContext &context, const T &x, bool mustBeVariable = false) {
101102
if (const auto *expr{GetExpr(context, x)}) {
102103
if (!IsTeamType(evaluate::GetDerivedTypeSpec(expr->GetType()))) {
103104
context.Say(parser::FindSourceLocation(x), // C1114
104105
"Team value must be of type TEAM_TYPE from module ISO_FORTRAN_ENV"_err_en_US);
106+
} else if (mustBeVariable && !IsVariable(*expr)) {
107+
context.Say(parser::FindSourceLocation(x),
108+
"Team must be a variable in this context"_err_en_US);
105109
}
106110
}
107111
}
@@ -389,7 +393,15 @@ void CoarrayChecker::Leave(const parser::ImageSelector &imageSelector) {
389393
}
390394

391395
void CoarrayChecker::Leave(const parser::FormTeamStmt &x) {
392-
CheckTeamType(context_, std::get<parser::TeamVariable>(x.t));
396+
CheckTeamType(
397+
context_, std::get<parser::TeamVariable>(x.t), /*mustBeVariable=*/true);
398+
for (const auto &spec :
399+
std::get<std::list<parser::FormTeamStmt::FormTeamSpec>>(x.t)) {
400+
if (const auto *statOrErrmsg{std::get_if<parser::StatOrErrmsg>(&spec.u)}) {
401+
CheckCoindexedStatOrErrmsg(
402+
context_, *statOrErrmsg, "form-team-spec-list");
403+
}
404+
}
393405
}
394406

395407
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

flang/test/Semantics/form_team01b.f90

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)