[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 Jun 3 05:01:41 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/5] [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/5] 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)`

>From 6a5319eb6bb6f489ef7ac6aaa64084a27dd32498 Mon Sep 17 00:00:00 2001
From: John Otken <john at otken.com>
Date: Wed, 6 May 2026 17:20:43 -0500
Subject: [PATCH 3/5] Update comment that function implements B descriptor as
 an extension

---
 flang-rt/lib/runtime/edit-input.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
index bb28b52b2c1ec..e555a229af78a 100644
--- a/flang-rt/lib/runtime/edit-input.cpp
+++ b/flang-rt/lib/runtime/edit-input.cpp
@@ -924,7 +924,7 @@ RT_API_ATTRS bool EditRealInput(
   }
 }
 
-// 13.7.3 in Fortran 2018
+// 13.7.3 in Fortran 2018 (B descriptor is an extension)
 RT_API_ATTRS bool EditLogicalInput(
     IoStatementState &io, const DataEdit &edit, bool &x) {
   switch (edit.descriptor) {

>From bb7d13b51189b48c6d0c11421fd5f28050145607 Mon Sep 17 00:00:00 2001
From: John Otken <john at otken.com>
Date: Mon, 1 Jun 2026 14:39:03 -0500
Subject: [PATCH 4/5] Use preferred comment format for spec references

---
 flang-rt/lib/runtime/edit-input.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
index e555a229af78a..97a6574247862 100644
--- a/flang-rt/lib/runtime/edit-input.cpp
+++ b/flang-rt/lib/runtime/edit-input.cpp
@@ -924,7 +924,7 @@ RT_API_ATTRS bool EditRealInput(
   }
 }
 
-// 13.7.3 in Fortran 2018 (B descriptor is an extension)
+// F2018 13.7.3 (B descriptor is a non-standard extension)
 RT_API_ATTRS bool EditLogicalInput(
     IoStatementState &io, const DataEdit &edit, bool &x) {
   switch (edit.descriptor) {

>From f64bf50a3c508238b5a02ad23f19ef527951ef30 Mon Sep 17 00:00:00 2001
From: John Otken <john.otken at hpe.com>
Date: Wed, 3 Jun 2026 06:59:18 -0500
Subject: [PATCH 5/5] Restart CI Checks




More information about the flang-commits mailing list