[flang-commits] [flang] 5c9aca1 - [flang] Descriptor-based I/O using wrong size for contiguous unformatted I/O
peter klausler via flang-commits
flang-commits at lists.llvm.org
Thu Aug 13 10:47:28 PDT 2020
Author: peter klausler
Date: 2020-08-13T10:46:43-07:00
New Revision: 5c9aca1e9396c54151b066189748209554230b59
URL: https://github.com/llvm/llvm-project/commit/5c9aca1e9396c54151b066189748209554230b59
DIFF: https://github.com/llvm/llvm-project/commit/5c9aca1e9396c54151b066189748209554230b59.diff
LOG: [flang] Descriptor-based I/O using wrong size for contiguous unformatted I/O
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.
Differential Revision: https://reviews.llvm.org/D85863
Added:
Modified:
flang/runtime/descriptor-io.h
flang/runtime/descriptor.h
Removed:
################################################################################
diff --git a/flang/runtime/descriptor-io.h b/flang/runtime/descriptor-io.h
index 22ae4f9917ab..ce0f39740c5f 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang/runtime/descriptor-io.h
@@ -223,16 +223,16 @@ static bool DescriptorIO(IoStatementState &io, const Descriptor &descriptor) {
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) {
diff --git a/flang/runtime/descriptor.h b/flang/runtime/descriptor.h
index 3462bb612dff..983d483788b9 100644
--- a/flang/runtime/descriptor.h
+++ b/flang/runtime/descriptor.h
@@ -255,6 +255,7 @@ class Descriptor {
}
}
+ // 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)};
More information about the flang-commits
mailing list