[flang-commits] [flang] 0c3c8f4 - [flang] Fix descriptor-based array data item I/O for list-directed CHARACTER & LOGICAL

peter klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 30 14:03:02 PDT 2020


Author: peter klausler
Date: 2020-09-30T14:01:45-07:00
New Revision: 0c3c8f4ae69a619efd8dc088e2572db172d40547

URL: https://github.com/llvm/llvm-project/commit/0c3c8f4ae69a619efd8dc088e2572db172d40547
DIFF: https://github.com/llvm/llvm-project/commit/0c3c8f4ae69a619efd8dc088e2572db172d40547.diff

LOG: [flang] Fix descriptor-based array data item I/O for list-directed CHARACTER & LOGICAL

These types have to distinguish list-directed I/O from formatted I/O,
and the subscript incrementation call was in the formatted branch
of the if() rather than after the if().

Differential revision: https://reviews.llvm.org/D88606

Added: 
    

Modified: 
    flang/runtime/descriptor-io.h
    flang/unittests/Runtime/hello.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/descriptor-io.h b/flang/runtime/descriptor-io.h
index ce0f39740c5f..22552f27c169 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang/runtime/descriptor-io.h
@@ -159,13 +159,13 @@ inline bool FormattedCharacterIO(
           }
         }
       }
-      if (!descriptor.IncrementSubscripts(subscripts) && j + 1 < numElements) {
-        io.GetIoErrorHandler().Crash(
-            "FormattedCharacterIO: subscripts out of bounds");
-      }
     } else {
       return false;
     }
+    if (!descriptor.IncrementSubscripts(subscripts) && j + 1 < numElements) {
+      io.GetIoErrorHandler().Crash(
+          "FormattedCharacterIO: subscripts out of bounds");
+    }
   }
   return true;
 }
@@ -198,13 +198,13 @@ inline bool FormattedLogicalIO(
           }
         }
       }
-      if (!descriptor.IncrementSubscripts(subscripts) && j + 1 < numElements) {
-        io.GetIoErrorHandler().Crash(
-            "FormattedLogicalIO: subscripts out of bounds");
-      }
     } else {
       return false;
     }
+    if (!descriptor.IncrementSubscripts(subscripts) && j + 1 < numElements) {
+      io.GetIoErrorHandler().Crash(
+          "FormattedLogicalIO: subscripts out of bounds");
+    }
   }
   return true;
 }

diff  --git a/flang/unittests/Runtime/hello.cpp b/flang/unittests/Runtime/hello.cpp
index c1daccae383a..bcd3bb448318 100644
--- a/flang/unittests/Runtime/hello.cpp
+++ b/flang/unittests/Runtime/hello.cpp
@@ -118,6 +118,41 @@ static void listInputTest() {
   }
 }
 
+static void descrOutputTest() {
+  char buffer[9];
+  // Formatted
+  const char *format{"(2A4)"};
+  auto cookie{IONAME(BeginInternalFormattedOutput)(
+      buffer, sizeof buffer, format, std::strlen(format))};
+  StaticDescriptor<1> staticDescriptor;
+  Descriptor &desc{staticDescriptor.descriptor()};
+  SubscriptValue extent[]{2};
+  char data[2][4];
+  std::memcpy(data[0], "ABCD", 4);
+  std::memcpy(data[1], "EFGH", 4);
+  desc.Establish(TypeCode{CFI_type_char}, sizeof data[0], &data, 1, extent);
+  desc.Dump();
+  desc.Check();
+  IONAME(OutputDescriptor)(cookie, desc);
+  if (auto status{IONAME(EndIoStatement)(cookie)}) {
+    Fail() << "descrOutputTest: '" << format << "' failed, status "
+           << static_cast<int>(status) << '\n';
+  } else {
+    test("descrOutputTest(formatted)", "ABCDEFGH ",
+        std::string{buffer, sizeof buffer});
+  }
+  // List-directed
+  cookie = IONAME(BeginInternalListOutput)(buffer, sizeof buffer);
+  IONAME(OutputDescriptor)(cookie, desc);
+  if (auto status{IONAME(EndIoStatement)(cookie)}) {
+    Fail() << "descrOutputTest: list-directed failed, status "
+           << static_cast<int>(status) << '\n';
+  } else {
+    test("descrOutputTest(list)", " ABCDEFGH",
+        std::string{buffer, sizeof buffer});
+  }
+}
+
 static void realTest(const char *format, double x, const char *expect) {
   char buffer[800];
   auto cookie{IONAME(BeginInternalFormattedOutput)(
@@ -485,6 +520,7 @@ int main() {
   realInTest("(DC,F18.0)", "              12,5", 0x4029000000000000);
 
   listInputTest();
+  descrOutputTest();
 
   return EndTests();
 }


        


More information about the flang-commits mailing list