[flang-commits] [flang] e3550f1 - [flang] Improve runtime crash messages
Peter Steinfeld via flang-commits
flang-commits at lists.llvm.org
Sat Mar 12 16:04:29 PST 2022
Author: Peter Steinfeld
Date: 2022-03-12T15:15:56-08:00
New Revision: e3550f1903d21d0355a37dc481b94e073609a5b3
URL: https://github.com/llvm/llvm-project/commit/e3550f1903d21d0355a37dc481b94e073609a5b3
DIFF: https://github.com/llvm/llvm-project/commit/e3550f1903d21d0355a37dc481b94e073609a5b3.diff
LOG: [flang] Improve runtime crash messages
Where possible, I added additional information to the messages to help
programmers figure out what went wrong. I also removed all uses of the word
"bad" from the messages since (to me) that implies a moral judgement rather
than a programming error. I replaced it with either "invalid" or "unsupported"
where appropriate.
Differential Revision: https://reviews.llvm.org/D121493
Added:
Modified:
flang/runtime/descriptor-io.h
flang/runtime/extrema.cpp
flang/runtime/findloc.cpp
flang/runtime/inquiry.cpp
flang/runtime/io-api.cpp
flang/runtime/io-stmt.cpp
flang/runtime/iostat.cpp
flang/runtime/random.cpp
flang/runtime/reduction-templates.h
flang/runtime/reduction.cpp
flang/runtime/transformational.cpp
flang/runtime/unit.cpp
Removed:
################################################################################
diff --git a/flang/runtime/descriptor-io.h b/flang/runtime/descriptor-io.h
index 1e78a826f04db..f6528762795a2 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang/runtime/descriptor-io.h
@@ -480,7 +480,7 @@ static bool DescriptorIO(IoStatementState &io, const Descriptor &descriptor) {
return FormattedDerivedTypeIO<DIR>(io, descriptor);
}
}
- handler.Crash("DescriptorIO: Bad type code (%d) in descriptor",
+ handler.Crash("DescriptorIO: bad type code (%d) in descriptor",
static_cast<int>(descriptor.type().raw()));
return false;
}
diff --git a/flang/runtime/extrema.cpp b/flang/runtime/extrema.cpp
index 3e471b3c09c15..c68caec52ea32 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang/runtime/extrema.cpp
@@ -176,7 +176,7 @@ inline void TypedMaxOrMinLoc(const char *intrinsic, Descriptor &result,
break;
default:
terminator.Crash(
- "%s: Bad data type code (%d) for array", intrinsic, x.type().raw());
+ "%s: bad data type code (%d) for array", intrinsic, x.type().raw());
}
}
@@ -262,7 +262,7 @@ inline void TypedPartialMaxOrMinLoc(const char *intrinsic, Descriptor &result,
break;
default:
terminator.Crash(
- "%s: Bad data type code (%d) for array", intrinsic, x.type().raw());
+ "%s: bad data type code (%d) for array", intrinsic, x.type().raw());
}
}
diff --git a/flang/runtime/findloc.cpp b/flang/runtime/findloc.cpp
index f268d462b43bf..6a3aaef882072 100644
--- a/flang/runtime/findloc.cpp
+++ b/flang/runtime/findloc.cpp
@@ -248,7 +248,7 @@ void RTNAME(Findloc)(Descriptor &result, const Descriptor &x,
break;
default:
terminator.Crash(
- "FINDLOC: Bad data type code (%d) for array", x.type().raw());
+ "FINDLOC: bad data type code (%d) for array", x.type().raw());
}
}
} // extern "C"
@@ -335,7 +335,7 @@ void RTNAME(FindlocDim)(Descriptor &result, const Descriptor &x,
break;
default:
terminator.Crash(
- "FINDLOC: Bad data type code (%d) for array", x.type().raw());
+ "FINDLOC: bad data type code (%d) for array", x.type().raw());
}
}
} // extern "C"
diff --git a/flang/runtime/inquiry.cpp b/flang/runtime/inquiry.cpp
index 1f67020f2cafd..5dc692c9a384a 100644
--- a/flang/runtime/inquiry.cpp
+++ b/flang/runtime/inquiry.cpp
@@ -23,7 +23,8 @@ std::int64_t RTNAME(LboundDim)(
const Descriptor &array, int dim, const char *sourceFile, int line) {
if (dim < 1 || dim > array.rank()) {
Terminator terminator{sourceFile, line};
- terminator.Crash("SIZE: bad DIM=%d", dim);
+ terminator.Crash(
+ "SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
}
const Dimension &dimension{array.GetDimension(dim - 1)};
return static_cast<std::int64_t>(dimension.LowerBound());
@@ -68,7 +69,8 @@ std::int64_t RTNAME(SizeDim)(
const Descriptor &array, int dim, const char *sourceFile, int line) {
if (dim < 1 || dim > array.rank()) {
Terminator terminator{sourceFile, line};
- terminator.Crash("SIZE: bad DIM=%d", dim);
+ terminator.Crash(
+ "SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
}
const Dimension &dimension{array.GetDimension(dim - 1)};
return static_cast<std::int64_t>(dimension.Extent());
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index e097867518c73..8733463e63083 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -564,7 +564,7 @@ bool IONAME(SetPos)(Cookie cookie, std::int64_t pos) {
unit->SetPosition(pos - 1, handler);
return true;
}
- io.GetIoErrorHandler().Crash("SetPos() on internal unit");
+ io.GetIoErrorHandler().Crash("SetPos() called on internal unit");
return false;
}
@@ -937,7 +937,7 @@ bool IONAME(GetNewUnit)(Cookie cookie, int &unit, int kind) {
}
std::int64_t result{open->unit().unitNumber()};
if (!SetInteger(unit, kind, result)) {
- open->SignalError("GetNewUnit(): Bad INTEGER kind(%d) or out-of-range "
+ open->SignalError("GetNewUnit(): bad INTEGER kind(%d) or out-of-range "
"value(%jd) for result",
kind, static_cast<std::intmax_t>(result));
}
@@ -1209,7 +1209,8 @@ bool IONAME(InquireInteger64)(
return true;
}
io.GetIoErrorHandler().SignalError(
- "InquireInteger64(): Bad INTEGER kind(%d) or out-of-range value(%jd) "
+ "InquireInteger64(): bad INTEGER kind(%d) or out-of-range "
+ "value(%jd) "
"for result",
kind, static_cast<std::intmax_t>(n));
}
diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index b86559631d1db..9415029201eae 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -78,7 +78,7 @@ bool IoStatementBase::Inquire(InquiryKeywordHash, std::int64_t &) {
void IoStatementBase::BadInquiryKeywordHashCrash(InquiryKeywordHash inquiry) {
char buffer[16];
const char *decode{InquiryKeywordHashDecode(buffer, sizeof buffer, inquiry)};
- Crash("bad InquiryKeywordHash 0x%x (%s)", inquiry,
+ Crash("Bad InquiryKeywordHash 0x%x (%s)", inquiry,
decode ? decode : "(cannot decode)");
}
diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp
index f1d20c1a23b0b..994af4f2a4f78 100644
--- a/flang/runtime/iostat.cpp
+++ b/flang/runtime/iostat.cpp
@@ -30,7 +30,7 @@ const char *IostatErrorString(int iostat) {
case IostatInternalWriteOverrun:
return "Internal write overran available records";
case IostatErrorInFormat:
- return "Invalid FORMAT";
+ return "Bad FORMAT";
case IostatErrorInKeyword:
return "Bad keyword argument value";
case IostatEndfileDirect:
diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp
index f425046235215..a2753da70af12 100644
--- a/flang/runtime/random.cpp
+++ b/flang/runtime/random.cpp
@@ -108,7 +108,7 @@ void RTNAME(RandomNumber)(
break;
#endif
default:
- terminator.Crash("RANDOM_NUMBER(): unsupported REAL kind %d", kind);
+ terminator.Crash("RANDOM_NUMBER(): bad REAL kind %d", kind);
}
}
diff --git a/flang/runtime/reduction-templates.h b/flang/runtime/reduction-templates.h
index 11b491a6466a5..93e987a04e5cb 100644
--- a/flang/runtime/reduction-templates.h
+++ b/flang/runtime/reduction-templates.h
@@ -44,8 +44,8 @@ inline void DoTotalReduction(const Descriptor &x, int dim,
const Descriptor *mask, ACCUMULATOR &accumulator, const char *intrinsic,
Terminator &terminator) {
if (dim < 0 || dim > 1) {
- terminator.Crash(
- "%s: bad DIM=%d for argument with rank %d", intrinsic, dim, x.rank());
+ terminator.Crash("%s: bad DIM=%d for ARRAY argument with rank %d",
+ intrinsic, dim, x.rank());
}
SubscriptValue xAt[maxRank];
x.GetLowerBounds(xAt);
@@ -166,7 +166,8 @@ static void CreatePartialReductionResult(Descriptor &result,
TypeCode typeCode) {
int xRank{x.rank()};
if (dim < 1 || dim > xRank) {
- terminator.Crash("%s: bad DIM=%d for rank %d", intrinsic, dim, xRank);
+ terminator.Crash(
+ "%s: bad DIM=%d for ARRAY with rank %d", intrinsic, dim, xRank);
}
int zeroBasedDim{dim - 1};
SubscriptValue resultExtent[maxRank];
@@ -295,7 +296,7 @@ inline void TypedPartialNumericReduction(Descriptor &result,
intrinsic);
break;
default:
- terminator.Crash("%s: invalid type code %d", intrinsic, x.type().raw());
+ terminator.Crash("%s: bad type code %d", intrinsic, x.type().raw());
}
}
diff --git a/flang/runtime/reduction.cpp b/flang/runtime/reduction.cpp
index dea25cf8dc764..c828f06d52276 100644
--- a/flang/runtime/reduction.cpp
+++ b/flang/runtime/reduction.cpp
@@ -228,7 +228,7 @@ inline auto GetTotalLogicalReduction(const Descriptor &x, const char *source,
typename ACCUMULATOR::Type {
Terminator terminator{source, line};
if (dim < 0 || dim > 1) {
- terminator.Crash("%s: bad DIM=%d", intrinsic, dim);
+ terminator.Crash("%s: bad DIM=%d for ARRAY with rank=1", intrinsic, dim);
}
SubscriptValue xAt[maxRank];
x.GetLowerBounds(xAt);
diff --git a/flang/runtime/transformational.cpp b/flang/runtime/transformational.cpp
index fef4eacc508fb..aac6e61ce9dd7 100644
--- a/flang/runtime/transformational.cpp
+++ b/flang/runtime/transformational.cpp
@@ -525,12 +525,15 @@ void RTNAME(Unpack)(Descriptor &result, const Descriptor &vector,
}
mask.GetLowerBounds(maskAt);
field.GetLowerBounds(fieldAt);
- SubscriptValue vectorLeft{vector.GetDimension(0).Extent()};
+ SubscriptValue vectorElements{vector.GetDimension(0).Extent()};
+ SubscriptValue vectorLeft{vectorElements};
for (std::size_t n{result.Elements()}; n-- > 0;) {
if (IsLogicalElementTrue(mask, maskAt)) {
if (vectorLeft-- == 0) {
- terminator.Crash("UNPACK: VECTOR= argument has fewer elements than "
- "MASK= has .TRUE. entries");
+ terminator.Crash(
+ "UNPACK: VECTOR= argument has fewer elements (%d) than "
+ "MASK= has .TRUE. entries",
+ vectorElements);
}
CopyElement(result, resultAt, vector, &vectorAt, terminator);
++vectorAt;
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index cef971d00c740..87b11820609a3 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -48,7 +48,7 @@ ExternalFileUnit &ExternalFileUnit::LookUpOrCrash(
int unit, const Terminator &terminator) {
ExternalFileUnit *file{LookUp(unit)};
if (!file) {
- terminator.Crash("Not an open I/O unit number: %d", unit);
+ terminator.Crash("%d is not an open I/O unit number", unit);
}
return *file;
}
@@ -855,7 +855,8 @@ bool ExternalFileUnit::CheckDirectAccess(IoErrorHandler &handler) {
if (access == Access::Direct) {
RUNTIME_CHECK(handler, openRecl);
if (!directAccessRecWasSet_) {
- handler.SignalError("No REC= was specified for a data transfer with ACCESS='DIRECT'");
+ handler.SignalError(
+ "No REC= was specified for a data transfer with ACCESS='DIRECT'");
return false;
}
}
More information about the flang-commits
mailing list