diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3375,6 +3375,7 @@ // 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant]) struct OmpAlignedClause { TUPLE_CLASS_BOILERPLATE(OmpAlignedClause); + CharBlock source; std::tuple, std::optional> t; }; diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -508,7 +508,7 @@ // OpenMP miscellaneous flags OmpCommonBlock, OmpReduction, OmpAllocate, OmpDeclareSimd, OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction, OmpFlushed, - OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined); + OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined, OmpAligned); using Flags = common::EnumSet; const Scope &owner() const { return *owner_; } diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -243,6 +243,15 @@ bool Pre(const parser::OpenMPSectionsConstruct &); void Post(const parser::OpenMPSectionsConstruct &) { PopContext(); } + bool Pre(const parser::OpenMPDeclareSimdConstruct &x) { + PushContext(x.source, llvm::omp::Directive::OMPD_declare_simd); + const auto &name{std::get>(x.t)}; + if (name) { + ResolveOmpName(*name, Symbol::Flag::OmpDeclareSimd); + } + return true; + } + void Post(const parser::OpenMPDeclareSimdConstruct &) { PopContext(); } bool Pre(const parser::OpenMPThreadprivate &); void Post(const parser::OpenMPThreadprivate &) { PopContext(); } @@ -273,7 +282,27 @@ ResolveOmpObjectList(x.v, Symbol::Flag::OmpCopyIn); return false; } - + bool Pre(const parser::OmpLinearClause &x) { + std::visit(common::visitors{ + [&](const parser::OmpLinearClause::WithoutModifier + &linearWithoutModifier) { + ResolveOmpNameList( + linearWithoutModifier.names, Symbol::Flag::OmpLinear); + }, + [&](const parser::OmpLinearClause::WithModifier + &linearWithModifier) { + ResolveOmpNameList( + linearWithModifier.names, Symbol::Flag::OmpLinear); + }, + }, + x.u); + return false; + } + bool Pre(const parser::OmpAlignedClause &x) { + const auto &alignedNameList{std::get>(x.t)}; + ResolveOmpNameList(alignedNameList, Symbol::Flag::OmpAligned); + return false; + } void Post(const parser::Name &); private: @@ -323,6 +352,9 @@ Symbol *ResolveOmp(const parser::Name &, Symbol::Flag, Scope &); Symbol *ResolveOmp(Symbol &, Symbol::Flag, Scope &); Symbol *ResolveOmpCommonBlockName(const parser::Name *); + void ResolveOmpNameList(const std::list &, Symbol::Flag); + void ResolveOmpName(const parser::Name &, Symbol::Flag); + Symbol *ResolveName(const parser::Name *); Symbol *DeclareOrMarkOtherAccessEntity(const parser::Name &, Symbol::Flag); Symbol *DeclareOrMarkOtherAccessEntity(Symbol &, Symbol::Flag); void CheckMultipleAppearances( @@ -925,6 +957,34 @@ } // within OpenMP construct } +Symbol *OmpAttributeVisitor::ResolveName(const parser::Name *name) { + if (auto *resolvedSymbol{ + name ? GetContext().scope.FindSymbol(name->source) : nullptr}) { + name->symbol = resolvedSymbol; + return resolvedSymbol; + } else { + return nullptr; + } +} + +void OmpAttributeVisitor::ResolveOmpName( + const parser::Name &name, Symbol::Flag ompFlag) { + if (ResolveName(&name)) { + if (auto *resolvedSymbol{ResolveOmp(name, ompFlag, currScope())}) { + if (dataSharingAttributeFlags.test(ompFlag)) { + AddToContextObjectWithDSA(*resolvedSymbol, ompFlag); + } + } + } +} + +void OmpAttributeVisitor::ResolveOmpNameList( + const std::list &nameList, Symbol::Flag ompFlag) { + for (const auto &name : nameList) { + ResolveOmpName(name, ompFlag); + } +} + Symbol *OmpAttributeVisitor::ResolveOmpCommonBlockName( const parser::Name *name) { if (auto *prev{name diff --git a/flang/test/Semantics/omp-clause-validity01.f90 b/flang/test/Semantics/omp-clause-validity01.f90 --- a/flang/test/Semantics/omp-clause-validity01.f90 +++ b/flang/test/Semantics/omp-clause-validity01.f90 @@ -197,7 +197,6 @@ enddo !ERROR: A modifier may not be specified in a LINEAR clause on the DO directive - !ERROR: Internal: no symbol found for 'b' !$omp do linear(ref(b)) do i = 1, N a = 3.14 @@ -217,8 +216,6 @@ !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression !ERROR: A loop directive may not have both a LINEAR clause and an ORDERED clause with a parameter - !ERROR: Internal: no symbol found for 'b' - !ERROR: Internal: no symbol found for 'a' !$omp do ordered(1-1) private(b) linear(b) linear(a) do i = 1, N a = 3.14 @@ -369,7 +366,6 @@ enddo !ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression - !ERROR: Internal: no symbol found for 'b' !$omp simd aligned(b:-2) do i = 1, N a = 3.14 @@ -388,7 +384,6 @@ !ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive !ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive - !ERROR: Internal: no symbol found for 'b' !$omp parallel do proc_bind(master) proc_bind(close) linear(val(b)) do i = 1, N a = 3.14 @@ -558,7 +553,6 @@ !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression !ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression - !ERROR: Internal: no symbol found for 'a' !$omp taskloop simd simdlen(-1) aligned(a:-2) do i = 1, N a = 3.14 diff --git a/flang/test/Semantics/omp-declarative-directive.f90 b/flang/test/Semantics/omp-declarative-directive.f90 --- a/flang/test/Semantics/omp-declarative-directive.f90 +++ b/flang/test/Semantics/omp-declarative-directive.f90 @@ -9,8 +9,6 @@ subroutine declare_simd_1(a, b) real(8), intent(inout) :: a, b - !ERROR: Internal: no symbol found for 'declare_simd_1' - !ERROR: Internal: no symbol found for 'a' !$omp declare simd(declare_simd_1) aligned(a) a = 3.14 + b end subroutine declare_simd_1 @@ -27,7 +25,6 @@ subroutine declare_simd_2 use m1 procedure (sub) sub1 - !ERROR: Internal: no symbol found for 'sub1' !ERROR: NOTINBRANCH and INBRANCH clauses are mutually exclusive and may not appear on the same DECLARE SIMD directive !$omp declare simd(sub1) inbranch notinbranch procedure (sub), pointer::p diff --git a/flang/test/Semantics/omp-do03.f90 b/flang/test/Semantics/omp-do03.f90 --- a/flang/test/Semantics/omp-do03.f90 +++ b/flang/test/Semantics/omp-do03.f90 @@ -1,5 +1,4 @@ ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp -! XFAIL: * ! OpenMP Version 4.5 ! 2.7.1 Loop Construct diff --git a/flang/test/Semantics/omp-loop-simd01.f90 b/flang/test/Semantics/omp-loop-simd01.f90 --- a/flang/test/Semantics/omp-loop-simd01.f90 +++ b/flang/test/Semantics/omp-loop-simd01.f90 @@ -1,5 +1,4 @@ ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp -! XFAIL: * ! OpenMP Version 4.5 ! 2.8.3 Loop simd Construct diff --git a/flang/test/Semantics/omp-simd02.f90 b/flang/test/Semantics/omp-simd02.f90 --- a/flang/test/Semantics/omp-simd02.f90 +++ b/flang/test/Semantics/omp-simd02.f90 @@ -1,5 +1,4 @@ ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp -! XFAIL: * ! OpenMP Version 4.5 ! 2.8.1 simd Construct