[flang-commits] [flang] d8364e3 - [flang] Allow tabs as white space in formats

V Donaldson via flang-commits flang-commits at lists.llvm.org
Wed Feb 16 17:50:04 PST 2022


Author: V Donaldson
Date: 2022-02-16T17:49:52-08:00
New Revision: d8364e3ea4ed50498d9721cdf87e06f81cf23d69

URL: https://github.com/llvm/llvm-project/commit/d8364e3ea4ed50498d9721cdf87e06f81cf23d69
DIFF: https://github.com/llvm/llvm-project/commit/d8364e3ea4ed50498d9721cdf87e06f81cf23d69.diff

LOG: [flang] Allow tabs as white space in formats

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 7ca3faa79f290..9ba76e919b7fd 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -149,9 +149,20 @@ template <typename CHAR = char> class FormatValidator {
   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>::NextChar() {
 
 template <typename CHAR> CHAR FormatValidator<CHAR>::LookAheadChar() {
   for (laCursor_ = cursor_ + 1; laCursor_ < end_; ++laCursor_) {
-    if (*laCursor_ != ' ') {
+    if (!IsWhite(*cursor_)) {
       return toupper(*laCursor_);
     }
   }

diff  --git a/flang/test/Semantics/io08.f90 b/flang/test/Semantics/io08.f90
index 843028acfd5bf..b4e8d9f4b6a01 100644
--- a/flang/test/Semantics/io08.f90
+++ b/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)')


        


More information about the flang-commits mailing list