[flang-commits] [flang] [flang][acc] Reject generic interface name in acc routine (PR #211269)

Razvan Lupusoru via flang-commits flang-commits at lists.llvm.org
Wed Jul 22 07:06:25 PDT 2026


https://github.com/razvanlupusoru created https://github.com/llvm/llvm-project/pull/211269

OpenACC ties the named argument of a ROUTINE directive to a subroutine or function. A generic interface name is therefore not a valid target. Thus adding an explicit check for this plus informational error message.

>From e6eaf73bf5d35863c12c4a91deb037002efd8020 Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Wed, 22 Jul 2026 07:05:06 -0700
Subject: [PATCH] [flang][acc] Reject generic interface name in acc routine

OpenACC ties the named argument of a ROUTINE directive to a
subroutine or function. A generic interface name is therefore not a
valid target. Thus adding an explicit check for this plus
informational error message.
---
 flang/lib/Semantics/resolve-directives.cpp    | 11 ++++++-
 .../Semantics/OpenACC/acc-routine-generic.f90 | 33 +++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/OpenACC/acc-routine-generic.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 51ad81bcbc2ef..cb710cdbb4589 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1425,7 +1425,16 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
     for (const auto &name : names) {
       if (Symbol * sym{ResolveFctName(name)}) {
         Symbol &ultimate{sym->GetUltimate()};
-        AddRoutineInfoToSymbol(ultimate, x);
+        // OpenACC ties the named argument of a ROUTINE directive to a
+        // subroutine or function. A generic interface name is therefore not a
+        // valid target.
+        if (ultimate.has<GenericDetails>()) {
+          context_.Say(name.source,
+              "A generic interface name may not appear in an ACC ROUTINE clause: %s"_err_en_US,
+              name.source);
+        } else {
+          AddRoutineInfoToSymbol(ultimate, x);
+        }
       } else {
         context_.Say(name.source,
             "No function or subroutine declared for '%s'"_err_en_US,
diff --git a/flang/test/Semantics/OpenACC/acc-routine-generic.f90 b/flang/test/Semantics/OpenACC/acc-routine-generic.f90
new file mode 100644
index 0000000000000..79804843f0a23
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-routine-generic.f90
@@ -0,0 +1,33 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenacc
+
+! A generic interface name is not a valid target of an OpenACC ROUTINE
+! directive. The name argument denotes a subroutine or function; the same
+! restriction appears in OpenMP for declare target procedure list items.
+
+module m1
+  interface foo
+    module procedure sbar, dbar
+  end interface
+  !ERROR: A generic interface name may not appear in an ACC ROUTINE clause: foo
+  !$acc routine(foo) seq
+contains
+  real function sbar(x)
+    real, intent(in) :: x
+    sbar = x
+  end function
+  double precision function dbar(x)
+    double precision, intent(in) :: x
+    dbar = x
+  end function
+end module
+
+program gen
+  use m1
+  real :: y = 1.0, z
+  !ERROR: A generic interface name may not appear in an ACC ROUTINE clause: foo
+  !$acc routine(foo) seq
+  !$acc parallel
+  z = foo(y)
+  !$acc end parallel
+  print *, z
+end program



More information about the flang-commits mailing list