[PATCH] D97875: [flang] Prohibit MODULE procedures in the global scope

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 3 11:51:33 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c2935a7729f: [flang] Prohibit MODULE procedures in the global scope (authored by PeteSteinfeld).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97875/new/

https://reviews.llvm.org/D97875

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


Index: flang/test/Semantics/resolve36.f90
===================================================================
--- flang/test/Semantics/resolve36.f90
+++ 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 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
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -3157,6 +3157,13 @@
 // 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))) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97875.327873.patch
Type: text/x-patch
Size: 1593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210303/5fd94987/attachment.bin>


More information about the llvm-commits mailing list