[flang-commits] [flang] [flang] Reject MODULE prefix in abstract interface body (PR #212980)

via flang-commits flang-commits at lists.llvm.org
Tue Oct 6 00:14:42 PDT 2026


https://github.com/ejose02 updated https://github.com/llvm/llvm-project/pull/212980

>From ff11655267dca6478c94c1b1af495be112dc9f60 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 67690d6f47d06..09a51800947e4 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5919,6 +5919,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 d1c76de3049cb2ce6b11fba703a8fe9470fdcbea 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 09a51800947e4..fc3de93b25c02 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5921,7 +5921,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