[flang-commits] [flang] 933882f - [flang][runtime] Fix trailing blanks for Gw.dEe output editing (#75263)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 26 15:23:04 PST 2023
Author: Peter Klausler
Date: 2023-12-26T15:23:01-08:00
New Revision: 933882f73971546d529ab225cb9bb982ed5ff47b
URL: https://github.com/llvm/llvm-project/commit/933882f73971546d529ab225cb9bb982ed5ff47b
DIFF: https://github.com/llvm/llvm-project/commit/933882f73971546d529ab225cb9bb982ed5ff47b.diff
LOG: [flang][runtime] Fix trailing blanks for Gw.dEe output editing (#75263)
When generalized numeric output editing of real data maps to Fw.d output
editing, either two or four trailing blanks are emitted depending on the
presence and value of 'e'. The code that detects field width overflow
didn't take these trailing blanks into account, and sometimes the field
width adjustment was producing an F0.d output edit descriptor (no fixed
field width). Fix by retaining the original field width, but requiring
it to also accommodate the trailing blanks.
Fixes llvm-test-suite/Fortran/gfortran/regression/fmt_g.f.
Added:
Modified:
flang/runtime/edit-output.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 32b13a8007d0cd..26e066c85fed39 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -341,11 +341,12 @@ bool RealOutputEditing<KIND>::EditEorDOutput(const DataEdit &edit) {
ConvertToDecimal(significantDigits, edit.modes.round, flags)};
if (IsInfOrNaN(converted.str, static_cast<int>(converted.length))) {
return editWidth > 0 &&
- converted.length > static_cast<std::size_t>(editWidth)
+ converted.length + trailingBlanks_ >
+ static_cast<std::size_t>(editWidth)
? EmitRepeated(io_, '*', editWidth)
: EmitPrefix(edit, converted.length, editWidth) &&
EmitAscii(io_, converted.str, converted.length) &&
- EmitSuffix(edit);
+ EmitRepeated(io_, ' ', trailingBlanks_) && EmitSuffix(edit);
}
if (!IsZero()) {
converted.decimalExponent -= scale;
@@ -522,8 +523,9 @@ bool RealOutputEditing<KIND>::EditFOutput(const DataEdit &edit) {
zeroesBeforePoint = 1; // "." -> "0."
}
int totalLength{signLength + digitsBeforePoint + zeroesBeforePoint +
- 1 /*'.'*/ + zeroesAfterPoint + digitsAfterPoint + trailingZeroes};
- int width{editWidth > 0 ? editWidth : totalLength};
+ 1 /*'.'*/ + zeroesAfterPoint + digitsAfterPoint + trailingZeroes +
+ trailingBlanks_ /* G editing converted to F */};
+ int width{editWidth > 0 || trailingBlanks_ ? editWidth : totalLength};
if (totalLength > width) {
return EmitRepeated(io_, '*', width);
}
@@ -574,8 +576,11 @@ DataEdit RealOutputEditing<KIND>::EditForGOutput(DataEdit edit) {
trailingBlanks_ = 0;
if (editWidth > 0) {
int expoDigits{edit.expoDigits.value_or(0)};
+ // F'2023 13.7.5.2.3 p5: "If 0 <= s <= d, the scale factor has no effect
+ // and F(w − n).(d − s),n(’b’) editing is used where b is a blank and
+ // n is 4 for Gw.d editing, e + 2 for Gw.dEe editing if e > 0, and
+ // 4 for Gw.dE0 editing."
trailingBlanks_ = expoDigits > 0 ? expoDigits + 2 : 4; // 'n'
- *edit.width = std::max(0, editWidth - trailingBlanks_);
}
if (edit.digits.has_value()) {
*edit.digits = std::max(0, *edit.digits - expo);
More information about the flang-commits
mailing list