Skip to content

[flang][openacc] Relax constraint on OpenACC declare statement #135238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flang/docs/OpenACC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,14 @@ void AccAttributeVisitor::Post(
const auto &clauseList = std::get<parser::AccClauseList>(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<parser::AccClause::Deviceptr>(clause.u) &&
!std::holds_alternative<parser::AccClause::Present>(clause.u)) {
DoNotAllowAssumedSizedArray(GetAccObjectList(clause));
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion flang/test/Semantics/OpenACC/acc-declare-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,21 @@ end function fct1
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
Expand Down