Skip to content

Commit

Permalink
[flang][runtime] Fix bug with extra leading zero in octal output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
klausler committed Jun 4, 2022
1 parent 66a871b commit 604016d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flang/runtime/edit-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)};
Expand Down

0 comments on commit 604016d

Please sign in to comment.