From a0f40e5a64baa3ae70aeeae6a7956f156f2907f2 Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Wed, 11 Jun 2025 08:45:47 -0700 Subject: [PATCH] [flang] silence bogus error with BIND(C) variable in hermetic module --- flang/lib/Semantics/check-declarations.cpp | 10 +++++++++ flang/test/Semantics/modfile76.F90 | 24 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 flang/test/Semantics/modfile76.F90 diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 46a5b970fdf0c..f9d64485f1407 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -2958,6 +2958,14 @@ static std::optional DefinesGlobalName(const Symbol &symbol) { return std::nullopt; } +static bool IsSameSymbolFromHermeticModule( + const Symbol &symbol, const Symbol &other) { + return symbol.name() == other.name() && symbol.owner().IsModule() && + other.owner().IsModule() && symbol.owner() != other.owner() && + symbol.owner().GetName() && + symbol.owner().GetName() == other.owner().GetName(); +} + // 19.2 p2 void CheckHelper::CheckGlobalName(const Symbol &symbol) { if (auto global{DefinesGlobalName(symbol)}) { @@ -2975,6 +2983,8 @@ void CheckHelper::CheckGlobalName(const Symbol &symbol) { (!IsExternalProcedureDefinition(symbol) || !IsExternalProcedureDefinition(other))) { // both are procedures/BLOCK DATA, not both definitions + } else if (IsSameSymbolFromHermeticModule(symbol, other)) { + // Both symbols are the same thing. } else if (symbol.has()) { Warn(common::LanguageFeature::BenignNameClash, symbol.name(), "Module '%s' conflicts with a global name"_port_en_US, diff --git a/flang/test/Semantics/modfile76.F90 b/flang/test/Semantics/modfile76.F90 new file mode 100644 index 0000000000000..50ee9a088e119 --- /dev/null +++ b/flang/test/Semantics/modfile76.F90 @@ -0,0 +1,24 @@ +!RUN: %flang_fc1 -fsyntax-only -fhermetic-module-files -DSTEP=1 %s +!RUN: %flang_fc1 -fsyntax-only %s + +! Tests that a BIND(C) variable in a module A captured in a hermetic module +! file USE'd in a module B is not creating bogus complaints about BIND(C) name +! conflict when both module A and B are later accessed. + +#if STEP == 1 +module modfile75a + integer, bind(c) :: x +end + +module modfile75b + use modfile75a ! capture hermetically +end + +#else +subroutine test + use modfile75a + use modfile75b + implicit none + print *, x +end subroutine +#endif