diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -581,6 +581,8 @@ NODE(OmpReductionCombiner, FunctionCombiner) NODE(parser, OmpReductionInitializerClause) NODE(parser, OmpReductionOperator) + NODE(parser, OmpAllocateClause) + NODE(OmpAllocateClause, Allocator) NODE(parser, OmpScheduleClause) NODE_ENUM(OmpScheduleClause, ScheduleType) NODE(parser, OmpScheduleModifier) 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 @@ -3411,6 +3411,13 @@ std::tuple> t; }; +// OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list) +struct OmpAllocateClause { + TUPLE_CLASS_BOILERPLATE(OmpAllocateClause); + WRAPPER_CLASS(Allocator, ScalarIntExpr); + std::tuple, OmpObjectList> t; +}; + // 2.13.9 depend-vec-length -> +/- non-negative-constant struct OmpDependSinkVecLength { TUPLE_CLASS_BOILERPLATE(OmpDependSinkVecLength); @@ -3488,7 +3495,7 @@ ThreadLimit, To, Link, Uniform, UseDevicePtr, IsDevicePtr, OmpAlignedClause, OmpDefaultClause, OmpDefaultmapClause, OmpDependClause, OmpIfClause, OmpLinearClause, OmpMapClause, OmpProcBindClause, - OmpReductionClause, OmpScheduleClause> + OmpReductionClause, OmpAllocateClause, OmpScheduleClause> u; }; diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -104,6 +104,10 @@ TYPE_PARSER(construct( Parser{} / ":", nonemptyList(designator))) +//OMP 5.0 2.11.4 ALLOCATE ([allocator:] variable-name-list) +TYPE_PARSER(construct( + maybe(construct(scalarIntExpr) / ":"), Parser{})) + // 2.13.9 DEPEND (SOURCE | SINK : vec | (IN | OUT | INOUT) : list TYPE_PARSER(construct( Parser{}, scalarIntConstantExpr)) @@ -206,6 +210,9 @@ construct(parenthesized(Parser{})) || "REDUCTION" >> construct(parenthesized(Parser{})) || + + "ALLOCATE" >> + construct(parenthesized(Parser{})) || "SAFELEN" >> construct(construct( parenthesized(scalarIntConstantExpr))) || "SCHEDULE" >> diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2201,6 +2201,12 @@ Walk(std::get>(x.t), ","); Put(")"); } + void Unparse(const OmpAllocateClause &x) { + Word("ALLOCATE("); + Walk(std::get>(x.t),":"); + Walk(std::get(x.t)); + Put(")"); + } void Unparse(const OmpDependSinkVecLength &x) { Walk(std::get(x.t)); Walk(std::get(x.t)); 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 @@ -1,5 +1,5 @@ ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp - +use omp_lib ! Check OpenMP clause validity for the following directives: ! ! 2.5 PARALLEL construct @@ -25,9 +25,28 @@ ! shared-clause | ! copyin-clause | ! reduction-clause | -! proc-bind-clause +! proc-bind-clause | +! allocate-clause - !$omp parallel + !$omp parallel + do i = 1, N + a = 3.14 + enddo + !$omp end parallel + + !$omp parallel allocate(b) + do i = 1, N + a = 3.14 + enddo + !$omp end parallel + + !$omp parallel allocate(omp_default_mem_space : b, c) + do i = 1, N + a = 3.14 + enddo + !$omp end parallel + + !$omp parallel allocate(b) allocate(c) do i = 1, N a = 3.14 enddo