Skip to content

Commit 8ed8210

Browse files
authored
[flang] Downgrade error message to warning (llvm#108115)
It is a non-mandatory error to reference an external procedure via an implicit interface declaration (EXTERNAL or PROCEDURE()) when the external procedure has an interface that requires the presence of an explicit interface to be called. Until now, the compiler has issued a fatal error message from semantics for this situation. But (1) there are situations, such as passing such an EXTERNAL as an actual argument, or as the target of a procedure pointer assignment, where little or no harm is done, (2) other compilers don't/can't detect this error, even when the procedure's definition is in the same source file, and (3) it shows up in some real applications. So downgrade this error to a stern warning. Perhaps in the future the compiler could resume emission of a hard error in the cases where the EXTERNAL procedure is actually known to be called via its implicit interface.
1 parent c6ca13d commit 8ed8210

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,11 @@ void CheckHelper::CheckExternal(const Symbol &symbol) {
15871587
} else if (!globalChars->CanBeCalledViaImplicitInterface() &&
15881588
context_.ShouldWarn(
15891589
common::UsageWarning::ExternalInterfaceMismatch)) {
1590-
msg = messages_.Say(
1591-
"The global subprogram '%s' may not be referenced via the implicit interface '%s'"_err_en_US,
1590+
// TODO: This should be a hard error if the procedure has
1591+
// actually been called (as opposed to just being used as a
1592+
// procedure pointer target or passed as an actual argument).
1593+
msg = WarnIfNotInModuleFile(
1594+
"The global subprogram '%s' should not be referenced via the implicit interface '%s'"_warn_en_US,
15921595
global->name(), symbol.name());
15931596
}
15941597
}

flang/test/Semantics/local-vs-global.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ program test
5050
external module_before_1
5151
!WARNING: The global entity 'block_data_before_1' corresponding to the local procedure 'block_data_before_1' is not a callable subprogram
5252
external block_data_before_1
53-
!ERROR: The global subprogram 'explicit_before_1' may not be referenced via the implicit interface 'explicit_before_1'
53+
!WARNING: The global subprogram 'explicit_before_1' should not be referenced via the implicit interface 'explicit_before_1'
5454
external explicit_before_1
5555
external implicit_before_1
56-
!ERROR: The global subprogram 'explicit_func_before_1' may not be referenced via the implicit interface 'explicit_func_before_1'
56+
!WARNING: The global subprogram 'explicit_func_before_1' should not be referenced via the implicit interface 'explicit_func_before_1'
5757
external explicit_func_before_1
5858
external implicit_func_before_1
5959
!WARNING: The global entity 'module_after_1' corresponding to the local procedure 'module_after_1' is not a callable subprogram
6060
external module_after_1
6161
!WARNING: The global entity 'block_data_after_1' corresponding to the local procedure 'block_data_after_1' is not a callable subprogram
6262
external block_data_after_1
63-
!ERROR: The global subprogram 'explicit_after_1' may not be referenced via the implicit interface 'explicit_after_1'
63+
!WARNING: The global subprogram 'explicit_after_1' should not be referenced via the implicit interface 'explicit_after_1'
6464
external explicit_after_1
6565
external implicit_after_1
66-
!ERROR: The global subprogram 'explicit_func_after_1' may not be referenced via the implicit interface 'explicit_func_after_1'
66+
!WARNING: The global subprogram 'explicit_func_after_1' should not be referenced via the implicit interface 'explicit_func_after_1'
6767
external explicit_func_after_1
6868
external implicit_func_after_1
6969
call module_before_1

0 commit comments

Comments
 (0)