[flang-commits] [flang] [flang] Allow extended char set in `BIND(C, name="...")` (PR #172457)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 16 08:05:25 PST 2025
https://github.com/foxtran updated https://github.com/llvm/llvm-project/pull/172457
>From da0cabc74a31adc93109f5b2a306217d322e8eb7 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 16 Dec 2025 12:02:12 +0100
Subject: [PATCH 1/4] Update flang/test/Semantics/bind-c10.f90 test
---
flang/test/Semantics/bind-c10.f90 | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/flang/test/Semantics/bind-c10.f90 b/flang/test/Semantics/bind-c10.f90
index c562e6aee31e8..b4ae18909cb86 100644
--- a/flang/test/Semantics/bind-c10.f90
+++ b/flang/test/Semantics/bind-c10.f90
@@ -1,10 +1,14 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
-!ERROR: Symbol has a BIND(C) name that is not a valid C language identifier
subroutine bang() bind(C,name='!')
end
-!ERROR: Symbol has a BIND(C) name that is not a valid C language identifier
+!ERROR: Symbol has a BIND(C) name containing non-visible ASCII character(s)
subroutine cr() bind(C,name=achar(13))
end
-!ERROR: Symbol has a BIND(C) name that is not a valid C language identifier
subroutine beast() bind(C,name="666")
end
+!ERROR: Symbol has a BIND(C) name with leading dot that may have special meaning to the toolchain
+subroutine llvm() bind(C,name=".L1")
+end
+!ERROR: Symbol has a BIND(C) name with leading dot that may have special meaning to the toolchain
+subroutine ld() bind(C,name=".text")
+end
>From 63f8cb382c93ced39e0e58d5231c6361f7532b23 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 16 Dec 2025 12:07:36 +0100
Subject: [PATCH 2/4] Detect non-visible characters
---
flang/lib/Semantics/check-declarations.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 9a6b3ff3cdc2c..29342439ee956 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3476,13 +3476,13 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
if (const std::string * bindName{symbol.GetBindName()};
bindName) { // has a binding name
if (!bindName->empty()) {
- bool ok{bindName->front() == '_' || parser::IsLetter(bindName->front())};
+ bool visible_ascii{true};
for (char ch : *bindName) {
- ok &= ch == '_' || parser::IsLetter(ch) || parser::IsDecimalDigit(ch);
+ visible_ascii &= parser::IsPrintable(ch);
}
- if (!ok) {
+ if (!visible_ascii) {
messages_.Say(symbol.name(),
- "Symbol has a BIND(C) name that is not a valid C language identifier"_err_en_US);
+ "Symbol has a BIND(C) name containing non-visible ASCII character(s)"_err_en_US);
context_.SetError(symbol);
}
}
>From e4ad5e418dc01a01b98e5b2d549d677c84f4f819 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 16 Dec 2025 12:09:46 +0100
Subject: [PATCH 3/4] Catch leading dot to avoid misleading with toolchain
internals
---
flang/lib/Semantics/check-declarations.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 29342439ee956..2d3df87f6e240 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3476,6 +3476,12 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
if (const std::string * bindName{symbol.GetBindName()};
bindName) { // has a binding name
if (!bindName->empty()) {
+ bool toolchain_error{bindName->front() == '.'};
+ if (toolchain_error) {
+ messages_.Say(symbol.name(),
+ "Symbol has a BIND(C) name with leading dot that may have special meaning to the toolchain"_err_en_US);
+ context_.SetError(symbol);
+ }
bool visible_ascii{true};
for (char ch : *bindName) {
visible_ascii &= parser::IsPrintable(ch);
>From a6a0f4c66780d12a697768a22aabba0f138df234 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 16 Dec 2025 17:05:08 +0100
Subject: [PATCH 4/4] Remove toolchain_error variable
---
flang/lib/Semantics/check-declarations.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 2d3df87f6e240..23f42684f6b48 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3476,8 +3476,7 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
if (const std::string * bindName{symbol.GetBindName()};
bindName) { // has a binding name
if (!bindName->empty()) {
- bool toolchain_error{bindName->front() == '.'};
- if (toolchain_error) {
+ if (bindName->front() == '.') {
messages_.Say(symbol.name(),
"Symbol has a BIND(C) name with leading dot that may have special meaning to the toolchain"_err_en_US);
context_.SetError(symbol);
More information about the flang-commits
mailing list