diff options
author | Peter Klausler <35819229+klausler@users.noreply.github.com> | 2024-01-15 09:47:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 09:47:52 -0800 |
commit | 2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7 (patch) | |
tree | 1da2ddc3605836749d480b7409e9f360fcfe4a25 | |
parent | 304119860ac0ded0a126ab1c8cc30367e29ebd01 (diff) | |
download | llvm-2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7.zip llvm-2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7.tar.gz llvm-2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7.tar.bz2 |
[flang][runtime] Extension: allow a comma to terminate a fixed input … (#76768)
…field
When a comma appears in a fixed-width input field for integer editing,
many compilers accept it without error and interpret the comma as
terminating the field early.
-rw-r--r-- | flang/docs/Extensions.md | 2 | ||||
-rw-r--r-- | flang/runtime/edit-input.cpp | 9 |
2 files changed, 9 insertions, 2 deletions
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md index 02ccd51..9868907 100644 --- a/flang/docs/Extensions.md +++ b/flang/docs/Extensions.md @@ -318,6 +318,8 @@ end * A `NAMELIST` input group may omit its trailing `/` character if it is followed by another `NAMELIST` input group. * A `NAMELIST` input group may begin with either `&` or `$`. +* A comma in a fixed-width numeric input field terminates the + field rather than signaling an invalid character error. ### Extensions supported when enabled by options diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp index 71e7f4e..6bffe24 100644 --- a/flang/runtime/edit-input.cpp +++ b/flang/runtime/edit-input.cpp @@ -80,6 +80,8 @@ static bool EditBOZInput( } else if (LOG2_BASE >= 4 && ch >= '8' && ch <= '9') { } else if (LOG2_BASE >= 4 && ch >= 'A' && ch <= 'F') { } else if (LOG2_BASE >= 4 && ch >= 'a' && ch <= 'f') { + } else if (ch == ',') { + break; // end non-list-directed field early } else { io.GetIoErrorHandler().SignalError( "Bad character '%lc' in B/O/Z input field", ch); @@ -214,6 +216,8 @@ bool EditIntegerInput( int digit{0}; if (ch >= '0' && ch <= '9') { digit = ch - '0'; + } else if (ch == ',') { + break; // end non-list-directed field early } else { io.GetIoErrorHandler().SignalError( "Bad character '%lc' in INTEGER input field", ch); @@ -291,7 +295,8 @@ static ScannedRealInput ScanRealInput( } bool bzMode{(edit.modes.editingFlags & blankZero) != 0}; int exponent{0}; - if (!next || (!bzMode && *next == ' ')) { + if (!next || (!bzMode && *next == ' ') || + (!(edit.modes.editingFlags & decimalComma) && *next == ',')) { if (!edit.IsListDirected() && !io.GetConnectionState().IsAtEOF()) { // An empty/blank field means zero when not list-directed. // A fixed-width field containing only a sign is also zero; @@ -473,7 +478,7 @@ static ScannedRealInput ScanRealInput( while (next && (*next == ' ' || *next == '\t')) { next = io.NextInField(remaining, edit); } - if (next) { + if (next && (*next != ',' || (edit.modes.editingFlags & decimalComma))) { return {}; // error: unused nonblank character in fixed-width field } } |