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

via flang-commits flang-commits at lists.llvm.org
Wed Oct 7 21:12:30 PDT 2026


Author: ejose02
Date: 2026-10-08T09:42:26+05:30
New Revision: d9f4c2ded1df90f93f8bf705d2895646292adffc

URL: https://github.com/llvm/llvm-project/commit/d9f4c2ded1df90f93f8bf705d2895646292adffc
DIFF: https://github.com/llvm/llvm-project/commit/d9f4c2ded1df90f93f8bf705d2895646292adffc.diff

LOG: [flang] Reject MODULE prefix in abstract interface body (#212980)

Issue: Flang accepts a MODULE prefix on a function or subroutine inside
an ABSTRACT INTERFACE. C1547 allows MODULE only on a module subprogram,
or on a nonabstract interface body in a module or submodule.

Fixes #208200

Root cause
- BeginSubprogram() only enforced the module/submodule half of C1547. An
abstract interface inside a module or submodule still has that scope, so
the check passed.
- In PushSubprogramScope(), an abstract interface body takes the
isAbstract() path, sets ABSTRACT, and never looks at hasModulePrefix, so
the prefix was ignored with no diagnostic.
```
if (isAbstract()) {
  SetExplicitAttr(*symbol, Attr::ABSTRACT);
} else if (hasModulePrefix) {
  SetExplicitAttr(*symbol, Attr::MODULE);
} else {
  MakeExternal(*symbol);
}
```

Fix
- BeginSubprogram() now reports an error when hasModulePrefix,
inInterfaceBlock(), and isAbstract() are all true.
- The message is '%s' may not have a MODULE prefix in an ABSTRACT
interface body. The check does not return, so the subprogram scope is
still built.
- resolve36.f90 covers a module function and a module subroutine in a
module abstract interface, and a module function in a submodule abstract
interface.
```
if (hasModulePrefix && inInterfaceBlock() && isAbstract()) { // C1547
  Say(name,
      "'%s' may not have a MODULE prefix in an ABSTRACT interface body"_err_en_US);
  isValid = false;
}
```

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve36.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 67690d6f47d06..9b7f3a2c2f0c6 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5911,7 +5911,11 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
     const parser::LanguageBindingSpec *bindingSpec,
     const ProgramTree::EntryStmtList *entryStmts) {
   bool isValid{true};
-  if (hasModulePrefix && !currScope().IsModule() &&
+  if (hasModulePrefix && isAbstract()) { // C1547
+    Say(name,
+        "'%s' may not have a MODULE prefix in an ABSTRACT interface body"_err_en_US);
+    isValid = false;
+  } else if (hasModulePrefix && !currScope().IsModule() &&
       !currScope().IsSubmodule()) { // C1547
     Say(name,
         "'%s' is a MODULE procedure which must be declared within a MODULE or SUBMODULE"_err_en_US);

diff  --git a/flang/test/Semantics/resolve36.f90 b/flang/test/Semantics/resolve36.f90
index bdb1b227f61ce..eedbe574290de 100644
--- a/flang/test/Semantics/resolve36.f90
+++ b/flang/test/Semantics/resolve36.f90
@@ -97,3 +97,36 @@ module subroutine b
 real module function c1547()
   func = 0.0
 end function
+
+module m5
+abstract interface
+  !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
+
+program p
+abstract interface
+  !ERROR: 'f4' may not have a MODULE prefix in an ABSTRACT interface body
+  module function f4()
+    integer :: f4
+  end function
+end interface
+end program


        


More information about the flang-commits mailing list