From 990222931ba2c87803f8b0381a2088b0e2969848 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 27 Oct 2020 21:09:48 -0400 Subject: [PATCH] [flang][openacc] Fix ambiguity in the self clause parsing In the OpenACC specification, there are two different self clause. One for the update directive with a var-list argument. This clause is a synonym of the host clause. The second self clause is present for most of the compute construct and takes an optional condition. To solve this ambiguity, the self clause for the update directive is directly translated to a host clause during the parsing. The self clause in AccClause refers always to the compute construct clause. Reviewed By: kiranktp Differential Revision: https://reviews.llvm.org/D90185 --- flang/lib/Parser/openacc-parsers.cpp | 5 +++++ flang/test/Semantics/acc-clause-validity.f90 | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp index 546f4e9..510b802 100644 --- a/flang/lib/Parser/openacc-parsers.cpp +++ b/flang/lib/Parser/openacc-parsers.cpp @@ -98,8 +98,13 @@ TYPE_PARSER("AUTO" >> construct(construct()) || parenthesized(construct( Parser{} / ":", Parser{})))) || + // SELF clause is either a simple optional condition for compute construct + // or a synonym of the HOST clause for the update directive 2.14.4 holding + // an object list. "SELF" >> construct(construct( maybe(parenthesized(scalarLogicalExpr)))) || + construct( + construct(parenthesized(Parser{}))) || "SEQ" >> construct(construct()) || "TILE" >> construct(construct( parenthesized(Parser{}))) || diff --git a/flang/test/Semantics/acc-clause-validity.f90 b/flang/test/Semantics/acc-clause-validity.f90 index 56910c2..188d41f 100644 --- a/flang/test/Semantics/acc-clause-validity.f90 +++ b/flang/test/Semantics/acc-clause-validity.f90 @@ -31,7 +31,7 @@ program openacc_clause_validity !ERROR: At least one clause is required on the DECLARE directive !$acc declare - real(8), dimension(N) :: a + real(8), dimension(N) :: a, f, g, h !$acc init !$acc init if(.TRUE.) @@ -83,6 +83,8 @@ program openacc_clause_validity !ERROR: Unmatched PARALLEL directive !$acc end parallel + !$acc update self(a, f) host(g) device(h) + !$acc update device(i) device_type(*) async !ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the UPDATE directive @@ -108,6 +110,21 @@ program openacc_clause_validity a(i) = 3.14 end do + !$acc parallel loop self + do i = 1, N + a(i) = 3.14 + end do + + !$acc parallel loop self(.true.) + do i = 1, N + a(i) = 3.14 + end do + + !$acc parallel loop self(ifCondition) + do i = 1, N + a(i) = 3.14 + end do + !$acc parallel loop tile(2, 2) do i = 1, N do j = 1, N -- 2.7.4