[flang-commits] [flang] [Flang] Fix spurious errors for common blocks with binding labels (PR #218566)
Ali Bahrani via flang-commits
flang-commits at lists.llvm.org
Tue Aug 25 07:52:45 PDT 2026
https://github.com/mrbahrani updated https://github.com/llvm/llvm-project/pull/218566
>From d4d2baecf5f255397f30d75e444d7972844224a7 Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu at ip-172-31-16-239.ec2.internal>
Date: Mon, 24 Aug 2026 19:53:26 +0000
Subject: [PATCH 1/3] flang semantics - change common block condition to check
the owner scope instead of the name to allow the same name binding in
different scopes
---
flang/lib/Semantics/check-declarations.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 41ddb61c4340d..f879af7a3b1f4 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -21,7 +21,9 @@
#include "flang/Semantics/tools.h"
#include "flang/Semantics/type.h"
#include <algorithm>
+#include <iostream>
#include <map>
+#include <ostream>
#include <string>
namespace Fortran::semantics {
@@ -3129,6 +3131,7 @@ static std::optional<std::string> DefinesGlobalName(const Symbol &symbol) {
// 19.2 p2
void CheckHelper::CheckGlobalName(const Symbol &symbol) {
+ // std::cout << symbol.name().ToString() << " " << symbol.GetParentComponent()->name().ToString()<< "\n";
if (auto global{DefinesGlobalName(symbol)}) {
auto pair{globalNames_.emplace(std::move(*global), symbol)};
if (!pair.second) {
@@ -3136,7 +3139,7 @@ void CheckHelper::CheckGlobalName(const Symbol &symbol) {
if (context_.HasError(symbol) || context_.HasError(other)) {
// don't pile on
} else if (symbol.has<CommonBlockDetails>() &&
- other.has<CommonBlockDetails>() && symbol.name() == other.name()) {
+ other.has<CommonBlockDetails>() && symbol.owner() != other.owner()) {
// Two common blocks can have the same global name so long as
// they're not in the same scope.
} else if ((IsProcedure(symbol) || IsBlockData(symbol)) &&
>From 3b0c14f5cfdfdb49abf5796be53ff5e348f9a117 Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu at ip-172-31-16-239.ec2.internal>
Date: Tue, 25 Aug 2026 00:56:11 +0000
Subject: [PATCH 2/3] flang Semantic tests - update declaration03.f90 to test
the bug fix on bind c error on commons with different symbol names
---
flang/test/Semantics/declarations03.f90 | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90
index 8e6f0a4aaf6bd..4e720e822cc77 100644
--- a/flang/test/Semantics/declarations03.f90
+++ b/flang/test/Semantics/declarations03.f90
@@ -67,6 +67,19 @@ subroutine common2()
bind(c, name='xcom') /com/ ! no error
end subroutine
+subroutine common3()
+ real :: y
+ common /comA/ y
+ bind(c, name='xcom2') /comA/ ! no error
+end subroutine
+
+subroutine common4()
+ real :: y
+ common /comB/ y
+ bind(c, name='xcom2') /comB/ ! no error
+end subroutine
+
+
module a
integer, bind(c, name="int") :: i
end module
>From 94c1d419d5a215a81a188fcf18f0a44401faf736 Mon Sep 17 00:00:00 2001
From: abahrani <ali.bahrani94521036 at gmail.com>
Date: Tue, 25 Aug 2026 10:52:11 -0400
Subject: [PATCH 3/3] flang semantics - remove debug code from
check-declarations.cpp
---
flang/lib/Semantics/check-declarations.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 856b44bc6cf5b..c5a1018f759fd 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -21,7 +21,6 @@
#include "flang/Semantics/tools.h"
#include "flang/Semantics/type.h"
#include <algorithm>
-#include <iostream>
#include <map>
#include <ostream>
#include <string>
@@ -3144,7 +3143,6 @@ static std::optional<std::string> DefinesGlobalName(const Symbol &symbol) {
// 19.2 p2
void CheckHelper::CheckGlobalName(const Symbol &symbol) {
- // std::cout << symbol.name().ToString() << " " << symbol.GetParentComponent()->name().ToString()<< "\n";
if (auto global{DefinesGlobalName(symbol)}) {
auto pair{globalNames_.emplace(std::move(*global), symbol)};
if (!pair.second) {
More information about the flang-commits
mailing list