[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
This commit is contained in:
peter klausler 2020-08-12 16:25:26 -07:00
parent 3a2645e428
commit 5c9aca1e93
2 changed files with 3 additions and 2 deletions

View File

@ -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) {

View File

@ -255,6 +255,7 @@ public:
}
}
// 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)};