Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Don't prematurely end formatted integer input #76643

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

klausler
Copy link
Contributor

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.

@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Dec 31, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 31, 2023

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/76643.diff

1 Files Affected:

  • (modified) flang/runtime/edit-input.cpp (+4-2)
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

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.
@klausler klausler merged commit 9fd03cb into llvm:main Jan 2, 2024
4 checks passed
@klausler klausler deleted the pr47878 branch January 2, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants