[flang-commits] [flang] [flang][runtime] Don't prematurely end formatted integer input (PR #76643)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Dec 30 16:36:38 PST 2023


https://github.com/klausler updated https://github.com/llvm/llvm-project/pull/76643

>From f94d77a69d9c1448b63b975ab680abf7eff3d6c5 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Sat, 30 Dec 2023 16:26:19 -0800
Subject: [PATCH] [flang][runtime] Don't prematurely end formatted integer
 input

When an input data-list has more items than can be read by a
format from the input record (e.g., "(4I5)" reading "1 2"),
don't return false from EditIntegerInput() just because nothing
was read -- that will prevent later items from being set to zero,
as they should be.  Return true unless nothing was read and there
is some kind of error pending.

Fixes llvm-error-tests/Fortran/gfortran/regression/pr478478.f90.
---
 flang/runtime/edit-input.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index c4fa186e289db2..e13e50fd3b10e5 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -243,7 +243,7 @@ bool EditIntegerInput(
   if (sign == '-') {
     value = -value;
   }
-  if (any || !io.GetConnectionState().IsAtEOF()) {
+  if (any || !io.GetIoErrorHandler().InError()) {
     // The value is stored in the lower order bits on big endian platform.
     // When memcpy, shift the value to the higher order bit.
     auto shft{static_cast<int>(sizeof(value.low())) - kind};
@@ -254,8 +254,10 @@ bool EditIntegerInput(
     } else {
       std::memcpy(n, &value, kind); // a blank field means zero
     }
+    return true;
+  } else {
+    return false;
   }
-  return any;
 }
 
 // Parses a REAL input number from the input source as a normalized



More information about the flang-commits mailing list