[flang-commits] [PATCH] D119987: [flang] Allow tabs as white space in formats

vdonaldson via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Feb 16 15:39:37 PST 2022


vdonaldson created this revision.
vdonaldson added a project: Flang.
Herald added a subscriber: jdoerfert.
vdonaldson requested review of this revision.

The fortran standard views blanks in IO formats as white space in
non-string contexts.  Other compilers extend this to also view horizontal
tabs as white space.  Some compilers additionally add other white space
characters to this group.

Add recognition of horizontal and vertical tabs to runtime format
validation code to match what the runtime code currently does.


https://reviews.llvm.org/D119987

Files:
  flang/include/flang/Common/format.h
  flang/test/Semantics/io08.f90


Index: flang/test/Semantics/io08.f90
===================================================================
--- flang/test/Semantics/io08.f90
+++ flang/test/Semantics/io08.f90
@@ -37,6 +37,9 @@
   write(*,'($)')
   write(*,'(\)')
   write(*,'(RZ,RU,RP,RN,RD,RC,SS,SP,S,3G15.3e2)')
+  write(*, '(' // achar( 9) // ')') ! horizontal tab
+  write(*, '(' // achar(11) // ')') ! vertical tab
+  write(*, '(' // achar(32) // ')') ! space
 
   ! C1302 warnings; no errors
   write(*,'(3P7I2)')
Index: flang/include/flang/Common/format.h
===================================================================
--- flang/include/flang/Common/format.h
+++ flang/include/flang/Common/format.h
@@ -149,9 +149,20 @@
   int maxNesting_{0}; // max level of nested parentheses
 };
 
+template <typename CHAR> static inline bool IsWhite(CHAR c) {
+  // White space.  ' ' is standard.  Other characters are extensions.
+  // Extension candidates:
+  //   '\t' (horizontal tab)
+  //   '\n' (new line)
+  //   '\v' (vertical tab)
+  //   '\f' (form feed)
+  //   '\r' (carriage ret)
+  return c == ' ' || c == '\t' || c == '\v';
+}
+
 template <typename CHAR> CHAR FormatValidator<CHAR>::NextChar() {
   for (++cursor_; cursor_ < end_; ++cursor_) {
-    if (*cursor_ != ' ') {
+    if (!IsWhite(*cursor_)) {
       return toupper(*cursor_);
     }
   }
@@ -161,7 +172,7 @@
 
 template <typename CHAR> CHAR FormatValidator<CHAR>::LookAheadChar() {
   for (laCursor_ = cursor_ + 1; laCursor_ < end_; ++laCursor_) {
-    if (*laCursor_ != ' ') {
+    if (!IsWhite(*cursor_)) {
       return toupper(*laCursor_);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119987.409439.patch
Type: text/x-patch
Size: 1595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220216/065882dc/attachment.bin>


More information about the flang-commits mailing list