[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:58:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: ejose02
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/212980.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+5)
- (modified) flang/test/Semantics/resolve36.f90 (+9)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/212980
More information about the flang-commits
mailing list