[flang] Semantic checks for teams directive

Original-commit: flang-compiler/f18@ec22e9c4c2
Reviewed-on: https://github.com/flang-compiler/f18/pull/750
Tree-same-pre-rewrite: false
This commit is contained in:
David Truby 2019-09-17 12:08:04 +01:00
parent 914e93681a
commit cad44d2e91
2 changed files with 54 additions and 2 deletions

View File

@ -404,6 +404,15 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
OmpClause::DEVICE, OmpClause::DEFAULTMAP, OmpClause::NOWAIT}; OmpClause::DEVICE, OmpClause::DEFAULTMAP, OmpClause::NOWAIT};
SetContextAllowedOnce(allowedOnce); SetContextAllowedOnce(allowedOnce);
} break; } break;
case parser::OmpBlockDirective::Directive::Teams: {
PushContext(beginDir.source, OmpDirective::TEAMS);
OmpClauseSet allowed{OmpClause::PRIVATE, OmpClause::FIRSTPRIVATE,
OmpClause::SHARED, OmpClause::REDUCTION};
SetContextAllowed(allowed);
OmpClauseSet allowedOnce{
OmpClause::NUM_TEAMS, OmpClause::THREAD_LIMIT, OmpClause::DEFAULT};
SetContextAllowedOnce(allowedOnce);
} break;
default: default:
// TODO others // TODO others
break; break;
@ -747,8 +756,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::NumTasks &x) {
CheckAllowed(OmpClause::NUM_TASKS); CheckAllowed(OmpClause::NUM_TASKS);
RequiresPositiveParameter(OmpClause::NUM_TASKS, x.v); RequiresPositiveParameter(OmpClause::NUM_TASKS, x.v);
} }
void OmpStructureChecker::Enter(const parser::OmpClause::NumTeams &) { void OmpStructureChecker::Enter(const parser::OmpClause::NumTeams &x) {
CheckAllowed(OmpClause::NUM_TEAMS); CheckAllowed(OmpClause::NUM_TEAMS);
RequiresPositiveParameter(OmpClause::NUM_TEAMS, x.v);
} }
void OmpStructureChecker::Enter(const parser::OmpClause::NumThreads &x) { void OmpStructureChecker::Enter(const parser::OmpClause::NumThreads &x) {
CheckAllowed(OmpClause::NUM_THREADS); CheckAllowed(OmpClause::NUM_THREADS);
@ -789,8 +799,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Simdlen &x) {
CheckAllowed(OmpClause::SIMDLEN); CheckAllowed(OmpClause::SIMDLEN);
RequiresConstantPositiveParameter(OmpClause::SIMDLEN, x.v); RequiresConstantPositiveParameter(OmpClause::SIMDLEN, x.v);
} }
void OmpStructureChecker::Enter(const parser::OmpClause::ThreadLimit &) { void OmpStructureChecker::Enter(const parser::OmpClause::ThreadLimit &x) {
CheckAllowed(OmpClause::THREAD_LIMIT); CheckAllowed(OmpClause::THREAD_LIMIT);
RequiresPositiveParameter(OmpClause::THREAD_LIMIT, x.v);
} }
void OmpStructureChecker::Enter(const parser::OmpClause::To &) { void OmpStructureChecker::Enter(const parser::OmpClause::To &) {
CheckAllowed(OmpClause::TO); CheckAllowed(OmpClause::TO);

View File

@ -70,4 +70,45 @@ program main
enddo enddo
!$omp end target !$omp end target
!$omp teams num_teams(3) thread_limit(10) default(shared) private(i) shared(a)
do i = 1, N
a = 3.14
enddo
!$omp end teams
!ERROR: At most one NUM_TEAMS clause can appear on the TEAMS directive
!$omp teams num_teams(2) num_teams(3)
do i = 1, N
a = 3.14
enddo
!$omp end teams
!ERROR: The parameter of the NUM_TEAMS clause must be a positive integer expression
!$omp teams num_teams(-1)
do i = 1, N
a = 3.14
enddo
!$omp end teams
!ERROR: At most one THREAD_LIMIT clause can appear on the TEAMS directive
!$omp teams thread_limit(2) thread_limit(3)
do i = 1, N
a = 3.14
enddo
!$omp end teams
!ERROR: The parameter of the THREAD_LIMIT clause must be a positive integer expression
!$omp teams thread_limit(-1)
do i = 1, N
a = 3.14
enddo
!$omp end teams
!ERROR: At most one DEFAULT clause can appear on the TEAMS directive
!$omp teams default(shared) default(none)
do i = 1, N
a = 3.14
enddo
!$omp end teams
end program main end program main