[flang][runtime] Handle READ of non-UTF-8 data into multi-byte CHARACTER

When a READ statement reads into a CHARACTER(2 or 4) variable from a
unit whose encoding is not UTF-8, don't copy bytes directly; they must
each be zero-extended.

Differential Revision: https://reviews.llvm.org/D128390
This commit is contained in:
Peter Klausler 2022-06-17 12:14:46 -07:00
parent b257acd266
commit ede4213169
1 changed files with 11 additions and 1 deletions

View File

@ -730,7 +730,17 @@ bool EditCharacterInput(
chunk = 1;
}
--remaining;
} else if constexpr (sizeof *x > 1) {
// Read single byte with expansion into multi-byte CHARACTER
chunk = 1;
if (skipping) {
--skip;
} else {
*x++ = static_cast<unsigned char>(*input);
--length;
}
--remaining;
} else { // single bytes -> default CHARACTER
if (skipping) {
chunk = std::min<std::size_t>(skip, ready);
skip -= chunk;