[flang-commits] [flang] 1c2935a - [flang] Prohibit MODULE procedures in the global scope
Peter Steinfeld via flang-commits
flang-commits at lists.llvm.org
Wed Mar 3 11:51:20 PST 2021
Author: Peter Steinfeld
Date: 2021-03-03T11:50:50-08:00
New Revision: 1c2935a7729fdc22186fa0a21968061a7f52f021
URL: https://github.com/llvm/llvm-project/commit/1c2935a7729fdc22186fa0a21968061a7f52f021
DIFF: https://github.com/llvm/llvm-project/commit/1c2935a7729fdc22186fa0a21968061a7f52f021.diff
LOG: [flang] Prohibit MODULE procedures in the global scope
We were allowing procedures with the MODULE prefix to be declared at the global
scope. This is prohibited by C1547 and was causing an internal check of the
compiler to fail.
I fixed this by adding a check. I also added a test that would trigger a crash
without this change.
Differential Revision: https://reviews.llvm.org/D97875
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 dd8acaa009ab..df358d880445 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3157,6 +3157,13 @@ bool SubprogramVisitor::BeginMpSubprogram(const parser::Name &name) {
// A subprogram declared with SUBROUTINE or FUNCTION
bool SubprogramVisitor::BeginSubprogram(
const parser::Name &name, Symbol::Flag subpFlag, bool hasModulePrefix) {
+ if (hasModulePrefix && currScope().IsGlobal()) { // C1547
+ Say(name,
+ "'%s' is a MODULE procedure which must be declared within a "
+ "MODULE or SUBMODULE"_err_en_US);
+ return false;
+ }
+
if (hasModulePrefix && !inInterfaceBlock() &&
!IsSeparateModuleProcedureInterface(
FindSymbol(currScope().parent(), name))) {
diff --git a/flang/test/Semantics/resolve36.f90 b/flang/test/Semantics/resolve36.f90
index 8a66d718aa89..38bc21dbd201 100644
--- a/flang/test/Semantics/resolve36.f90
+++ b/flang/test/Semantics/resolve36.f90
@@ -2,6 +2,9 @@
! C1568 The procedure-name shall have been declared to be a separate module
! procedure in the containing program unit or an ancestor of that program unit.
+! C1547 MODULE shall appear only in the function-stmt or subroutine-stmt of a
+! module subprogram or of a nonabstract interface body that is declared in the
+! scoping unit of a module or submodule.
module m1
interface
module subroutine sub1(arg1)
@@ -89,3 +92,8 @@ module subroutine b
module procedure b
end procedure
end
+
+!ERROR: 'c1547' is a MODULE procedure which must be declared within a MODULE or SUBMODULE
+real module function c1547()
+ func = 0.0
+end function
More information about the flang-commits
mailing list