[flang-commits] [flang] e468f07 - [flang] Set "undefined" NEXTREC=n variable to 0 rather than random garbage
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Jun 6 11:58:27 PDT 2023
Author: Peter Klausler
Date: 2023-06-06T11:58:01-07:00
New Revision: e468f07550c56eeb49659d02c7c5c3f79f53db6f
URL: https://github.com/llvm/llvm-project/commit/e468f07550c56eeb49659d02c7c5c3f79f53db6f
DIFF: https://github.com/llvm/llvm-project/commit/e468f07550c56eeb49659d02c7c5c3f79f53db6f.diff
LOG: [flang] Set "undefined" NEXTREC=n variable to 0 rather than random garbage
12.10.2.17 defines that a INQUIRE statement's NEXTREC=n output value
for a unit that is not connected for direct access becomes undefined,
but the current I/O runtime can fail in a confusing manner by trying
to return uninitialized stack garbage.
Reported on Slack by Tarun Prabhu as an intermittent failure in
the gfortran regression test inquire_pre.f90.
Differential Revision: https://reviews.llvm.org/D152295
Added:
Modified:
flang/runtime/io-api.cpp
Removed:
################################################################################
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 09639c136c2af..4d569f898ea8b 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -1451,15 +1451,14 @@ bool IONAME(InquirePendingId)(Cookie cookie, std::int64_t id, bool &result) {
bool IONAME(InquireInteger64)(
Cookie cookie, InquiryKeywordHash inquiry, std::int64_t &result, int kind) {
IoStatementState &io{*cookie};
- std::int64_t n;
+ std::int64_t n{0}; // safe "undefined" value
if (io.Inquire(inquiry, n)) {
if (SetInteger(result, kind, n)) {
return true;
}
io.GetIoErrorHandler().SignalError(
"InquireInteger64(): bad INTEGER kind(%d) or out-of-range "
- "value(%jd) "
- "for result",
+ "value(%jd) for result",
kind, static_cast<std::intmax_t>(n));
}
return false;
More information about the flang-commits
mailing list