[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 03:15:12 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: foxtran (foxtran)

<details>
<summary>Changes</summary>

Fixes #<!-- -->172456 

---
Full diff: https://github.com/llvm/llvm-project/pull/172457.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-declarations.cpp (+10-4) 
- (modified) flang/test/Semantics/bind-c10.f90 (+7-3) 


``````````diff
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 9a6b3ff3cdc2c..2d3df87f6e240 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3476,13 +3476,19 @@ 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 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) {
-        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);
       }
     }
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/172457


More information about the flang-commits mailing list