[flang-commits] [flang] [llvm] [flang-rt] Add support for logical binary input edit descriptor (PR #193490)

John Otken via flang-commits flang-commits at lists.llvm.org
Wed May 6 07:55:31 PDT 2026


https://github.com/jotken updated https://github.com/llvm/llvm-project/pull/193490

>From 534d699618f0dfca9661e3737e3a2e5e97937d9b Mon Sep 17 00:00:00 2001
From: John Otken <john at otken.com>
Date: Wed, 22 Apr 2026 07:51:24 -0500
Subject: [PATCH 1/2] [flang-rt] Add support for logical binary input edit
 descriptor

Add binary 'B' input edit descriptor support for logical values
to flang runtime EditLogicalInput().  The logical binary 'B'
edit descriptor is already supported in EditLogicalOutput().

Co-authored-by: John Otken john.otken at hpe.com
---
 flang-rt/lib/runtime/edit-input.cpp | 42 ++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
index 9b31ecce82838..328c04064096e 100644
--- a/flang-rt/lib/runtime/edit-input.cpp
+++ b/flang-rt/lib/runtime/edit-input.cpp
@@ -935,6 +935,7 @@ RT_API_ATTRS bool EditLogicalInput(
     break;
   case 'L':
   case 'G':
+  case 'B':
     break;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInFormat,
@@ -951,19 +952,34 @@ RT_API_ATTRS bool EditLogicalInput(
     io.GetIoErrorHandler().SignalError("Empty LOGICAL input field");
     return false;
   }
-  switch (*next) {
-  case 'T':
-  case 't':
-    x = true;
-    break;
-  case 'F':
-  case 'f':
-    x = false;
-    break;
-  default:
-    io.GetIoErrorHandler().SignalError(
-        "Bad character '%lc' in LOGICAL input field", *next);
-    return false;
+  if (edit.descriptor == 'B') {
+    switch (*next) {
+    case '1':
+      x = true;
+      break;
+    case '0':
+      x = false;
+      break;
+    default:
+      io.GetIoErrorHandler().SignalError(
+          "Bad character '%lc' in BINARY input field", *next);
+      return false;
+    }
+  } else {
+    switch (*next) {
+    case 'T':
+    case 't':
+      x = true;
+      break;
+    case 'F':
+    case 'f':
+      x = false;
+      break;
+    default:
+      io.GetIoErrorHandler().SignalError(
+          "Bad character '%lc' in LOGICAL input field", *next);
+      return false;
+    }
   }
   if (remaining || edit.descriptor == DataEdit::ListDirected) {
     // Ignore the rest of the input field; stop after separator when

>From 53dce469dd16cf7069326c9637e983e8f6b8f0f0 Mon Sep 17 00:00:00 2001
From: John Otken <john at otken.com>
Date: Wed, 6 May 2026 09:51:57 -0500
Subject: [PATCH 2/2] Include unit tests and document extensions.

---
 flang-rt/lib/runtime/edit-input.cpp            | 2 +-
 flang-rt/unittests/Runtime/InputExtensions.cpp | 6 +++++-
 flang/docs/Extensions.md                       | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
index 328c04064096e..bb28b52b2c1ec 100644
--- a/flang-rt/lib/runtime/edit-input.cpp
+++ b/flang-rt/lib/runtime/edit-input.cpp
@@ -945,7 +945,7 @@ RT_API_ATTRS bool EditLogicalInput(
   }
   common::optional<int> remaining{io.CueUpInput(edit)};
   common::optional<char32_t> next{io.NextInField(remaining, edit)};
-  if (next && *next == '.') { // skip optional period
+  if (next && *next == '.' && edit.descriptor != 'B') { // skip optional period
     next = io.NextInField(remaining, edit);
   }
   if (!next) {
diff --git a/flang-rt/unittests/Runtime/InputExtensions.cpp b/flang-rt/unittests/Runtime/InputExtensions.cpp
index 4bb1124928f03..3f68b1ce9970c 100644
--- a/flang-rt/unittests/Runtime/InputExtensions.cpp
+++ b/flang-rt/unittests/Runtime/InputExtensions.cpp
@@ -88,6 +88,10 @@ TEST(InputExtensionTests, SeparatorInField_L) {
       {2, "(DC,2L4)", ".F;T,", {false, true}},
       {2, "(DC,2L4)", ".T.;F,", {true, false}},
       {2, "(DC,2L4)", ".F.;T,", {false, true}},
+      {2, "(2B4)", "1   0,", {true, false}},
+      {2, "(2B4)", "0   1,", {false, true}},
+      {2, "(DC,2B4)", "1   0,", {true, false}},
+      {2, "(DC,2B4)", "0   1,", {false, true}},
   };
   for (std::size_t j{0}; j < sizeof test / sizeof *test; ++j) {
     auto cookie{IONAME(BeginInternalFormattedInput)(test[j].data,
@@ -100,7 +104,7 @@ TEST(InputExtensionTests, SeparatorInField_L) {
           << "expected " << test[j].expect[k] << ", got " << got;
     }
     auto status{IONAME(EndIoStatement)(cookie)};
-    ASSERT_EQ(status, 0) << "error status " << status << " on L test case "
+    ASSERT_EQ(status, 0) << "error status " << status << " on L/B test case "
                          << j;
   }
 }
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 391fe99749fd6..d518e87330b93 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -238,6 +238,7 @@ end
 * `ASSIGN` statement, assigned `GO TO`, and assigned format
 * `PAUSE` statement
 * Hollerith literals and edit descriptors
+* Binary logical edit descriptor B (1/0 vs T/F)
 * `NAMELIST` allowed in the execution part
 * Omitted colons on type declaration statements with attributes
 * COMPLEX constructor expression, e.g. `(x+y,z)`



More information about the flang-commits mailing list