[flang-commits] [PATCH] D100494: [flang] Correct the interpretation of BIND(C, NAME='')

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Apr 14 11:13:10 PDT 2021


klausler created this revision.
klausler added a reviewer: tskeith.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

An empty NAME= should mean that there is no C binding, not the
binding that would result from BIND(C) without a NAME=.
See 18.10.2p2.


https://reviews.llvm.org/D100494

Files:
  flang/lib/Semantics/resolve-names.cpp


Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -235,7 +235,7 @@
   Attrs GetAttrs();
   Attrs EndAttrs();
   bool SetPassNameOn(Symbol &);
-  bool SetBindNameOn(Symbol &);
+  void SetBindNameOn(Symbol &);
   void Post(const parser::LanguageBindingSpec &);
   bool Pre(const parser::IntentSpec &);
   bool Pre(const parser::Pass &);
@@ -1529,28 +1529,26 @@
   return true;
 }
 
-bool AttrsVisitor::SetBindNameOn(Symbol &symbol) {
+void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
   if (!attrs_ || !attrs_->test(Attr::BIND_C)) {
-    return false;
+    return;
   }
   std::optional<std::string> label{evaluate::GetScalarConstantValue<
       evaluate::Type<TypeCategory::Character, 1>>(bindName_)};
   // 18.9.2(2): discard leading and trailing blanks, ignore if all blank
   if (label) {
     auto first{label->find_first_not_of(" ")};
-    auto last{label->find_last_not_of(" ")};
     if (first == std::string::npos) {
+      // Empty NAME= means no binding at all (18.10.2p2)
       Say(currStmtSource().value(), "Blank binding label ignored"_en_US);
-      label.reset();
-    } else {
-      label = label->substr(first, last - first + 1);
+      return;
     }
-  }
-  if (!label) {
+    auto last{label->find_last_not_of(" ")};
+    label = label->substr(first, last - first + 1);
+  } else {
     label = parser::ToLowerCaseLetters(symbol.name().ToString());
   }
   symbol.SetBindName(std::move(*label));
-  return true;
 }
 
 void AttrsVisitor::Post(const parser::LanguageBindingSpec &x) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100494.337500.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210414/dcb880e6/attachment.bin>


More information about the flang-commits mailing list