Skip to content

Commit

Permalink
[flang] Downgrade a too-strong error message to a warning (llvm#80095)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klausler authored and Carlos Gálvez committed Feb 1, 2024
1 parent 3aba4c7 commit 6c66b9f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion flang/include/flang/Common/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
ShortCharacterActual, ExprPassedToVolatile, ImplicitInterfaceActual,
PolymorphicTransferArg, PointerComponentTransferArg, TransferSizePresence,
F202XAllocatableBreakingChange, DimMustBePresent, CommonBlockPadding,
LogicalVsCBool, BindCCharLength, ProcDummyArgShapes)
LogicalVsCBool, BindCCharLength, ProcDummyArgShapes, ExternalNameConflict)

using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;
Expand Down
9 changes: 5 additions & 4 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,10 +1465,11 @@ void CheckHelper::CheckExternal(const Symbol &symbol) {
if (interfaceName == definitionName) {
parser::Message *msg{nullptr};
if (!IsProcedure(*global)) {
if (symbol.flags().test(Symbol::Flag::Function) ||
symbol.flags().test(Symbol::Flag::Subroutine)) {
msg = messages_.Say(
"The global entity '%s' corresponding to the local procedure '%s' is not a callable subprogram"_err_en_US,
if ((symbol.flags().test(Symbol::Flag::Function) ||
symbol.flags().test(Symbol::Flag::Subroutine)) &&
context_.ShouldWarn(common::UsageWarning::ExternalNameConflict)) {
msg = WarnIfNotInModuleFile(
"The global entity '%s' corresponding to the local procedure '%s' is not a callable subprogram"_warn_en_US,
global->name(), symbol.name());
}
} else if (auto chars{Characterize(symbol)}) {
Expand Down
10 changes: 5 additions & 5 deletions flang/test/Semantics/local-vs-global.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic

module module_before_1
end
Expand Down Expand Up @@ -46,19 +46,19 @@ function implicit_func_before_2(a)

program test
external justfine ! OK to name a BLOCK DATA if not called
!ERROR: The global entity 'module_before_1' corresponding to the local procedure 'module_before_1' is not a callable subprogram
!WARNING: The global entity 'module_before_1' corresponding to the local procedure 'module_before_1' is not a callable subprogram
external module_before_1
!ERROR: The global entity 'block_data_before_1' corresponding to the local procedure 'block_data_before_1' is not a callable subprogram
!WARNING: The global entity 'block_data_before_1' corresponding to the local procedure 'block_data_before_1' is not a callable subprogram
external block_data_before_1
!ERROR: The global subprogram 'explicit_before_1' may not be referenced via the implicit interface 'explicit_before_1'
external explicit_before_1
external implicit_before_1
!ERROR: The global subprogram 'explicit_func_before_1' may not be referenced via the implicit interface 'explicit_func_before_1'
external explicit_func_before_1
external implicit_func_before_1
!ERROR: The global entity 'module_after_1' corresponding to the local procedure 'module_after_1' is not a callable subprogram
!WARNING: The global entity 'module_after_1' corresponding to the local procedure 'module_after_1' is not a callable subprogram
external module_after_1
!ERROR: The global entity 'block_data_after_1' corresponding to the local procedure 'block_data_after_1' is not a callable subprogram
!WARNING: The global entity 'block_data_after_1' corresponding to the local procedure 'block_data_after_1' is not a callable subprogram
external block_data_after_1
!ERROR: The global subprogram 'explicit_after_1' may not be referenced via the implicit interface 'explicit_after_1'
external explicit_after_1
Expand Down

0 comments on commit 6c66b9f

Please sign in to comment.