forked from OSchip/llvm-project
[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
This commit is contained in:
parent
7b8fbb796c
commit
e3550f1903
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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)");
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue