Skip to content

Commit 1c2935a

Browse files
committed
[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
1 parent 83c56aa commit 1c2935a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,13 @@ bool SubprogramVisitor::BeginMpSubprogram(const parser::Name &name) {
31573157
// A subprogram declared with SUBROUTINE or FUNCTION
31583158
bool SubprogramVisitor::BeginSubprogram(
31593159
const parser::Name &name, Symbol::Flag subpFlag, bool hasModulePrefix) {
3160+
if (hasModulePrefix && currScope().IsGlobal()) { // C1547
3161+
Say(name,
3162+
"'%s' is a MODULE procedure which must be declared within a "
3163+
"MODULE or SUBMODULE"_err_en_US);
3164+
return false;
3165+
}
3166+
31603167
if (hasModulePrefix && !inInterfaceBlock() &&
31613168
!IsSeparateModuleProcedureInterface(
31623169
FindSymbol(currScope().parent(), name))) {

flang/test/Semantics/resolve36.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
! C1568 The procedure-name shall have been declared to be a separate module
44
! procedure in the containing program unit or an ancestor of that program unit.
5+
! C1547 MODULE shall appear only in the function-stmt or subroutine-stmt of a
6+
! module subprogram or of a nonabstract interface body that is declared in the
7+
! scoping unit of a module or submodule.
58
module m1
69
interface
710
module subroutine sub1(arg1)
@@ -89,3 +92,8 @@ module subroutine b
8992
module procedure b
9093
end procedure
9194
end
95+
96+
!ERROR: 'c1547' is a MODULE procedure which must be declared within a MODULE or SUBMODULE
97+
real module function c1547()
98+
func = 0.0
99+
end function

0 commit comments

Comments
 (0)