[flang-commits] [PATCH] D88688: [flang] Make binary->decimal conversion buffer sizes accurate

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Oct 1 11:28:50 PDT 2020


klausler created this revision.
klausler added a reviewer: sscalpone.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

The binary values that produce the most significant decimal
digits in an exact conversion are those with the least normal
biased exponent (1) and all fractional bits set, not the
least-valued subnormals.  So the binary->decimal conversion
buffer sizes were a little short, and could cause a overrun crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88688

Files:
  flang/include/flang/Common/real.h


Index: flang/include/flang/Common/real.h
===================================================================
--- flang/include/flang/Common/real.h
+++ flang/include/flang/Common/real.h
@@ -39,26 +39,25 @@
   }
 }
 
-// Number of significant decimal digits in the fraction of the
-// exact conversion of the least nonzero (subnormal) value
-// in each type; i.e., a 128-bit quad value can be formatted
-// exactly with FORMAT(E0.22981).
+// Maximum number of significant decimal digits in the fraction of an
+// exact conversion in each type; computed by converting the value
+// with the minimum exponent (biased to 1) and all fractional bits set.
 static constexpr int MaxDecimalConversionDigits(int binaryPrecision) {
   switch (binaryPrecision) {
   case 8:
-    return 93;
+    return 96;
   case 11:
-    return 17;
+    return 21;
   case 24:
-    return 105;
+    return 112;
   case 53:
-    return 751;
+    return 767;
   case 64:
-    return 11495;
+    return 11514;
   case 106:
-    return 2 * 751;
+    return 2 * 767;
   case 113:
-    return 11530;
+    return 11563;
   default:
     return -1;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88688.295634.patch
Type: text/x-patch
Size: 1118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201001/b880aa0e/attachment.bin>


More information about the flang-commits mailing list