Skip to content

[flang] silence bogus error with BIND(C) variable in hermetic module #143737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2958,6 +2958,14 @@ static std::optional<std::string> 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)}) {
Expand All @@ -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<ModuleDetails>()) {
Warn(common::LanguageFeature::BenignNameClash, symbol.name(),
"Module '%s' conflicts with a global name"_port_en_US,
Expand Down
24 changes: 24 additions & 0 deletions flang/test/Semantics/modfile76.F90
Original file line number Diff line number Diff line change
@@ -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
Loading