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] pass true/false to EditLogicalOutput directly (NFC) #73375

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

kkwli
Copy link
Collaborator

@kkwli kkwli commented Nov 24, 2023

Using reinterpret_cast<const char *>(&n) will cause issue in the big endian environment when KIND > 1.

@kkwli kkwli self-assigned this Nov 24, 2023
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Nov 24, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 24, 2023

@llvm/pr-subscribers-flang-runtime

Author: None (kkwli)

Changes

Using reinterpret_cast&lt;const char *&gt;(&amp;n) will cause issue in the big endian environment when KIND&gt;1.


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

1 Files Affected:

  • (modified) flang/runtime/edit-output.cpp (+1-1)
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 18b209bc6798c33..3056cc6924d5c9c 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -140,7 +140,7 @@ bool EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
     return EditBOZOutput<4>(
         io, edit, reinterpret_cast<const unsigned char *>(&n), KIND);
   case 'L':
-    return EditLogicalOutput(io, edit, *reinterpret_cast<const char *>(&n));
+    return EditLogicalOutput(io, edit, n == 0 ? false : true);
   case 'A': // legacy extension
     return EditCharacterOutput(
         io, edit, reinterpret_cast<char *>(&n), sizeof n);

@kkwli kkwli changed the title [flang] pass true/false to EditLogicalOutput directly [flang] pass true/false to EditLogicalOutput directly (NFC) Nov 24, 2023
flang/runtime/edit-output.cpp Outdated Show resolved Hide resolved
@@ -140,7 +140,7 @@ bool EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
return EditBOZOutput<4>(
io, edit, reinterpret_cast<const unsigned char *>(&n), KIND);
case 'L':
return EditLogicalOutput(io, edit, *reinterpret_cast<const char *>(&n));
return EditLogicalOutput(io, edit, n != 0 ? true : false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suggestion was to do

return EditLogicalOutput(io, edit, n != 0);

@kkwli kkwli merged commit 3bc7e55 into llvm:main Dec 7, 2023
4 checks passed
@kkwli kkwli deleted the logical-format-io branch December 13, 2023 12:20
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