Skip to content

Commit e5639ec

Browse files
author
Mark Danial
committed
[Flang] Shift the data from lower to higher order bits in the big endian environment
1 parent 6dc5ba4 commit e5639ec

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flang/runtime/edit-input.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ bool EditIntegerInput(
244244
value = -value;
245245
}
246246
if (any || !io.GetConnectionState().IsAtEOF()) {
247-
std::memcpy(n, &value, kind); // a blank field means zero
247+
// For integer kind <= 4, the value is stored in the lower order bits on
248+
// the big endian platform. When memcpy the value, shift the value, shift
249+
// the value to the higher order bit.
250+
if (!isHostLittleEndian && kind <= 4) {
251+
auto l{value.low() << (8 * (sizeof(value.low()) - kind))};
252+
std::memcpy(n, &l, kind);
253+
} else {
254+
std::memcpy(n, &value, kind); // a blank field means zero
255+
}
248256
}
249257
return any;
250258
}

0 commit comments

Comments
 (0)