[flang-commits] [flang] [flang] silence bogus error with BIND(C) variable in hermetic module (PR #143737)
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 11 08:50:30 PDT 2025
https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/143737
The global name semantic check was firing in a bogus way when BIND(C) variable are in hermetic module.
The added test would fail to compile with error:
```
error: Semantic errors in flang/test/Semantics/modfile76.F90
./modfile75b.mod:6:21: error: Two entities have the same global name 'x'
integer(4),bind(c)::x
^
./modfile75a.mod:3:21: Conflicting declaration
integer(4),bind(c)::x
```
Do not raise the error if one of the symbol with the conflicting global name is an "hermetic variant" of the other.
>From a0f40e5a64baa3ae70aeeae6a7956f156f2907f2 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
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<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)}) {
@@ -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,
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
More information about the flang-commits
mailing list