diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -1234,7 +1234,7 @@ // variables on Data-sharing attribute clauses std::map objectWithDSA; bool withinConstruct{false}; - std::size_t associatedLoopLevel{0}; + int64_t associatedLoopLevel{0}; }; // back() is the top of the stack OmpContext &GetContext() { @@ -1267,10 +1267,10 @@ return it != GetContext().objectWithDSA.end(); } - void SetContextAssociatedLoopLevel(std::size_t level) { + void SetContextAssociatedLoopLevel(int64_t level) { GetContext().associatedLoopLevel = level; } - std::size_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &); + int64_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &); Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) { const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})}; @@ -6446,10 +6446,10 @@ return nullptr; } -std::size_t OmpAttributeVisitor::GetAssociatedLoopLevelFromClauses( +int64_t OmpAttributeVisitor::GetAssociatedLoopLevelFromClauses( const parser::OmpClauseList &x) { - std::size_t orderedLevel{0}; - std::size_t collapseLevel{0}; + int64_t orderedLevel{0}; + int64_t collapseLevel{0}; for (const auto &clause : x.v) { if (const auto *orderedClause{ std::get_if(&clause.u)}) { @@ -6484,11 +6484,13 @@ // - The loop iteration variables in the associated do-loops of a simd // construct with multiple associated do-loops are lastprivate. // -// TODO: This assumes that the do-loops association for collapse/ordered -// clause has been performed (the number of nested do-loops >= n). +// TODO: revisit after semantics checks are completed for do-loop association of +// collapse and ordered void OmpAttributeVisitor::PrivatizeAssociatedLoopIndex( const parser::OpenMPLoopConstruct &x) { - std::size_t level{GetContext().associatedLoopLevel}; + int64_t level{GetContext().associatedLoopLevel}; + if (level <= 0) + return; Symbol::Flag ivDSA{Symbol::Flag::OmpPrivate}; if (simdSet.test(GetContext().directive)) { if (level == 1) { 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 @@ -50,6 +50,15 @@ enddo !$omp end parallel + !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression + !$omp do collapse(-1) + do i = 1, N + do j = 1, N + a = 3.14 + enddo + enddo + !$omp end do + a = 1.0 !$omp parallel firstprivate(a) do i = 1, N