[flang-commits] [flang] d02b318 - [flang] Remove typo that affected complex namelist input

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Nov 22 15:06:53 PST 2021


Author: Peter Klausler
Date: 2021-11-22T15:06:46-08:00
New Revision: d02b318af636a887e85741a5fe699fe3852d1199

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

LOG: [flang] Remove typo that affected complex namelist input

A recent patch to real/complex formatted input included what must
have been an editing hiccup: "++ ++p" instead of "++p".  This
compiles, and it broke the consumption of the trailing ')' of a
complex value in namelist input by skipping over the character.

Extend existing test to cover this case.

Differential Revision: https://reviews.llvm.org/D114297

Added: 
    

Modified: 
    flang/runtime/edit-input.cpp
    flang/unittests/Runtime/NumericalFormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index a14216d51deab..3251db1fed84f 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -303,15 +303,15 @@ static bool TryFastPathRealInput(
   for (; p < limit && (*p == ' ' || *p == '\t'); ++p) {
   }
   if (edit.descriptor == DataEdit::ListDirectedImaginaryPart) {
-    // Need a trailing ')'
+    // Need to consume a trailing ')' and any white space after
     if (p >= limit || *p != ')') {
       return false;
     }
-    for (++ ++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
+    for (++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
     }
   }
-  if (p < limit) {
-    return false; // unconverted characters remain in field
+  if (edit.width && p < str + *edit.width) {
+    return false; // unconverted characters remain in fixed width field
   }
   // Success on the fast path!
   // TODO: raise converted.flags as exceptions?

diff  --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang/unittests/Runtime/NumericalFormatTest.cpp
index a1f0a976b38ee..a2bd63524cb95 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang/unittests/Runtime/NumericalFormatTest.cpp
@@ -144,11 +144,11 @@ TEST(IOApiTests, MultilineOutputTest) {
 }
 
 TEST(IOApiTests, ListInputTest) {
-  static const char input[]{",1*,(5.,6..)"};
+  static const char input[]{",1*,(5.,6.),(7.0,8.0)"};
   auto cookie{IONAME(BeginInternalListInput)(input, sizeof input - 1)};
 
   // Create real values for IO tests
-  static constexpr int numRealValues{6};
+  static constexpr int numRealValues{8};
   float z[numRealValues];
   for (int j{0}; j < numRealValues; ++j) {
     z[j] = -(j + 1);
@@ -166,7 +166,7 @@ TEST(IOApiTests, ListInputTest) {
                        << static_cast<int>(status);
 
   // Ensure writing complex values from floats does not result in an error
-  static constexpr int bufferSize{33};
+  static constexpr int bufferSize{39};
   char output[bufferSize];
   output[bufferSize - 1] = '\0';
   cookie = IONAME(BeginInternalListOutput)(output, bufferSize - 1);
@@ -182,7 +182,8 @@ TEST(IOApiTests, ListInputTest) {
                        << static_cast<int>(status);
 
   // Verify output buffer against expected value
-  static const char expect[bufferSize]{" (-1.,-2.) (-3.,-4.) (5.,6.)    "};
+  static const char expect[bufferSize]{
+      " (-1.,-2.) (-3.,-4.) (5.,6.) (7.,8.)  "};
   ASSERT_EQ(std::strncmp(output, expect, bufferSize), 0)
       << "Failed complex list-directed output, expected '" << expect
       << "', but got '" << output << "'";


        


More information about the flang-commits mailing list