diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp index d69e1c597e2fb..44aaa1fdd8036 100644 --- a/flang/lib/Semantics/check-acc-structure.cpp +++ b/flang/lib/Semantics/check-acc-structure.cpp @@ -592,15 +592,28 @@ void AccStructureChecker::Enter(const parser::AccClause::Gang &g) { if (g.v) { bool hasNum = false; bool hasDim = false; + bool hasStatic = false; const Fortran::parser::AccGangArgList &x = *g.v; for (const Fortran::parser::AccGangArg &gangArg : x.v) { if (std::get_if(&gangArg.u)) { hasNum = true; } else if (std::get_if(&gangArg.u)) { hasDim = true; + } else if (std::get_if(&gangArg.u)) { + hasStatic = true; } } + if (GetContext().directive == llvm::acc::Directive::ACCD_routine && + (hasStatic || hasNum)) { + context_.Say(GetContext().clauseSource, + "Only the dim argument is allowed on the %s clause on the %s directive"_err_en_US, + parser::ToUpperCaseLetters( + llvm::acc::getOpenACCClauseName(llvm::acc::Clause::ACCC_gang) + .str()), + ContextDirectiveAsFortran()); + } + if (hasDim && hasNum) { context_.Say(GetContext().clauseSource, "The num argument is not allowed when dim is specified"_err_en_US); diff --git a/flang/test/Semantics/OpenACC/acc-routine.f90 b/flang/test/Semantics/OpenACC/acc-routine.f90 index 42762f537b8bc..8281822ca01d0 100644 --- a/flang/test/Semantics/OpenACC/acc-routine.f90 +++ b/flang/test/Semantics/OpenACC/acc-routine.f90 @@ -14,6 +14,16 @@ subroutine sub3() !$acc routine bind(sub1) end subroutine +subroutine sub4() + !ERROR: Only the dim argument is allowed on the GANG clause on the ROUTINE directive + !$acc routine gang(num: 1) +end subroutine + +subroutine sub5() + !ERROR: Only the dim argument is allowed on the GANG clause on the ROUTINE directive + !$acc routine gang(static: 1) +end subroutine + subroutine sub6() !ERROR: Clause GANG is not allowed if clause GANG appears on the ROUTINE directive !$acc routine gang gang