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 @@ -582,6 +582,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 @@ -3415,6 +3415,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); @@ -3490,9 +3497,9 @@ Firstprivate, From, Grainsize, Lastprivate, NumTasks, NumTeams, NumThreads, Ordered, Priority, Private, Safelen, Shared, Simdlen, ThreadLimit, To, Link, Uniform, UseDevicePtr, IsDevicePtr, - OmpAlignedClause, OmpDefaultClause, OmpDefaultmapClause, OmpDependClause, - OmpIfClause, OmpLinearClause, OmpMapClause, OmpProcBindClause, - OmpReductionClause, OmpScheduleClause> + OmpAlignedClause, OmpAllocateClause, OmpDefaultClause, + OmpDefaultmapClause, OmpDependClause, OmpIfClause, OmpLinearClause, + OmpMapClause, OmpProcBindClause, OmpReductionClause, 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,11 @@ 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 +211,8 @@ 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 @@ -2207,6 +2207,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 @@ -13,6 +13,11 @@ integer, parameter :: num = 16 real(8) :: arrayA(256), arrayB(512) + integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space + type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)] + integer(omp_allocator_handle_kind) :: xy_alloc + xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits) + arrayA = 1.414 arrayB = 3.14 N = 1024 @@ -25,7 +30,8 @@ ! shared-clause | ! copyin-clause | ! reduction-clause | -! proc-bind-clause +! proc-bind-clause | +! allocate-clause !$omp parallel do i = 1, N @@ -33,6 +39,30 @@ 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 + !$omp end parallel + + !$omp parallel allocate(xy_alloc :b) + do i = 1, N + a = 3.14 + enddo + !$omp end parallel + !ERROR: SCHEDULE clause is not allowed on the PARALLEL directive !$omp parallel schedule(static) do i = 1, N