Skip to content

[flang] Complete semantic checks for FORM TEAM #131022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions flang/lib/Semantics/check-coarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ class CriticalBodyEnforce {
};

template <typename T>
static void CheckTeamType(SemanticsContext &context, const T &x) {
static void CheckTeamType(
SemanticsContext &context, const T &x, bool mustBeVariable = false) {
if (const auto *expr{GetExpr(context, x)}) {
if (!IsTeamType(evaluate::GetDerivedTypeSpec(expr->GetType()))) {
context.Say(parser::FindSourceLocation(x), // C1114
"Team value must be of type TEAM_TYPE from module ISO_FORTRAN_ENV"_err_en_US);
} else if (mustBeVariable && !IsVariable(*expr)) {
context.Say(parser::FindSourceLocation(x),
"Team must be a variable in this context"_err_en_US);
}
}
}
Expand Down Expand Up @@ -356,7 +360,15 @@ void CoarrayChecker::Leave(const parser::ImageSelector &imageSelector) {
}

void CoarrayChecker::Leave(const parser::FormTeamStmt &x) {
CheckTeamType(context_, std::get<parser::TeamVariable>(x.t));
CheckTeamType(
context_, std::get<parser::TeamVariable>(x.t), /*mustBeVariable=*/true);
for (const auto &spec :
std::get<std::list<parser::FormTeamStmt::FormTeamSpec>>(x.t)) {
if (const auto *statOrErrmsg{std::get_if<parser::StatOrErrmsg>(&spec.u)}) {
CheckCoindexedStatOrErrmsg(
context_, *statOrErrmsg, "form-team-spec-list");
}
}
}

void CoarrayChecker::Enter(const parser::CriticalConstruct &x) {
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/form_team01a.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! Check for semantic errors in form team statements
! Check for parsing errors in form team statements
! This subtest contains syntactic tests that prevent the main tests from being emitted.

subroutine test
Expand Down
17 changes: 7 additions & 10 deletions flang/test/Semantics/form_team01b.f90
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! XFAIL: *
! Check for semantic errors in form team statements
! This subtest contains tests for unimplemented errors.

subroutine test
use, intrinsic :: iso_fortran_env, only: team_type
type(team_type) :: team
integer :: team_number
integer, codimension[*] :: co_statvar
character(len=50), codimension[*] :: co_errvar

! Semantically invalid invocations.
! argument 'stat' shall not be a coindexed object
!ERROR: to be determined
integer, save, codimension[*] :: co_statvar
character(len=50), save, codimension[*] :: co_errvar
procedure(type(team_type)) teamfunc
!ERROR: The stat-variable or errmsg-variable in a form-team-spec-list may not be a coindexed object
FORM TEAM (team_number, team, STAT=co_statvar[this_image()])
! argument 'errmsg' shall not be a coindexed object
!ERROR: to be determined
!ERROR: The stat-variable or errmsg-variable in a form-team-spec-list may not be a coindexed object
FORM TEAM (team_number, team, ERRMSG=co_errvar[this_image()])

!ERROR: Team must be a variable in this context
form team (team_number, teamfunc())
end subroutine