[flang-commits] [flang] [flang] Reject MODULE prefix in abstract interface body (PR #212980)
via flang-commits
flang-commits at lists.llvm.org
Sun Aug 2 21:58:55 PDT 2026
https://github.com/ejose02 updated https://github.com/llvm/llvm-project/pull/212980
>From e3d01ec9127f18271ad0844d557ff723a56ce2b2 Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Thu, 30 Jul 2026 09:45:23 +0000
Subject: [PATCH 1/2] [flang] Reject MODULE prefix in abstract interface body
Diagnose MODULE on a procedure in an ABSTRACT INTERFACE block per Fortran C1547 (R1526, J3/18-007r1): MODULE may appear only in a module subprogram or a nonabstract interface body in a module/submodule.
Fixes #208200
---
flang/lib/Semantics/resolve-names.cpp | 5 +++++
flang/test/Semantics/resolve36.f90 | 9 +++++++++
2 files changed, 14 insertions(+)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3f2d97bfc7bef..30460d1fbda41 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5630,6 +5630,11 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
// other semantic checks run before we print the errors
isValid = false;
}
+ if (hasModulePrefix && inInterfaceBlock() && isAbstract()) { // C1547
+ Say(name,
+ "'%s' has MODULE prefix, which is not allowed in an ABSTRACT interface body"_err_en_US);
+ isValid = false;
+ }
Symbol *moduleInterface{nullptr};
if (isValid && hasModulePrefix && !inInterfaceBlock()) {
moduleInterface = FindSeparateModuleProcedureInterface(name);
diff --git a/flang/test/Semantics/resolve36.f90 b/flang/test/Semantics/resolve36.f90
index bdb1b227f61ce..b3aed359c04fb 100644
--- a/flang/test/Semantics/resolve36.f90
+++ b/flang/test/Semantics/resolve36.f90
@@ -97,3 +97,12 @@ module subroutine b
real module function c1547()
func = 0.0
end function
+
+module mod_test
+abstract interface
+ !ERROR: 'f1' has MODULE prefix, which is not allowed in an ABSTRACT interface body
+ pure integer module function f1(i)
+ integer, intent(in) :: i
+ end function
+end interface
+end module
>From 4677249e1ffac31c523ca1f3ce8b7c4624b23db3 Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Mon, 3 Aug 2026 04:56:28 +0000
Subject: [PATCH 2/2] Address review concern for MODULE prefix in abstract
interface
Updated the C1547 diagnostic to use flang's usual "may not have" wording.
Renamed the test module to m5 and extend resolve36.f90 with a module subroutine case and an abstract-interface-in-submodule case.
---
flang/lib/Semantics/resolve-names.cpp | 2 +-
flang/test/Semantics/resolve36.f90 | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 30460d1fbda41..4a3203458c42a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5632,7 +5632,7 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
}
if (hasModulePrefix && inInterfaceBlock() && isAbstract()) { // C1547
Say(name,
- "'%s' has MODULE prefix, which is not allowed in an ABSTRACT interface body"_err_en_US);
+ "'%s' may not have a MODULE prefix in an ABSTRACT interface body"_err_en_US);
isValid = false;
}
Symbol *moduleInterface{nullptr};
diff --git a/flang/test/Semantics/resolve36.f90 b/flang/test/Semantics/resolve36.f90
index b3aed359c04fb..348b5f6cc4ff8 100644
--- a/flang/test/Semantics/resolve36.f90
+++ b/flang/test/Semantics/resolve36.f90
@@ -98,11 +98,26 @@ real module function c1547()
func = 0.0
end function
-module mod_test
+module m5
abstract interface
- !ERROR: 'f1' has MODULE prefix, which is not allowed in an ABSTRACT interface body
+ !ERROR: 'f1' may not have a MODULE prefix in an ABSTRACT interface body
pure integer module function f1(i)
integer, intent(in) :: i
end function
+ !ERROR: 's1' may not have a MODULE prefix in an ABSTRACT interface body
+ module subroutine s1(i)
+ integer, intent(in) :: i
+ end subroutine
end interface
end module
+
+module m6
+end module
+submodule(m6) s6
+abstract interface
+ !ERROR: 'f2' may not have a MODULE prefix in an ABSTRACT interface body
+ module function f2()
+ integer :: f2
+ end function
+end interface
+end submodule
More information about the flang-commits
mailing list