[flang-commits] [flang] 2750556 - [flang] Roll up small fixes to runtime bugs found in testing
peter klausler via flang-commits
flang-commits at lists.llvm.org
Thu Jun 18 14:25:54 PDT 2020
Author: peter klausler
Date: 2020-06-18T14:25:04-07:00
New Revision: 27505565515ee8b680cfca3ca32211b2564a6a66
URL: https://github.com/llvm/llvm-project/commit/27505565515ee8b680cfca3ca32211b2564a6a66
DIFF: https://github.com/llvm/llvm-project/commit/27505565515ee8b680cfca3ca32211b2564a6a66.diff
LOG: [flang] Roll up small fixes to runtime bugs found in testing
Summary:
Fix several bugs in the Fortran runtime found in initial
testing.
Reviewers: tskeith, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby
Reviewed By: tskeith, PeteSteinfeld
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D82116
Added:
Modified:
flang/runtime/connection.h
flang/runtime/format-implementation.h
flang/runtime/stop.cpp
flang/runtime/unit.cpp
Removed:
################################################################################
diff --git a/flang/runtime/connection.h b/flang/runtime/connection.h
index 67d4d77fd4fb..d45ccfb51901 100644
--- a/flang/runtime/connection.h
+++ b/flang/runtime/connection.h
@@ -40,7 +40,7 @@ struct ConnectionState : public ConnectionAttributes {
// Positions in a record file (sequential or direct, not stream)
std::int64_t currentRecordNumber{1}; // 1 is first
std::int64_t positionInRecord{0}; // offset in current record
- std::int64_t furthestPositionInRecord{0}; // max(positionInRecord)
+ std::int64_t furthestPositionInRecord{0}; // max(position+bytes)
bool nonAdvancing{false}; // ADVANCE='NO'
// Set at end of non-advancing I/O data transfer
diff --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h
index 21cb41c26266..ce0e08b99005 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang/runtime/format-implementation.h
@@ -225,14 +225,14 @@ int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
while (true) {
std::optional<int> repeat;
bool unlimited{false};
- CharType ch{Capitalize(GetNextChar(context))};
+ CharType ch{GetNextChar(context)};
while (ch == ',' || ch == ':') {
// Skip commas, and don't complain if they're missing; the format
// validator does that.
if (stop && ch == ':') {
return 0;
}
- ch = Capitalize(GetNextChar(context));
+ ch = GetNextChar(context);
}
if (ch == '-' || ch == '+' || (ch >= '0' && ch <= '9')) {
repeat = GetIntField(context, ch);
@@ -246,6 +246,7 @@ int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
return 0;
}
}
+ ch = Capitalize(ch);
if (ch == '(') {
if (height_ >= maxHeight_) {
context.SignalError(IostatErrorInFormat,
diff --git a/flang/runtime/stop.cpp b/flang/runtime/stop.cpp
index 321b060d8b91..cd91b77cff1c 100644
--- a/flang/runtime/stop.cpp
+++ b/flang/runtime/stop.cpp
@@ -42,8 +42,14 @@ static void DescribeIEEESignaledExceptions() {
}
}
+static void CloseAllExternalUnits(const char *why) {
+ Fortran::runtime::io::IoErrorHandler handler{why};
+ Fortran::runtime::io::ExternalFileUnit::CloseAll(handler);
+}
+
[[noreturn]] void RTNAME(StopStatement)(
int code, bool isErrorStop, bool quiet) {
+ CloseAllExternalUnits("STOP statement");
if (!quiet) {
if (code != EXIT_SUCCESS) {
std::fprintf(stderr, "Fortran %s: code %d\n",
@@ -56,6 +62,7 @@ static void DescribeIEEESignaledExceptions() {
[[noreturn]] void RTNAME(StopStatementText)(
const char *code, bool isErrorStop, bool quiet) {
+ CloseAllExternalUnits("STOP statement");
if (!quiet) {
std::fprintf(
stderr, "Fortran %s: %s\n", isErrorStop ? "ERROR STOP" : "STOP", code);
@@ -66,12 +73,12 @@ static void DescribeIEEESignaledExceptions() {
[[noreturn]] void RTNAME(FailImageStatement)() {
Fortran::runtime::NotifyOtherImagesOfFailImageStatement();
+ CloseAllExternalUnits("FAIL IMAGE statement");
std::exit(EXIT_FAILURE);
}
[[noreturn]] void RTNAME(ProgramEndStatement)() {
- Fortran::runtime::io::IoErrorHandler handler{"END statement"};
- Fortran::runtime::io::ExternalFileUnit::CloseAll(handler);
+ CloseAllExternalUnits("END statement");
std::exit(EXIT_SUCCESS);
}
}
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 0661d55134f4..81035ab6fcde 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -129,6 +129,10 @@ bool ExternalFileUnit::Emit(
return false;
}
WriteFrame(frameOffsetInFile_, recordOffsetInFrame_ + furthestAfter, handler);
+ if (positionInRecord > furthestPositionInRecord) {
+ std::memset(Frame() + furthestPositionInRecord, ' ',
+ positionInRecord - furthestPositionInRecord);
+ }
std::memcpy(Frame() + positionInRecord, data, bytes);
positionInRecord += bytes;
furthestPositionInRecord = furthestAfter;
@@ -189,7 +193,7 @@ bool ExternalFileUnit::AdvanceRecord(IoErrorHandler &handler) {
' ', *recordLength - furthestPositionInRecord);
}
} else {
- positionInRecord = furthestPositionInRecord + 1;
+ positionInRecord = furthestPositionInRecord;
ok &= Emit("\n", 1, handler); // TODO: Windows CR+LF
frameOffsetInFile_ += recordOffsetInFrame_ + furthestPositionInRecord;
recordOffsetInFrame_ = 0;
More information about the flang-commits
mailing list