[flang-commits] [flang] b811df9 - [flang] Fix parse error on !$ACC ROUTINE (#175856)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 19 10:59:46 PST 2026


Author: Peter Klausler
Date: 2026-01-19T10:59:41-08:00
New Revision: b811df906e7884269050e46fd4d77946dedde5ed

URL: https://github.com/llvm/llvm-project/commit/b811df906e7884269050e46fd4d77946dedde5ed
DIFF: https://github.com/llvm/llvm-project/commit/b811df906e7884269050e46fd4d77946dedde5ed.diff

LOG: [flang] Fix parse error on !$ACC ROUTINE (#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.

Fixes https://github.com/llvm/llvm-project/issues/135964.

Added: 
    flang/test/Parser/bug135964.f90

Modified: 
    flang/lib/Parser/program-parsers.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index 36a9c00a4f30d..357bee0ad417d 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/bug135964.f90 b/flang/test/Parser/bug135964.f90
new file mode 100644
index 0000000000000..e582a918551eb
--- /dev/null
+++ b/flang/test/Parser/bug135964.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