Skip to content

Commit 88a097d

Browse files
committed
[flang] Diagnose bad attributes of implicit interface externals
Procedures with the EXTERNAL attribute (explicit or implied) are not permitted to be ALLOCATABLE or be arrays if their interfaces are implicit. Differential Revision: https://reviews.llvm.org/D146572
1 parent 57e1943 commit 88a097d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ void CheckHelper::Check(const Symbol &symbol) {
426426
" of a module"_err_en_US,
427427
symbol.name());
428428
}
429+
if (IsProcedure(symbol) && !symbol.HasExplicitInterface()) {
430+
if (IsAllocatable(symbol)) {
431+
messages_.Say(
432+
"Procedure '%s' may not be ALLOCATABLE without an explicit interface"_err_en_US,
433+
symbol.name());
434+
} else if (symbol.Rank() > 0) {
435+
messages_.Say(
436+
"Procedure '%s' may not be an array without an explicit interface"_err_en_US,
437+
symbol.name());
438+
}
439+
}
429440
}
430441

431442
void CheckHelper::CheckCommonBlock(const Symbol &symbol) {
@@ -916,7 +927,7 @@ void CheckHelper::CheckProcEntity(
916927
}
917928
CheckPassArg(symbol, details.procInterface(), details);
918929
}
919-
if (symbol.attrs().test(Attr::POINTER)) {
930+
if (IsPointer(symbol)) {
920931
CheckPointerInitialization(symbol);
921932
if (const Symbol * interface{details.procInterface()}) {
922933
const Symbol &ultimate{interface->GetUltimate()};
@@ -936,7 +947,7 @@ void CheckHelper::CheckProcEntity(
936947
symbol.name()); // C1517
937948
}
938949
}
939-
} else if (symbol.attrs().test(Attr::SAVE)) {
950+
} else if (IsSave(symbol)) {
940951
messages_.Say(
941952
"Procedure '%s' with SAVE attribute must also have POINTER attribute"_err_en_US,
942953
symbol.name());

flang/test/Semantics/call05.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ subroutine test
121121

122122
module m2
123123

124+
!ERROR: Procedure 't3' may not be ALLOCATABLE without an explicit interface
124125
character(len=10), allocatable :: t1, t2, t3, t4
126+
!ERROR: Procedure 't6' may not be ALLOCATABLE without an explicit interface
125127
character(len=:), allocatable :: t5, t6, t7, t8(:)
126128

127129
character(len=10), pointer :: p1

flang/test/Semantics/resolve20.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ subroutine foo2
2121
procedure(h) :: i
2222
procedure(forward) :: j
2323
!ERROR: 'bad1' must be an abstract interface or a procedure with an explicit interface
24+
!ERROR: Procedure 'k1' may not be an array without an explicit interface
2425
procedure(bad1) :: k1
2526
!ERROR: 'bad2' must be an abstract interface or a procedure with an explicit interface
2627
procedure(bad2) :: k2

0 commit comments

Comments
 (0)