diff --git a/flang/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h index f6c9cbbc0f7cd..231fbd8601a2a 100644 --- a/flang/include/flang/Common/idioms.h +++ b/flang/include/flang/Common/idioms.h @@ -87,6 +87,8 @@ template visitors(LAMBDAS... x) -> visitors; // To disable, compile with '-DCHECK=(void)' #ifndef CHECK #define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false)) +// Same as above, but with a custom error message. +#define CHECK_MSG(x, y) ((x) || (DIE("CHECK(" #x ") failed: " #y), false)) #endif // User-defined type traits that default to false: diff --git a/flang/lib/Evaluate/constant.cpp b/flang/lib/Evaluate/constant.cpp index a3bdefb76a414..990339958399e 100644 --- a/flang/lib/Evaluate/constant.cpp +++ b/flang/lib/Evaluate/constant.cpp @@ -160,7 +160,7 @@ template auto ConstantBase::Reshape( const ConstantSubscripts &dims) const -> std::vector { std::optional optN{TotalElementCount(dims)}; - CHECK(optN); + CHECK_MSG(optN, "Overflow in TotalElementCount"); uint64_t n{*optN}; CHECK(!empty() || n == 0); std::vector elements;