[flang-commits] [PATCH] D85863: [flang] Descriptor-based I/O using wrong size for contiguous unformatted I/O

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Aug 12 16:32:08 PDT 2020


klausler created this revision.
klausler added reviewers: sscalpone, schweitz.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

The descriptor-based I/O routine was using the size of the descriptor
rather than the size of the described data for the transfer.  Fix,
and add a comment to the relevant API.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85863

Files:
  flang/runtime/descriptor-io.h
  flang/runtime/descriptor.h


Index: flang/runtime/descriptor.h
===================================================================
--- flang/runtime/descriptor.h
+++ flang/runtime/descriptor.h
@@ -255,6 +255,7 @@
     }
   }
 
+  // Returns size in bytes of the descriptor (not the data)
   static constexpr std::size_t SizeInBytes(
       int rank, bool addendum = false, int lengthTypeParameters = 0) {
     std::size_t bytes{sizeof(Descriptor) - sizeof(Dimension)};
Index: flang/runtime/descriptor-io.h
===================================================================
--- flang/runtime/descriptor-io.h
+++ flang/runtime/descriptor-io.h
@@ -223,16 +223,16 @@
     std::size_t elementBytes{descriptor.ElementBytes()};
     SubscriptValue subscripts[maxRank];
     descriptor.GetLowerBounds(subscripts);
+    std::size_t numElements{descriptor.Elements()};
     if (descriptor.IsContiguous()) { // contiguous unformatted I/O
       char &x{ExtractElement<char>(io, descriptor, subscripts)};
-      auto totalBytes{descriptor.SizeInBytes()};
+      auto totalBytes{numElements * elementBytes};
       if constexpr (DIR == Direction::Output) {
         return unf->Emit(&x, totalBytes, elementBytes);
       } else {
         return unf->Receive(&x, totalBytes, elementBytes);
       }
     } else { // non-contiguous unformatted I/O
-      std::size_t numElements{descriptor.Elements()};
       for (std::size_t j{0}; j < numElements; ++j) {
         char &x{ExtractElement<char>(io, descriptor, subscripts)};
         if constexpr (DIR == Direction::Output) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85863.285210.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200812/98a2d73c/attachment.bin>


More information about the flang-commits mailing list