[flang-commits] [flang] 2e08e82 - [flang][runtime] Extension: allow a comma to terminate a fixed input … (#76768)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 15 09:47:56 PST 2024
Author: Peter Klausler
Date: 2024-01-15T09:47:52-08:00
New Revision: 2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7
URL: https://github.com/llvm/llvm-project/commit/2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7
DIFF: https://github.com/llvm/llvm-project/commit/2e08e821b7ea5bf7c0fe0775feb94a7fdb5204c7.diff
LOG: [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.
Added:
Modified:
flang/docs/Extensions.md
flang/runtime/edit-input.cpp
Removed:
################################################################################
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 02ccd51dcb686a..98689071441703 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 71e7f4edbd0e19..6bffe24f03ca74 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
}
}
More information about the flang-commits
mailing list