diff --git a/flang/docs/OpenACC.md b/flang/docs/OpenACC.md index 61038a9f13df..87f30ccd953b 100644 --- a/flang/docs/OpenACC.md +++ b/flang/docs/OpenACC.md @@ -25,6 +25,8 @@ local: logical expression. * `!$acc routine` directive can be placed at the top level. * `!$acc cache` directive accepts scalar variable. +* The `!$acc declare` directive accepts assumed size array arguments for + `deviceptr` and `present` clauses. ## Remarks about incompatibilities with other implementations * Array element references in the data clauses are equivalent to array sections diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index d75b4ea13d35..c50724fe9d35 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -953,7 +953,14 @@ void AccAttributeVisitor::Post( const auto &clauseList = std::get(x.t); for (const auto &clause : clauseList.v) { // Restriction - line 2414 - DoNotAllowAssumedSizedArray(GetAccObjectList(clause)); + // We assume the restriction is present because clauses that require + // moving data would require the size of the data to be present, but + // the deviceptr and present clauses do not require moving data and + // thus we permit them. + if (!std::holds_alternative(clause.u) && + !std::holds_alternative(clause.u)) { + DoNotAllowAssumedSizedArray(GetAccObjectList(clause)); + } } } diff --git a/flang/test/Semantics/OpenACC/acc-declare-validity.f90 b/flang/test/Semantics/OpenACC/acc-declare-validity.f90 index 2e7e651815d4..7cdc69436704 100644 --- a/flang/test/Semantics/OpenACC/acc-declare-validity.f90 +++ b/flang/test/Semantics/OpenACC/acc-declare-validity.f90 @@ -62,9 +62,21 @@ contains subroutine sub2(cc) real(8), dimension(*) :: cc !ERROR: Assumed-size dummy arrays may not appear on the DECLARE directive - !$acc declare present(cc) + !$acc declare copyin(cc) end subroutine sub2 + subroutine sub2e1(cc) + real(8), dimension(*) :: cc + !OK + !$acc declare present(cc) + end subroutine sub2e1 + + subroutine sub2e2(cc) + real(8), dimension(*) :: cc + !OK + !$acc declare deviceptr(cc) + end subroutine sub2e2 + subroutine sub3() real :: aa(100) !ERROR: The ZERO modifier is not allowed for the COPYOUT clause on the DECLARE directive