Skip to content

Commit

Permalink
[flang] Respect BZ mode in exponent parts, too
Browse files Browse the repository at this point in the history
The Fortran standard discusses BZ mode (treat blanks as zero digits)
explicitly in its effect on the editing of the digits prior to the
exponent part, but doesn't mention it in description of the
exponent part.  Other compilers honor BZ mode in the exponent,
so we should do so too.  So "1 e 1 " is 1.E11 in BZ mode.

Differential Revision: https://reviews.llvm.org/D87653
  • Loading branch information
klausler committed Sep 15, 2020
1 parent 4667376 commit b2cf572
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions flang/runtime/edit-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ static int ScanRealInput(char *buffer, int bufferSize, IoStatementState &io,
first == 'E' || first == 'D' || first == 'Q') {
Put('.'); // input field is normalized to a fraction
auto start{got};
bool bzMode{(edit.modes.editingFlags & blankZero) != 0};
for (; next; next = io.NextInField(remaining)) {
char32_t ch{*next};
if (ch == ' ' || ch == '\t') {
if (edit.modes.editingFlags & blankZero) {
if (bzMode) {
ch = '0'; // BZ mode - treat blank as if it were zero
} else {
continue;
Expand All @@ -206,19 +207,29 @@ static int ScanRealInput(char *buffer, int bufferSize, IoStatementState &io,
if (next &&
(*next == 'e' || *next == 'E' || *next == 'd' || *next == 'D' ||
*next == 'q' || *next == 'Q')) {
// Optional exponent letter. Blanks are allowed between the
// optional exponent letter and the exponent value.
io.SkipSpaces(remaining);
next = io.NextInField(remaining);
}
exponent = -edit.modes.scale; // default exponent is -kP
// The default exponent is -kP, but the scale factor doesn't affect
// an explicit exponent.
exponent = -edit.modes.scale;
if (next &&
(*next == '-' || *next == '+' || (*next >= '0' && *next <= '9'))) {
(*next == '-' || *next == '+' || (*next >= '0' && *next <= '9') ||
(bzMode && (*next == ' ' || *next == '\t')))) {
bool negExpo{*next == '-'};
if (negExpo || *next == '+') {
next = io.NextInField(remaining);
}
for (exponent = 0; next && (*next >= '0' && *next <= '9');
next = io.NextInField(remaining)) {
exponent = 10 * exponent + *next - '0';
for (exponent = 0; next; next = io.NextInField(remaining)) {
if (*next >= '0' && *next <= '9') {
exponent = 10 * exponent + *next - '0';
} else if (bzMode && (*next == ' ' || *next == '\t')) {
exponent = 10 * exponent;
} else {
break;
}
}
if (negExpo) {
exponent = -exponent;
Expand Down
1 change: 1 addition & 0 deletions flang/unittests/Runtime/hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ int main() {
realInTest("(-1P,F18.0)", " 125", 0x4093880000000000); // 1250
realInTest("(1P,F18.0)", " 125", 0x4029000000000000); // 12.5
realInTest("(BZ,F18.0)", " 125 ", 0x4093880000000000); // 1250
realInTest("(BZ,F18.0)", " 125 . e +1 ", 0x42a6bcc41e900000); // 1.25e13
realInTest("(DC,F18.0)", " 12,5", 0x4029000000000000);

listInputTest();
Expand Down

0 comments on commit b2cf572

Please sign in to comment.