[flang-commits] [flang] [flang][runtime] Extension: allow a comma to terminate a fixed input … (PR #76768)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Jan 2 16:17:56 PST 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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.

>From 0bff0aeccd01a2859f8659eb7ae5240bac898ee1 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 2 Jan 2024 16:14:47 -0800
Subject: [PATCH] [flang][runtime] Extension: allow a comma to terminate a
 fixed input 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.
---
 flang/docs/Extensions.md     | 2 ++
 flang/runtime/edit-input.cpp | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 16eb67f2e27c81..b56ebe6a92bbcf 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 integer 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 6d4fa588cbf60d..5d47b146488158 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);



More information about the flang-commits mailing list