[flang-commits] [flang] [flang] Reject MODULE prefix in abstract interface body (PR #212980)
via flang-commits
flang-commits at lists.llvm.org
Thu Jul 30 02:57:45 PDT 2026
https://github.com/ejose02 created https://github.com/llvm/llvm-project/pull/212980
Flang failed to diagnose an invalid MODULE prefix on a function or subroutine declared inside an ABSTRACT INTERFACE block. C1547 (R1526, J3/18-007r1) requires that MODULE appear only in a module subprogram or a nonabstract interface body declared in a module or submodule.
Flang accepted such code with no diagnostic. The root cause is that BeginSubprogram() in resolve-names.cpp enforced only the module/submodule scope part of C1547 and never checked whether the interface body was abstract. For abstract interfaces, the code took the isAbstract() path and silently skipped the MODULE prefix instead of reporting an error.
This patch adds a C1547 check to reject MODULE in this particular case. A semantics test is added in resolve36.f90
Fixes #208200
>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] [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
More information about the flang-commits
mailing list