[flang-commits] [flang] [flang] Fix parse error on !$ACC ROUTINE (PR #175856)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Jan 13 14:15:45 PST 2026
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/175856
!$ACC ROUTINE is allowed to appear between program units, but we fail to parse it when it is not followed by one, because its parser in program-parsers.cpp doesn't consume the end of the line. Fix.
>From 9b770fe5875b339df239e4431f1dc1ed0d194d1b Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 13 Jan 2026 14:13:45 -0800
Subject: [PATCH] [flang] Fix parse error on !$ACC ROUTINE
!$ACC ROUTINE is allowed to appear between program units,
but we fail to parse it when it is not followed by one,
because its parser in program-parsers.cpp doesn't consume
the end of the line. Fix.
---
flang/lib/Parser/program-parsers.cpp | 2 +-
flang/test/Parser/acc-routine.f90 | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Parser/acc-routine.f90
diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index 303335934a37a..569224b9d23e8 100644
--- a/flang/lib/Parser/program-parsers.cpp
+++ b/flang/lib/Parser/program-parsers.cpp
@@ -77,7 +77,7 @@ static constexpr auto globalCompilerDirective{
static constexpr auto globalOpenACCCompilerDirective{
construct<ProgramUnit>(indirect(skipStuffBeforeStatement >>
- "!$ACC "_sptok >> Parser<OpenACCRoutineConstruct>{}))};
+ "!$ACC "_sptok >> Parser<OpenACCRoutineConstruct>{} / endOfLine))};
// R501 program -> program-unit [program-unit]...
// This is the top-level production for the Fortran language.
diff --git a/flang/test/Parser/acc-routine.f90 b/flang/test/Parser/acc-routine.f90
new file mode 100644
index 0000000000000..a73e0d62ceb4a
--- /dev/null
+++ b/flang/test/Parser/acc-routine.f90
@@ -0,0 +1,8 @@
+! RUN: %flang_fc1 -fopenacc -fdebug-unparse %s | FileCheck %s
+CHECK: !$ACC ROUTINE(square) BIND(asdf)
+
+function square(x)
+ square = x * x
+end
+
+!$acc routine(square) bind(asdf)
More information about the flang-commits
mailing list