Skip to content

Commit 2ba94bf

Browse files
authored
[flang] Downgrade a too-strong error message to a warning (#80095)
When a compilation unit has an interface to an external subroutine or function, and there is a global object (like a module) with the same name, we're emitting an error. This is too strong, the program will still build. This comes up in real applications, too. Downgrade the error to a warning.
1 parent 6086007 commit 2ba94bf

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

flang/include/flang/Common/Fortran-features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
5454
ShortCharacterActual, ExprPassedToVolatile, ImplicitInterfaceActual,
5555
PolymorphicTransferArg, PointerComponentTransferArg, TransferSizePresence,
5656
F202XAllocatableBreakingChange, DimMustBePresent, CommonBlockPadding,
57-
LogicalVsCBool, BindCCharLength, ProcDummyArgShapes)
57+
LogicalVsCBool, BindCCharLength, ProcDummyArgShapes, ExternalNameConflict)
5858

5959
using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
6060
using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,10 +1465,11 @@ void CheckHelper::CheckExternal(const Symbol &symbol) {
14651465
if (interfaceName == definitionName) {
14661466
parser::Message *msg{nullptr};
14671467
if (!IsProcedure(*global)) {
1468-
if (symbol.flags().test(Symbol::Flag::Function) ||
1469-
symbol.flags().test(Symbol::Flag::Subroutine)) {
1470-
msg = messages_.Say(
1471-
"The global entity '%s' corresponding to the local procedure '%s' is not a callable subprogram"_err_en_US,
1468+
if ((symbol.flags().test(Symbol::Flag::Function) ||
1469+
symbol.flags().test(Symbol::Flag::Subroutine)) &&
1470+
context_.ShouldWarn(common::UsageWarning::ExternalNameConflict)) {
1471+
msg = WarnIfNotInModuleFile(
1472+
"The global entity '%s' corresponding to the local procedure '%s' is not a callable subprogram"_warn_en_US,
14721473
global->name(), symbol.name());
14731474
}
14741475
} else if (auto chars{Characterize(symbol)}) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
22

33
module module_before_1
44
end
@@ -46,19 +46,19 @@ function implicit_func_before_2(a)
4646

4747
program test
4848
external justfine ! OK to name a BLOCK DATA if not called
49-
!ERROR: The global entity 'module_before_1' corresponding to the local procedure 'module_before_1' is not a callable subprogram
49+
!WARNING: The global entity 'module_before_1' corresponding to the local procedure 'module_before_1' is not a callable subprogram
5050
external module_before_1
51-
!ERROR: The global entity 'block_data_before_1' corresponding to the local procedure 'block_data_before_1' is not a callable subprogram
51+
!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
5353
!ERROR: The global subprogram 'explicit_before_1' may not be referenced via the implicit interface 'explicit_before_1'
5454
external explicit_before_1
5555
external implicit_before_1
5656
!ERROR: The global subprogram 'explicit_func_before_1' may not be referenced via the implicit interface 'explicit_func_before_1'
5757
external explicit_func_before_1
5858
external implicit_func_before_1
59-
!ERROR: The global entity 'module_after_1' corresponding to the local procedure 'module_after_1' is not a callable subprogram
59+
!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
61-
!ERROR: The global entity 'block_data_after_1' corresponding to the local procedure 'block_data_after_1' is not a callable subprogram
61+
!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
6363
!ERROR: The global subprogram 'explicit_after_1' may not be referenced via the implicit interface 'explicit_after_1'
6464
external explicit_after_1

0 commit comments

Comments
 (0)