[flang-commits] [flang] [Flang][Parser] Handle compiler directives inside INTERFACE blocks (PR #198516)
via flang-commits
flang-commits at lists.llvm.org
Tue May 19 05:54:58 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: CHANDRA GHALE (chandraghale)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/198516.diff
3 Files Affected:
- (modified) flang/include/flang/Parser/parse-tree.h (+3-1)
- (modified) flang/lib/Parser/program-parsers.cpp (+2-1)
- (added) flang/test/Parser/compiler-directive-in-interface.f90 (+25)
``````````diff
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
+
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/198516
More information about the flang-commits
mailing list