[flang-commits] [flang] 604016d - [flang][runtime] Fix bug with extra leading zero in octal output

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Jun 3 17:07:21 PDT 2022


Author: Peter Klausler
Date: 2022-06-03T17:02:07-07:00
New Revision: 604016dbe4790da5ca4f789cad46b695cb137b6f

URL: https://github.com/llvm/llvm-project/commit/604016dbe4790da5ca4f789cad46b695cb137b6f
DIFF: https://github.com/llvm/llvm-project/commit/604016dbe4790da5ca4f789cad46b695cb137b6f.diff

LOG: [flang][runtime] Fix bug with extra leading zero in octal output

Octal (O) output editing often emits an extra leading 0 digit
due to the total digit count being off by one since word sizes
aren't multiples of three bits.

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

Added: 
    

Modified: 
    flang/runtime/edit-output.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index eca27e3e2c0cf..fd9b70f753d88 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -21,7 +21,11 @@ static bool EditBOZOutput(IoStatementState &io, const DataEdit &edit,
     const unsigned char *data0, std::size_t bytes) {
   int digits{static_cast<int>((bytes * 8) / LOG2_BASE)};
   int get{static_cast<int>(bytes * 8) - digits * LOG2_BASE};
-  get = get ? get : LOG2_BASE;
+  if (get > 0) {
+    ++digits;
+  } else {
+    get = LOG2_BASE;
+  }
   int shift{7};
   int increment{isHostLittleEndian ? -1 : 1};
   const unsigned char *data{data0 + (isHostLittleEndian ? bytes - 1 : 0)};


        


More information about the flang-commits mailing list