Skip to content

Commit 04cdacf

Browse files
psteinfeldjeanPerier
authored andcommitted
[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
1 parent 6bc4946 commit 04cdacf

File tree

12 files changed

+31
-23
lines changed

12 files changed

+31
-23
lines changed

flang/runtime/descriptor-io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static bool DescriptorIO(IoStatementState &io, const Descriptor &descriptor) {
480480
return FormattedDerivedTypeIO<DIR>(io, descriptor);
481481
}
482482
}
483-
handler.Crash("DescriptorIO: Bad type code (%d) in descriptor",
483+
handler.Crash("DescriptorIO: bad type code (%d) in descriptor",
484484
static_cast<int>(descriptor.type().raw()));
485485
return false;
486486
}

flang/runtime/extrema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ inline void TypedMaxOrMinLoc(const char *intrinsic, Descriptor &result,
176176
break;
177177
default:
178178
terminator.Crash(
179-
"%s: Bad data type code (%d) for array", intrinsic, x.type().raw());
179+
"%s: bad data type code (%d) for array", intrinsic, x.type().raw());
180180
}
181181
}
182182

@@ -262,7 +262,7 @@ inline void TypedPartialMaxOrMinLoc(const char *intrinsic, Descriptor &result,
262262
break;
263263
default:
264264
terminator.Crash(
265-
"%s: Bad data type code (%d) for array", intrinsic, x.type().raw());
265+
"%s: bad data type code (%d) for array", intrinsic, x.type().raw());
266266
}
267267
}
268268

flang/runtime/findloc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void RTNAME(Findloc)(Descriptor &result, const Descriptor &x,
248248
break;
249249
default:
250250
terminator.Crash(
251-
"FINDLOC: Bad data type code (%d) for array", x.type().raw());
251+
"FINDLOC: bad data type code (%d) for array", x.type().raw());
252252
}
253253
}
254254
} // extern "C"
@@ -335,7 +335,7 @@ void RTNAME(FindlocDim)(Descriptor &result, const Descriptor &x,
335335
break;
336336
default:
337337
terminator.Crash(
338-
"FINDLOC: Bad data type code (%d) for array", x.type().raw());
338+
"FINDLOC: bad data type code (%d) for array", x.type().raw());
339339
}
340340
}
341341
} // extern "C"

flang/runtime/inquiry.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ std::int64_t RTNAME(LboundDim)(
2323
const Descriptor &array, int dim, const char *sourceFile, int line) {
2424
if (dim < 1 || dim > array.rank()) {
2525
Terminator terminator{sourceFile, line};
26-
terminator.Crash("SIZE: bad DIM=%d", dim);
26+
terminator.Crash(
27+
"SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
2728
}
2829
const Dimension &dimension{array.GetDimension(dim - 1)};
2930
return static_cast<std::int64_t>(dimension.LowerBound());
@@ -68,7 +69,8 @@ std::int64_t RTNAME(SizeDim)(
6869
const Descriptor &array, int dim, const char *sourceFile, int line) {
6970
if (dim < 1 || dim > array.rank()) {
7071
Terminator terminator{sourceFile, line};
71-
terminator.Crash("SIZE: bad DIM=%d", dim);
72+
terminator.Crash(
73+
"SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
7274
}
7375
const Dimension &dimension{array.GetDimension(dim - 1)};
7476
return static_cast<std::int64_t>(dimension.Extent());

flang/runtime/io-api.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ bool IONAME(SetPos)(Cookie cookie, std::int64_t pos) {
564564
unit->SetPosition(pos - 1, handler);
565565
return true;
566566
}
567-
io.GetIoErrorHandler().Crash("SetPos() on internal unit");
567+
io.GetIoErrorHandler().Crash("SetPos() called on internal unit");
568568
return false;
569569
}
570570

@@ -937,7 +937,7 @@ bool IONAME(GetNewUnit)(Cookie cookie, int &unit, int kind) {
937937
}
938938
std::int64_t result{open->unit().unitNumber()};
939939
if (!SetInteger(unit, kind, result)) {
940-
open->SignalError("GetNewUnit(): Bad INTEGER kind(%d) or out-of-range "
940+
open->SignalError("GetNewUnit(): bad INTEGER kind(%d) or out-of-range "
941941
"value(%jd) for result",
942942
kind, static_cast<std::intmax_t>(result));
943943
}
@@ -1209,7 +1209,8 @@ bool IONAME(InquireInteger64)(
12091209
return true;
12101210
}
12111211
io.GetIoErrorHandler().SignalError(
1212-
"InquireInteger64(): Bad INTEGER kind(%d) or out-of-range value(%jd) "
1212+
"InquireInteger64(): bad INTEGER kind(%d) or out-of-range "
1213+
"value(%jd) "
12131214
"for result",
12141215
kind, static_cast<std::intmax_t>(n));
12151216
}

flang/runtime/io-stmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool IoStatementBase::Inquire(InquiryKeywordHash, std::int64_t &) {
7878
void IoStatementBase::BadInquiryKeywordHashCrash(InquiryKeywordHash inquiry) {
7979
char buffer[16];
8080
const char *decode{InquiryKeywordHashDecode(buffer, sizeof buffer, inquiry)};
81-
Crash("bad InquiryKeywordHash 0x%x (%s)", inquiry,
81+
Crash("Bad InquiryKeywordHash 0x%x (%s)", inquiry,
8282
decode ? decode : "(cannot decode)");
8383
}
8484

flang/runtime/iostat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const char *IostatErrorString(int iostat) {
3030
case IostatInternalWriteOverrun:
3131
return "Internal write overran available records";
3232
case IostatErrorInFormat:
33-
return "Invalid FORMAT";
33+
return "Bad FORMAT";
3434
case IostatErrorInKeyword:
3535
return "Bad keyword argument value";
3636
case IostatEndfileDirect:

flang/runtime/random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void RTNAME(RandomNumber)(
108108
break;
109109
#endif
110110
default:
111-
terminator.Crash("RANDOM_NUMBER(): unsupported REAL kind %d", kind);
111+
terminator.Crash("RANDOM_NUMBER(): bad REAL kind %d", kind);
112112
}
113113
}
114114

flang/runtime/reduction-templates.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ inline void DoTotalReduction(const Descriptor &x, int dim,
4444
const Descriptor *mask, ACCUMULATOR &accumulator, const char *intrinsic,
4545
Terminator &terminator) {
4646
if (dim < 0 || dim > 1) {
47-
terminator.Crash(
48-
"%s: bad DIM=%d for argument with rank %d", intrinsic, dim, x.rank());
47+
terminator.Crash("%s: bad DIM=%d for ARRAY argument with rank %d",
48+
intrinsic, dim, x.rank());
4949
}
5050
SubscriptValue xAt[maxRank];
5151
x.GetLowerBounds(xAt);
@@ -166,7 +166,8 @@ static void CreatePartialReductionResult(Descriptor &result,
166166
TypeCode typeCode) {
167167
int xRank{x.rank()};
168168
if (dim < 1 || dim > xRank) {
169-
terminator.Crash("%s: bad DIM=%d for rank %d", intrinsic, dim, xRank);
169+
terminator.Crash(
170+
"%s: bad DIM=%d for ARRAY with rank %d", intrinsic, dim, xRank);
170171
}
171172
int zeroBasedDim{dim - 1};
172173
SubscriptValue resultExtent[maxRank];
@@ -295,7 +296,7 @@ inline void TypedPartialNumericReduction(Descriptor &result,
295296
intrinsic);
296297
break;
297298
default:
298-
terminator.Crash("%s: invalid type code %d", intrinsic, x.type().raw());
299+
terminator.Crash("%s: bad type code %d", intrinsic, x.type().raw());
299300
}
300301
}
301302

flang/runtime/reduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ inline auto GetTotalLogicalReduction(const Descriptor &x, const char *source,
228228
typename ACCUMULATOR::Type {
229229
Terminator terminator{source, line};
230230
if (dim < 0 || dim > 1) {
231-
terminator.Crash("%s: bad DIM=%d", intrinsic, dim);
231+
terminator.Crash("%s: bad DIM=%d for ARRAY with rank=1", intrinsic, dim);
232232
}
233233
SubscriptValue xAt[maxRank];
234234
x.GetLowerBounds(xAt);

0 commit comments

Comments
 (0)