[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));
+    }
----------------
eugeneepshteyn wrote:

(This comment was generated with the help of AI)

This fallback checks the bare base object, so a reference whose deepest representable prefix is itself listed in a data clause is now rejected. This compiled before this revision:

```fortran
subroutine s(c, r)
  character(5) :: c(3)
  character(2) :: r
  !$acc parallel default(none) copy(c(1)) copyout(r)
  r = c(1)(2:3)
  !$acc end parallel
end subroutine
```

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

The substring makes the path unrepresentable, but `c(1)` is representable and is exactly the covered object. Falling back to the deepest representable prefix instead of the bare base would accept this and keep rejecting genuinely uncovered references; the same applies to the other fallback call sites (the `FunctionReference` branch below and the `ArrayElement` one).

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


More information about the flang-commits mailing list