[flang-commits] [flang] 9bb091a - [flang] Handle leading zeroes after decimal in REAL formatted input

peter klausler via flang-commits flang-commits at lists.llvm.org
Tue Jul 21 18:04:22 PDT 2020


Author: peter klausler
Date: 2020-07-21T18:03:24-07:00
New Revision: 9bb091a8fc3c673dc24fed6a28da204e0ef98ac2

URL: https://github.com/llvm/llvm-project/commit/9bb091a8fc3c673dc24fed6a28da204e0ef98ac2
DIFF: https://github.com/llvm/llvm-project/commit/9bb091a8fc3c673dc24fed6a28da204e0ef98ac2.diff

LOG: [flang] Handle leading zeroes after decimal in REAL formatted input

Leading zero digits after the decimal mark were being dropped.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84282

Added: 
    

Modified: 
    flang/runtime/edit-input.cpp
    flang/unittests/Runtime/hello.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index dd708c7bfb91..9af2dbeb244c 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -177,8 +177,8 @@ static int ScanRealInput(char *buffer, int bufferSize, IoStatementState &io,
           continue;
         }
       }
-      if (ch == '0' && got == start) {
-        // omit leading zeroes
+      if (ch == '0' && got == start && !decimalPoint) {
+        // omit leading zeroes before the decimal
       } else if (ch >= '0' && ch <= '9') {
         if (got < bufferSize) {
           buffer[got++] = ch;

diff  --git a/flang/unittests/Runtime/hello.cpp b/flang/unittests/Runtime/hello.cpp
index ff806523eb5f..71d49437bfcc 100644
--- a/flang/unittests/Runtime/hello.cpp
+++ b/flang/unittests/Runtime/hello.cpp
@@ -420,11 +420,16 @@ int main() {
   realInTest("(F18.0)", "                 0", 0x0);
   realInTest("(F18.0)", "                  ", 0x0);
   realInTest("(F18.0)", "                -0", 0x8000000000000000);
+  realInTest("(F18.0)", "                01", 0x3ff0000000000000);
   realInTest("(F18.0)", "                 1", 0x3ff0000000000000);
   realInTest("(F18.0)", "              125.", 0x405f400000000000);
   realInTest("(F18.0)", "              12.5", 0x4029000000000000);
   realInTest("(F18.0)", "              1.25", 0x3ff4000000000000);
+  realInTest("(F18.0)", "             01.25", 0x3ff4000000000000);
   realInTest("(F18.0)", "              .125", 0x3fc0000000000000);
+  realInTest("(F18.0)", "             0.125", 0x3fc0000000000000);
+  realInTest("(F18.0)", "             .0625", 0x3fb0000000000000);
+  realInTest("(F18.0)", "            0.0625", 0x3fb0000000000000);
   realInTest("(F18.0)", "               125", 0x405f400000000000);
   realInTest("(F18.1)", "               125", 0x4029000000000000);
   realInTest("(F18.2)", "               125", 0x3ff4000000000000);


        


More information about the flang-commits mailing list