[flang-commits] [flang] [flang] Fix parse error on !$ACC ROUTINE (PR #175856)
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 13 14:16:20 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
!$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.
---
Full diff: https://github.com/llvm/llvm-project/pull/175856.diff
2 Files Affected:
- (modified) flang/lib/Parser/program-parsers.cpp (+1-1)
- (added) flang/test/Parser/acc-routine.f90 (+8)
``````````diff
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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/175856
More information about the flang-commits
mailing list