[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:
parent
3a2645e428
commit
5c9aca1e93
|
@ -223,16 +223,16 @@ static bool DescriptorIO(IoStatementState &io, const Descriptor &descriptor) {
|
||||||
std::size_t elementBytes{descriptor.ElementBytes()};
|
std::size_t elementBytes{descriptor.ElementBytes()};
|
||||||
SubscriptValue subscripts[maxRank];
|
SubscriptValue subscripts[maxRank];
|
||||||
descriptor.GetLowerBounds(subscripts);
|
descriptor.GetLowerBounds(subscripts);
|
||||||
|
std::size_t numElements{descriptor.Elements()};
|
||||||
if (descriptor.IsContiguous()) { // contiguous unformatted I/O
|
if (descriptor.IsContiguous()) { // contiguous unformatted I/O
|
||||||
char &x{ExtractElement<char>(io, descriptor, subscripts)};
|
char &x{ExtractElement<char>(io, descriptor, subscripts)};
|
||||||
auto totalBytes{descriptor.SizeInBytes()};
|
auto totalBytes{numElements * elementBytes};
|
||||||
if constexpr (DIR == Direction::Output) {
|
if constexpr (DIR == Direction::Output) {
|
||||||
return unf->Emit(&x, totalBytes, elementBytes);
|
return unf->Emit(&x, totalBytes, elementBytes);
|
||||||
} else {
|
} else {
|
||||||
return unf->Receive(&x, totalBytes, elementBytes);
|
return unf->Receive(&x, totalBytes, elementBytes);
|
||||||
}
|
}
|
||||||
} else { // non-contiguous unformatted I/O
|
} else { // non-contiguous unformatted I/O
|
||||||
std::size_t numElements{descriptor.Elements()};
|
|
||||||
for (std::size_t j{0}; j < numElements; ++j) {
|
for (std::size_t j{0}; j < numElements; ++j) {
|
||||||
char &x{ExtractElement<char>(io, descriptor, subscripts)};
|
char &x{ExtractElement<char>(io, descriptor, subscripts)};
|
||||||
if constexpr (DIR == Direction::Output) {
|
if constexpr (DIR == Direction::Output) {
|
||||||
|
|
|
@ -255,6 +255,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns size in bytes of the descriptor (not the data)
|
||||||
static constexpr std::size_t SizeInBytes(
|
static constexpr std::size_t SizeInBytes(
|
||||||
int rank, bool addendum = false, int lengthTypeParameters = 0) {
|
int rank, bool addendum = false, int lengthTypeParameters = 0) {
|
||||||
std::size_t bytes{sizeof(Descriptor) - sizeof(Dimension)};
|
std::size_t bytes{sizeof(Descriptor) - sizeof(Dimension)};
|
||||||
|
|
Loading…
Reference in New Issue