[flang-commits] [flang] [flang][OpenACC] Reland data-clause designator path handling (PR #220781)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Thu Oct 8 19:58:35 PDT 2026


================
@@ -1892,6 +2056,87 @@ void AccAttributeVisitor::Post(const parser::Name &name) {
   }
 }
 
+bool AccAttributeVisitor::Pre(const parser::Expr &) {
+  enterExpressionLikeContext();
+  return true;
+}
+
+template <typename A>
+void AccAttributeVisitor::CheckAccDefaultNoneReferenceIn(const A &x) {
+  // A reference whose structural path cannot be built (a substring, a
+  // coindexed object, an unanalyzable subscript) is still a reference to its
+  // base object, so check that rather than skipping the reference.
+  if (const auto *designator{
+          std::get_if<common::Indirection<parser::Designator>>(&x.u)}) {
+    const parser::Name &name{parser::GetFirstName(designator->value())};
+    std::optional<DesignatorPath> designatorPath{
+        GetDesignatorPath(context_, designator->value())};
+    if (!designatorPath && name.symbol) {
+      designatorPath = MakeBaseDesignatorPath(*name.symbol);
+    }
+    if (designatorPath) {
+      CheckAccDefaultNoneReference(name, std::move(*designatorPath));
+    }
+  } else if (const auto *functionReference{
+                 std::get_if<common::Indirection<parser::FunctionReference>>(
+                     &x.u)}) {
+    const parser::Name &name{parser::GetFirstName(functionReference->value())};
+    if (WithinConstruct() && GetContext().defaultDSA == Symbol::Flag::AccNone &&
+        name.symbol && name.symbol->has<ObjectEntityDetails>()) {
+      std::optional<DesignatorPath> designatorPath{
+          GetDesignatorPath(context_, functionReference->value())};
+      CheckAccDefaultNoneReference(name,
+          designatorPath ? std::move(*designatorPath)
+                         : MakeBaseDesignatorPath(*name.symbol));
+    }
----------------
eugeneepshteyn wrote:

(This comment was generated with the help of AI)

A statically bound NOPASS type-bound call reads no data of its base, but this branch now requires the base to be listed. This compiled before this revision:

```fortran
module m
  type :: t
    real :: b(10)
  contains
    procedure, nopass :: f
  end type
contains
  real function f(i)
    integer, intent(in) :: i
    !$acc routine seq
    f = real(i)
  end function
end module

subroutine s(x, r)
  use m
  type(t) :: x
  real :: r
  !$acc parallel default(none) copyout(r)
  r = x%f(1)
  !$acc end parallel
end subroutine
```

```console
$ flang -fc1 -fopenacc -fsyntax-only nopass_call.f90
nopass_call.f90:20:7: error: The DEFAULT(NONE) clause requires that 'x' must be listed in a data-mapping clause
```

Suggested gate: skip the base-object check only when the binding is statically resolvable — NOPASS and (non-polymorphic base or NON_OVERRIDABLE) and not a procedure-pointer component. Keeping the error for PASS bindings, for polymorphic bases (a NOPASS call on a `class(t)` base still reads the descriptor for dispatch), and for procedure-pointer components looks right — the procedure-pointer rejection this revision adds is a genuine fix and deserves its own test.

https://github.com/llvm/llvm-project/pull/220781


More information about the flang-commits mailing list