[flang-commits] [flang] [Flang][Parser] Handle compiler directives inside INTERFACE blocks (PR #198516)
CHANDRA GHALE via flang-commits
flang-commits at lists.llvm.org
Tue May 19 05:54:06 PDT 2026
https://github.com/chandraghale created https://github.com/llvm/llvm-project/pull/198516
Unrecognized !DIR$ directives between interface specifications currently cause cascading parse errors because the grammar for InterfaceSpecification has no path to consume them. This patch adds CompilerDirective as a valid alternative — matching how InternalSubprogram and ModuleSubprogram already handle this — so that unrecognized directives produce the expected warning instead of a fatal parse failure.
Fixes : [https://github.com/llvm/llvm-project/issues/198289](https://github.com/llvm/llvm-project/issues/198289)
>From c97d7064bea5cd9d0be35aac83e7ccf82b2099c8 Mon Sep 17 00:00:00 2001
From: Chandra Ghale <ghale at pe34genoa.hpc.amslabs.hpecorp.net>
Date: Tue, 19 May 2026 07:51:49 -0500
Subject: [PATCH] Handle compiler directives inside INTERFACE blocks
---
flang/include/flang/Parser/parse-tree.h | 4 ++-
flang/lib/Parser/program-parsers.cpp | 3 ++-
.../compiler-directive-in-interface.f90 | 25 +++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
create mode 100644 flang/test/Parser/compiler-directive-in-interface.f90
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 28a565d7e27f8..8505ad2c50227 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3195,7 +3195,9 @@ struct ProcedureStmt {
// R1502 interface-specification -> interface-body | procedure-stmt
struct InterfaceSpecification {
UNION_CLASS_BOILERPLATE(InterfaceSpecification);
- std::variant<InterfaceBody, Statement<ProcedureStmt>> u;
+ std::variant<InterfaceBody, Statement<ProcedureStmt>,
+ common::Indirection<CompilerDirective>>
+ u;
};
// R1504 end-interface-stmt -> END INTERFACE [generic-spec]
diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index b4e56213d9f02..048255898022c 100644
--- a/flang/lib/Parser/program-parsers.cpp
+++ b/flang/lib/Parser/program-parsers.cpp
@@ -373,7 +373,8 @@ TYPE_PARSER(construct<InterfaceBlock>(statement(Parser<InterfaceStmt>{}),
// R1502 interface-specification -> interface-body | procedure-stmt
TYPE_PARSER(construct<InterfaceSpecification>(Parser<InterfaceBody>{}) ||
- construct<InterfaceSpecification>(statement(Parser<ProcedureStmt>{})))
+ construct<InterfaceSpecification>(statement(Parser<ProcedureStmt>{})) ||
+ construct<InterfaceSpecification>(indirect(compilerDirective)))
// R1503 interface-stmt -> INTERFACE [generic-spec] | ABSTRACT INTERFACE
TYPE_PARSER(construct<InterfaceStmt>("INTERFACE" >> maybe(genericSpec)) ||
diff --git a/flang/test/Parser/compiler-directive-in-interface.f90 b/flang/test/Parser/compiler-directive-in-interface.f90
new file mode 100644
index 0000000000000..77c3053b757b9
--- /dev/null
+++ b/flang/test/Parser/compiler-directive-in-interface.f90
@@ -0,0 +1,25 @@
+! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+! Test that unrecognized compiler directives inside INTERFACE blocks
+! produce a warning rather than a parse error.
+
+module m
+ interface
+ subroutine ccff
+ end subroutine ccff
+!CHECK: warning: Unrecognized compiler directive was ignored
+ !dir$ id "test"
+ end interface
+end module
+
+module m2
+ interface
+!CHECK: warning: Unrecognized compiler directive was ignored
+ !dir$ id "test"
+ subroutine foo(a)
+ integer, intent(in) :: a
+ end subroutine foo
+ end interface
+end module
+
+
More information about the flang-commits
mailing list