[flang-commits] [flang] a51d13f - [Flang] Add new CHECK_MSG() function (#86576)

via flang-commits flang-commits at lists.llvm.org
Tue Mar 26 06:47:22 PDT 2024


Author: Carlos Seo
Date: 2024-03-26T10:47:18-03:00
New Revision: a51d13f5db08e36e0b734bc2aa9b5c4fea9cf116

URL: https://github.com/llvm/llvm-project/commit/a51d13f5db08e36e0b734bc2aa9b5c4fea9cf116
DIFF: https://github.com/llvm/llvm-project/commit/a51d13f5db08e36e0b734bc2aa9b5c4fea9cf116.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Common/idioms.h
    flang/lib/Evaluate/constant.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h
index f6c9cbbc0f7cd0..231fbd8601a2a7 100644
--- a/flang/include/flang/Common/idioms.h
+++ b/flang/include/flang/Common/idioms.h
@@ -87,6 +87,8 @@ template <typename... LAMBDAS> visitors(LAMBDAS... x) -> visitors<LAMBDAS...>;
 // 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 a3bdefb76a414c..990339958399ea 100644
--- a/flang/lib/Evaluate/constant.cpp
+++ b/flang/lib/Evaluate/constant.cpp
@@ -160,7 +160,7 @@ template <typename RESULT, typename ELEMENT>
 auto ConstantBase<RESULT, ELEMENT>::Reshape(
     const ConstantSubscripts &dims) const -> std::vector<Element> {
   std::optional<uint64_t> optN{TotalElementCount(dims)};
-  CHECK(optN);
+  CHECK_MSG(optN, "Overflow in TotalElementCount");
   uint64_t n{*optN};
   CHECK(!empty() || n == 0);
   std::vector<Element> elements;


        


More information about the flang-commits mailing list