[flang-commits] [flang] [flang][openacc] Ignore bare acc routine in module subprogram part instead of erroring out (PR #205450)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Tue Jun 23 19:09:29 PDT 2026


================
@@ -88,6 +88,26 @@ static constexpr auto globalOpenACCCompilerDirective{
     construct<ProgramUnit>(indirect(skipStuffBeforeStatement >>
         "!$ACC "_sptok >> Parser<OpenACCRoutineConstruct>{} / endOfLine))};
 
+struct WarnUnnamedOpenACCRoutineDirective {
+  using resultType = Success;
+  std::optional<Success> Parse(ParseState &state) const {
+    state.Say("OpenACC routine directive without name must be placed in a "
+              "subroutine or function"_warn_en_US);
+    return {Success{}};
+  }
+};
+static constexpr WarnUnnamedOpenACCRoutineDirective
+    warnUnnamedOpenACCRoutineDirective;
+
+// In a module-subprogram-part, a bare `!$ACC ROUTINE` line (without a name)
+// cannot be attached to a specific routine. Accept and ignore it so parsing
+// can continue to the following subprogram.
+static constexpr auto ignoredBareRoutineOpenACCDirective{
+    ((skipStuffBeforeStatement >> "!$ACC "_sptok >>
+         "ROUTINE"_tok / endOfLine) >>
+        warnUnnamedOpenACCRoutineDirective) >>
+    construct<CompilerDirective>(pure<CompilerDirective::Unrecognized>())};
----------------
eugeneepshteyn wrote:

Hmm, how is this unparsed (e.g., when saved in a module)?  Definitely need a semantic test for the unparsing case.

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


More information about the flang-commits mailing list