@@ -1184,6 +1184,53 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
11841184void OmpStructureChecker::Enter (const parser::OpenMPGroupprivate &x) {
11851185 PushContextAndClauseSets (
11861186 x.v .DirName ().source , llvm::omp::Directive::OMPD_groupprivate);
1187+
1188+ for (const parser::OmpArgument &arg : x.v .Arguments ().v ) {
1189+ auto *locator{std::get_if<parser::OmpLocator>(&arg.u )};
1190+ const Symbol *sym{GetArgumentSymbol (arg)};
1191+
1192+ if (!locator || !sym ||
1193+ (!IsVariableListItem (*sym) && !IsCommonBlock (*sym))) {
1194+ context_.Say (arg.source ,
1195+ " GROUPPRIVATE argument should be a variable or a named common block" _err_en_US);
1196+ continue ;
1197+ }
1198+
1199+ if (sym->has <AssocEntityDetails>()) {
1200+ context_.SayWithDecl (*sym, arg.source ,
1201+ " GROUPPRIVATE argument cannot be an an ASSOCIATE name" _err_en_US);
1202+ continue ;
1203+ }
1204+ if (auto *obj{sym->detailsIf <ObjectEntityDetails>()}) {
1205+ if (obj->IsCoarray ()) {
1206+ context_.Say (arg.source ,
1207+ " GROUPPRIVATE argument cannot be an a coarray" _err_en_US);
1208+ continue ;
1209+ }
1210+ if (obj->init ()) {
1211+ context_.SayWithDecl (*sym, arg.source ,
1212+ " GROUPPRIVATE argument cannot be declared with an initializer" _err_en_US);
1213+ continue ;
1214+ }
1215+ }
1216+ if (sym->test (Symbol::Flag::InCommonBlock)) {
1217+ context_.Say (arg.source ,
1218+ " GROUPPRIVATE argument cannot be an a member of a common block" _err_en_US);
1219+ continue ;
1220+ }
1221+ if (!IsCommonBlock (*sym)) {
1222+ const Scope &thisScope{context_.FindScope (x.v .source )};
1223+ if (thisScope != sym->owner ()) {
1224+ context_.SayWithDecl (*sym, arg.source ,
1225+ " GROUPPRIVATE argument variable must be declared in the same scope as the construct on which it appears" _err_en_US);
1226+ continue ;
1227+ } else if (!thisScope.IsModule () && !sym->attrs ().test (Attr::SAVE)) {
1228+ context_.SayWithDecl (*sym, arg.source ,
1229+ " GROUPPRIVATE argument variable must be declared in the module scope or have SAVE attribute" _err_en_US);
1230+ continue ;
1231+ }
1232+ }
1233+ }
11871234}
11881235
11891236void OmpStructureChecker::Leave (const parser::OpenMPGroupprivate &x) {
0 commit comments