[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:30:46 PST 2023


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

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.

>From 84340073ecdf6982842691079cbf03f891cce441 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 2b809749067772..ce55a03094841c 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -243,10 +243,12 @@ bool EditIntegerInput(
   if (sign == '-') {
     value = -value;
   }
-  if (any || !io.GetConnectionState().IsAtEOF()) {
+  if (any || !io.GetIoErrorHandler().InError()) {
     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