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][runtime] Fix off-by-one error in EX0.0 output editing #85428

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

klausler
Copy link
Contributor

The maximum number of significant hexadecimal digits in EX0.0 REAL output editing is 29, not 28. Fix by computing it at build time from the precision of REAL(16).

The maximum number of significant hexadecimal digits in EX0.0
REAL output editing is 29, not 28.  Fix by computing it at
build time from the precision of REAL(16).
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Mar 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 15, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

The maximum number of significant hexadecimal digits in EX0.0 REAL output editing is 29, not 28. Fix by computing it at build time from the precision of REAL(16).


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

1 Files Affected:

  • (modified) flang/runtime/edit-output.cpp (+4-1)
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index b474c8cd91bae4..7267540370fc07 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -9,6 +9,7 @@
 #include "edit-output.h"
 #include "emit-encoded.h"
 #include "utf.h"
+#include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include <algorithm>
 
@@ -700,7 +701,9 @@ bool RealOutputEditing<KIND>::EditEXOutput(const DataEdit &edit) {
   if ((editWidth == 0 && !edit.digits) || editDigits == 0) {
     // EX0 or EXw.0
     flags |= decimal::Minimize;
-    significantDigits = 28; // enough for 128-bit F.P.
+    static constexpr int maxSigHexDigits{
+        (common::PrecisionOfRealKind(16) + 3) / 4};
+    significantDigits = maxSigHexDigits;
   }
   auto converted{
       ConvertToHexadecimal(significantDigits, edit.modes.round, flags)};

Copy link
Contributor

@vdonaldson vdonaldson left a comment

Choose a reason for hiding this comment

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

Thanks!

@klausler klausler merged commit 5e21fa2 into llvm:main Mar 15, 2024
6 of 7 checks passed
@klausler klausler deleted the suy068a branch March 15, 2024 20:56
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

3 participants