From 44ff4df6debf5a8d8fd1478ed6da0e374e669a8d Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 16 Feb 2022 16:41:53 -0800 Subject: [PATCH] [flang] Extension: don't require commas between most edit descriptors in formats The standard explicitly allows a comma to be omitted between a 'P' edit descriptor and a following numeric edit descriptor (e.g., 1PE10.1), and before and after a '/' edit descriptor, but otherwise requires them between edit descriptors. Most implementations, however, only require commas where they prevent ambiguity, and accept things like 1XI10. This extension is already assumed by the static FORMAT checker in semantics. Patch the runtime to behave accordingly. Differential Revision: https://reviews.llvm.org/D120747 --- flang/docs/Extensions.md | 2 ++ flang/runtime/format-implementation.h | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md index 4953186..4a03874 100644 --- a/flang/docs/Extensions.md +++ b/flang/docs/Extensions.md @@ -217,6 +217,8 @@ end * At runtime, `NAMELIST` input will skip over `NAMELIST` groups with other names, and will treat text before and between groups as if they were comment lines, even if not begun with `!`. +* Commas are required in FORMAT statements and character variables + only when they prevent ambiguity. ### Extensions supported when enabled by options diff --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h index 6b1a64b..11f3ad7 100644 --- a/flang/runtime/format-implementation.h +++ b/flang/runtime/format-implementation.h @@ -301,8 +301,14 @@ int FormatControl::CueUpNextDataEdit(Context &context, bool stop) { if (ch != 'P') { // 1PE5.2 - comma not required (C1302) CharType peek{Capitalize(PeekNext())}; if (peek >= 'A' && peek <= 'Z') { - next = peek; - ++offset_; + if (ch == 'A' /* anticipate F'202X AT editing */ || ch == 'B' || + ch == 'D' || ch == 'E' || ch == 'R' || ch == 'S' || ch == 'T') { + // Assume a two-letter edit descriptor + next = peek; + ++offset_; + } else { + // extension: assume a comma between 'ch' and 'peek' + } } } if ((!next && -- 2.7.4