Skip to content

Commit a51d13f

Browse files
authored
[Flang] Add new CHECK_MSG() function (#86576)
Added a new variant of the CHECK() function that takes a custom message as a parameter. This is useful for more meaninful error messages when the compiler is expected to crash. Fixes #78931
1 parent 47f4a07 commit a51d13f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

flang/include/flang/Common/idioms.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ template <typename... LAMBDAS> visitors(LAMBDAS... x) -> visitors<LAMBDAS...>;
8787
// To disable, compile with '-DCHECK=(void)'
8888
#ifndef CHECK
8989
#define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false))
90+
// Same as above, but with a custom error message.
91+
#define CHECK_MSG(x, y) ((x) || (DIE("CHECK(" #x ") failed: " #y), false))
9092
#endif
9193

9294
// User-defined type traits that default to false:

flang/lib/Evaluate/constant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ template <typename RESULT, typename ELEMENT>
160160
auto ConstantBase<RESULT, ELEMENT>::Reshape(
161161
const ConstantSubscripts &dims) const -> std::vector<Element> {
162162
std::optional<uint64_t> optN{TotalElementCount(dims)};
163-
CHECK(optN);
163+
CHECK_MSG(optN, "Overflow in TotalElementCount");
164164
uint64_t n{*optN};
165165
CHECK(!empty() || n == 0);
166166
std::vector<Element> elements;

0 commit comments

Comments
 (0)