Skip to content

Commit 621a7d0

Browse files
authored
[flang] silence bogus error with BIND(C) variable in hermetic module (#143737)
The global name semantic check was firing in a bogus way when BIND(C) variables are in hermetic module. Do not raise the error if one of the symbol with the conflicting global name is an "hermetic variant" of the other.
1 parent 370e54d commit 621a7d0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,14 @@ static std::optional<std::string> DefinesGlobalName(const Symbol &symbol) {
29582958
return std::nullopt;
29592959
}
29602960

2961+
static bool IsSameSymbolFromHermeticModule(
2962+
const Symbol &symbol, const Symbol &other) {
2963+
return symbol.name() == other.name() && symbol.owner().IsModule() &&
2964+
other.owner().IsModule() && symbol.owner() != other.owner() &&
2965+
symbol.owner().GetName() &&
2966+
symbol.owner().GetName() == other.owner().GetName();
2967+
}
2968+
29612969
// 19.2 p2
29622970
void CheckHelper::CheckGlobalName(const Symbol &symbol) {
29632971
if (auto global{DefinesGlobalName(symbol)}) {
@@ -2975,6 +2983,8 @@ void CheckHelper::CheckGlobalName(const Symbol &symbol) {
29752983
(!IsExternalProcedureDefinition(symbol) ||
29762984
!IsExternalProcedureDefinition(other))) {
29772985
// both are procedures/BLOCK DATA, not both definitions
2986+
} else if (IsSameSymbolFromHermeticModule(symbol, other)) {
2987+
// Both symbols are the same thing.
29782988
} else if (symbol.has<ModuleDetails>()) {
29792989
Warn(common::LanguageFeature::BenignNameClash, symbol.name(),
29802990
"Module '%s' conflicts with a global name"_port_en_US,

flang/test/Semantics/modfile76.F90

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
!RUN: %flang_fc1 -fsyntax-only -fhermetic-module-files -DSTEP=1 %s
2+
!RUN: %flang_fc1 -fsyntax-only %s
3+
4+
! Tests that a BIND(C) variable in a module A captured in a hermetic module
5+
! file USE'd in a module B is not creating bogus complaints about BIND(C) name
6+
! conflict when both module A and B are later accessed.
7+
8+
#if STEP == 1
9+
module modfile75a
10+
integer, bind(c) :: x
11+
end
12+
13+
module modfile75b
14+
use modfile75a ! capture hermetically
15+
end
16+
17+
#else
18+
subroutine test
19+
use modfile75a
20+
use modfile75b
21+
implicit none
22+
print *, x
23+
end subroutine
24+
#endif

0 commit comments

Comments
 (0)