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

via flang-commits flang-commits at lists.llvm.org
Tue Jun 9 11:55:45 PDT 2026


Author: John Otken
Date: 2026-06-09T14:55:40-04:00
New Revision: 8dac043eb036250cfc2010c44c75b54d08d2d5ef

URL: https://github.com/llvm/llvm-project/commit/8dac043eb036250cfc2010c44c75b54d08d2d5ef
DIFF: https://github.com/llvm/llvm-project/commit/8dac043eb036250cfc2010c44c75b54d08d2d5ef.diff

LOG: [flang-rt] Add support for logical binary input edit descriptor (#193490)

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

Added: 
    

Modified: 
    flang-rt/lib/runtime/edit-input.cpp
    flang-rt/unittests/Runtime/InputExtensions.cpp
    flang/docs/Extensions.md

Removed: 
    


################################################################################
diff  --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
index 577e64d43421d..c2d50c83372c3 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
+// 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) {
@@ -935,6 +935,7 @@ RT_API_ATTRS bool EditLogicalInput(
     break;
   case 'L':
   case 'G':
+  case 'B':
     break;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInFormat,
@@ -944,26 +945,41 @@ 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) {
     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

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 f86073db20224..b84b2ac188ff7 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -248,6 +248,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