Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] Shift the data from lower to higher order bits in the big endian environment #73670

Merged
merged 4 commits into from
Dec 28, 2023

Conversation

madanial0
Copy link
Contributor

Shift the data from lower to higher order bits when memcpy the value in the namelist in the big endian environment

@madanial0 madanial0 added the flang Flang issues not falling into any other category label Nov 28, 2023
@madanial0 madanial0 self-assigned this Nov 28, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 28, 2023

@llvm/pr-subscribers-flang-runtime

Author: None (madanial0)

Changes

Shift the data from lower to higher order bits when memcpy the value in the namelist in the big endian environment


Full diff: https://github.com/llvm/llvm-project/pull/73670.diff

1 Files Affected:

  • (modified) flang/runtime/edit-input.cpp (+9-1)
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;
 }

Copy link

github-actions bot commented Dec 14, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@madanial0
Copy link
Contributor Author

friendly ping! Thanks!

flang/include/flang/Common/uint128.h Outdated Show resolved Hide resolved
flang/include/flang/Common/uint128.h Outdated Show resolved Hide resolved
flang/runtime/edit-input.cpp Show resolved Hide resolved
@madanial0
Copy link
Contributor Author

Friendly ping! Thanks!

@madanial0
Copy link
Contributor Author

Thanks for the review!

@madanial0 madanial0 merged commit fdccfa3 into llvm:main Dec 28, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants