[flang-commits] [PATCH] D143833: [flang] Check for invalid BIND(C) names

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Feb 13 17:27:22 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG69373a5d3f45: [flang] Check for invalid BIND(C) names (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143833/new/

https://reviews.llvm.org/D143833

Files:
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Semantics/bind-c10.f90


Index: flang/test/Semantics/bind-c10.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/bind-c10.f90
@@ -0,0 +1,10 @@
+! 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
+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
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -13,6 +13,7 @@
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/tools.h"
+#include "flang/Parser/characters.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
@@ -2173,6 +2174,18 @@
   }
   CheckConflicting(symbol, Attr::BIND_C, Attr::PARAMETER);
   CheckConflicting(symbol, Attr::BIND_C, Attr::ELEMENTAL);
+  if (const std::string * bindName{symbol.GetBindName()};
+      bindName && !bindName->empty()) {
+    bool ok{bindName->front() == '_' || parser::IsLetter(bindName->front())};
+    for (char ch : *bindName) {
+      ok &= ch == '_' || parser::IsLetter(ch) || parser::IsDecimalDigit(ch);
+    }
+    if (!ok) {
+      messages_.Say(symbol.name(),
+          "Symbol has a BIND(C) name that is not a valid C language identifier"_err_en_US);
+      context_.SetError(symbol);
+    }
+  }
   if (symbol.has<ObjectEntityDetails>() && !symbol.owner().IsModule()) {
     messages_.Say(symbol.name(),
         "A variable with BIND(C) attribute may only appear in the specification part of a module"_err_en_US);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143833.497160.patch
Type: text/x-patch
Size: 1938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230214/988f441b/attachment.bin>


More information about the flang-commits mailing list