[flang-commits] [flang] [Flang] Shift the data from lower to higher order bits in the big endian environment (PR #73670)
via flang-commits
flang-commits at lists.llvm.org
Tue Nov 28 08:58:26 PST 2023
https://github.com/madanial0 created https://github.com/llvm/llvm-project/pull/73670
Shift the data from lower to higher order bits when memcpy the value in the namelist in the big endian environment
>From 66d78dfbc70aac69be46a18806d9c1967df2c572 Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Mon, 27 Nov 2023 21:11:52 -0500
Subject: [PATCH] [Flang] Shift the data from lower to higher order bits in the
big endian environment
---
flang/runtime/edit-input.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index 4e8c9aa868a691c..305d85afe480ffe 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -222,7 +222,15 @@ bool EditIntegerInput(
value = -value;
}
if (any || !io.GetConnectionState().IsAtEOF()) {
- std::memcpy(n, &value, kind); // a blank field means zero
+ // For integer kind <= 4, the value is stored in the lower order bits on
+ // the big endian platform. When memcpy the value, shift the value, shift
+ // the value to the higher order bit.
+ if (!isHostLittleEndian && kind <= 4) {
+ auto l{value.low() << (8 * (sizeof(value.low()) - kind))};
+ std::memcpy(n, &l, kind);
+ } else {
+ std::memcpy(n, &value, kind); // a blank field means zero
+ }
}
return any;
}
More information about the flang-commits
mailing list