[flang-commits] [PATCH] D151738: [flang] Detect output field width overflow for Inf/NaN
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue May 30 10:57:32 PDT 2023
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The output editing code paths for F and E/D output that handle
IEEE-754 infinities and NaNs fail to check for overflow of the
output field, which should cause the field to be filled with
asterisks instead. Catch these cases.
https://reviews.llvm.org/D151738
Files:
flang/runtime/edit-output.cpp
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -320,8 +320,12 @@
decimal::ConversionToDecimalResult converted{
Convert(significantDigits, edit.modes.round, flags)};
if (IsInfOrNaN(converted)) {
- return EmitPrefix(edit, converted.length, editWidth) &&
- EmitAscii(io_, converted.str, converted.length) && EmitSuffix(edit);
+ return editWidth > 0 &&
+ converted.length > static_cast<std::size_t>(editWidth)
+ ? EmitRepeated(io_, '*', editWidth)
+ : EmitPrefix(edit, converted.length, editWidth) &&
+ EmitAscii(io_, converted.str, converted.length) &&
+ EmitSuffix(edit);
}
if (!IsZero()) {
converted.decimalExponent -= scale;
@@ -415,8 +419,12 @@
decimal::ConversionToDecimalResult converted{
Convert(extraDigits + fracDigits, rounding, flags)};
if (IsInfOrNaN(converted)) {
- return EmitPrefix(edit, converted.length, editWidth) &&
- EmitAscii(io_, converted.str, converted.length) && EmitSuffix(edit);
+ return editWidth > 0 &&
+ converted.length > static_cast<std::size_t>(editWidth)
+ ? EmitRepeated(io_, '*', editWidth)
+ : EmitPrefix(edit, converted.length, editWidth) &&
+ EmitAscii(io_, converted.str, converted.length) &&
+ EmitSuffix(edit);
}
int expo{converted.decimalExponent + edit.modes.scale /*kP*/};
int signLength{*converted.str == '-' || *converted.str == '+' ? 1 : 0};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151738.526715.patch
Type: text/x-patch
Size: 1638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230530/57238209/attachment-0001.bin>
More information about the flang-commits
mailing list