Index: flang/lib/Semantics/check-omp-structure.cpp =================================================================== --- flang/lib/Semantics/check-omp-structure.cpp +++ flang/lib/Semantics/check-omp-structure.cpp @@ -1772,7 +1772,6 @@ CHECK_SIMPLE_CLAUSE(Affinity, OMPC_affinity) CHECK_SIMPLE_CLAUSE(Allocate, OMPC_allocate) CHECK_SIMPLE_CLAUSE(Capture, OMPC_capture) -CHECK_SIMPLE_CLAUSE(Copyin, OMPC_copyin) CHECK_SIMPLE_CLAUSE(Default, OMPC_default) CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj) CHECK_SIMPLE_CLAUSE(Destroy, OMPC_destroy) @@ -2381,6 +2380,27 @@ currSymbols, dirClauseTriple, GetClauseKindForParserClass(x)); } +void OmpStructureChecker::Enter(const parser::OmpClause::Copyin &x) { + CheckAllowed(llvm::omp::Clause::OMPC_copyin); + for (const auto &ompObject : x.v.v) { + common::visit( + common::visitors{ + [&](const parser::Designator &) { + if (const auto *name{parser::Unwrap(ompObject)}) { + if (IsPolymorphicAllocatable(*name->symbol)) { + context_.Say(name->source, + "If a polymorphic variable with allocatable attribute " + "'%s' is in COPYIN clause, the behavior is " + "unspecified"_port_en_US, name->symbol->name()); + } + } + }, + [&](const parser::Name &) {}, // common block + }, + ompObject.u); + } +} + llvm::StringRef OmpStructureChecker::getClauseName(llvm::omp::Clause clause) { return llvm::omp::getOpenMPClauseName(clause); } Index: flang/test/Semantics/OpenMP/omp-copyin06.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/OpenMP/omp-copyin06.f90 @@ -0,0 +1,17 @@ +! RUN: %python %S/../test_errors.py %s %flang -fopenmp +! OpenMP Version 5.0 +! 2.19.6.1 copyin Clause +! If the list item is a polymorphic variable with the allocatable attribute, +! the behavior is unspecified. + +subroutine copyin() + class(*), allocatable, save :: x + !$omp threadprivate(x) + + !WARNING: If a polymorphic variable with allocatable attribute 'x' is in COPYIN clause, the behavior is unspecified + !$omp parallel copyin(x) + call sub() + !$omp end parallel + +end +