[flang-commits] [flang] [flang] Fix bogus error about duplicate binding names (PR #89786)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Apr 23 09:10:56 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/89786
Don't call SetBindNameOn() from DeclareUnknownEntity() unless there is an explicit BIND(C) attribute.
Fixes https://github.com/llvm/llvm-project/issues/89439.
>From 607e410c928bdafbf575a519defd05b3052d64b1 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 23 Apr 2024 09:07:55 -0700
Subject: [PATCH] [flang] Fix bogus error about duplicate binding names
Don't call SetBindNameOn() from DeclareUnknownEntity() unless
there is an explicit BIND(C) attribute.
Fixes https://github.com/llvm/llvm-project/issues/89439.
---
flang/lib/Semantics/resolve-names.cpp | 15 +++++++++------
flang/test/Semantics/declarations03.f90 | 13 +++++++++----
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b941f257a95ea3..c21cf1bf4d7da3 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1779,7 +1779,6 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
!symbol.attrs().test(Attr::BIND_C)) {
return;
}
-
std::optional<std::string> label{
evaluate::GetScalarConstantValue<evaluate::Ascii>(bindName_)};
// 18.9.2(2): discard leading and trailing blanks
@@ -1798,16 +1797,18 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
} else {
label = symbol.name().ToString();
}
- // Check if a symbol has two Bind names.
+ // Checks whether a symbol has two Bind names.
std::string oldBindName;
- if (symbol.GetBindName()) {
- oldBindName = *symbol.GetBindName();
+ if (const auto *bindName{symbol.GetBindName()}) {
+ oldBindName = *bindName;
}
symbol.SetBindName(std::move(*label));
if (!oldBindName.empty()) {
if (const std::string * newBindName{symbol.GetBindName()}) {
if (oldBindName != *newBindName) {
- Say(symbol.name(), "The entity '%s' has multiple BIND names"_err_en_US);
+ Say(symbol.name(),
+ "The entity '%s' has multiple BIND names ('%s' and '%s')"_err_en_US,
+ symbol.name(), oldBindName, *newBindName);
}
}
}
@@ -4986,7 +4987,9 @@ Symbol &DeclarationVisitor::DeclareUnknownEntity(
if (symbol.attrs().test(Attr::EXTERNAL)) {
ConvertToProcEntity(symbol);
}
- SetBindNameOn(symbol);
+ if (attrs.test(Attr::BIND_C)) {
+ SetBindNameOn(symbol);
+ }
return symbol;
}
}
diff --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90
index 3459b2287b2bad..65b07e7d5c6567 100644
--- a/flang/test/Semantics/declarations03.f90
+++ b/flang/test/Semantics/declarations03.f90
@@ -19,7 +19,7 @@ module m
common /blk4/ w
bind(c, name="cc") :: t2, /blk4/
- !ERROR: The entity 'blk5' has multiple BIND names
+ !ERROR: The entity 'blk5' has multiple BIND names ('dd' and 'ee')
common /blk5/ i
bind(c, name="dd") :: /blk5/
bind(c, name="ee") :: /blk5/
@@ -29,7 +29,7 @@ module m
bind(c, name="ff") :: /blk6/
bind(c, name="ff") :: /blk7/
- !ERROR: The entity 's1' has multiple BIND names
+ !ERROR: The entity 's1' has multiple BIND names ('gg' and 'hh')
integer :: s1
bind(c, name="gg") :: s1
!ERROR: BIND_C attribute was already specified on 's1'
@@ -40,12 +40,12 @@ module m
bind(c, name="ii") :: s2
bind(c, name="ii") :: s3
- !ERROR: The entity 's4' has multiple BIND names
+ !ERROR: The entity 's4' has multiple BIND names ('ss1' and 'jj')
integer, bind(c, name="ss1") :: s4
!ERROR: BIND_C attribute was already specified on 's4'
bind(c, name="jj") :: s4
- !ERROR: The entity 's5' has multiple BIND names
+ !ERROR: The entity 's5' has multiple BIND names ('kk' and 'ss2')
bind(c, name="kk") :: s5
!ERROR: BIND_C attribute was already specified on 's5'
integer, bind(c, name="ss2") :: s5
@@ -72,3 +72,8 @@ module b
!ERROR: Two entities have the same global name 'int'
integer, bind(c, name="int") :: i
end module
+
+module c
+ bind(c, name = "AAA") a
+ integer aaa ! ensure no bogus error about multiple binding names
+end module
More information about the flang-commits
mailing list