assert(0) -> LLVM_UNREACHABLE.
Make llvm_unreachable take an optional string, thus moving the cerr<< out of
line.
LLVM_UNREACHABLE is now a simple wrapper that makes the message go away for
NDEBUG builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75379 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index 3b03c54..29bf0b4 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <cstring>
@@ -1068,7 +1069,7 @@
switch (rounding_mode) {
default:
- assert(0);
+ llvm_unreachable();
case rmNearestTiesToAway:
return lost_fraction == lfExactlyHalf || lost_fraction == lfMoreThanHalf;
@@ -1207,7 +1208,7 @@
{
switch (convolve(category, rhs.category)) {
default:
- assert(0);
+ llvm_unreachable();
case convolve(fcNaN, fcZero):
case convolve(fcNaN, fcNormal):
@@ -1331,7 +1332,7 @@
{
switch (convolve(category, rhs.category)) {
default:
- assert(0);
+ llvm_unreachable();
case convolve(fcNaN, fcZero):
case convolve(fcNaN, fcNormal):
@@ -1373,7 +1374,7 @@
{
switch (convolve(category, rhs.category)) {
default:
- assert(0);
+ llvm_unreachable();
case convolve(fcNaN, fcZero):
case convolve(fcNaN, fcNormal):
@@ -1415,7 +1416,7 @@
{
switch (convolve(category, rhs.category)) {
default:
- assert(0);
+ llvm_unreachable();
case convolve(fcNaN, fcZero):
case convolve(fcNaN, fcNormal):
@@ -1692,7 +1693,7 @@
switch (convolve(category, rhs.category)) {
default:
- assert(0);
+ llvm_unreachable();
case convolve(fcNaN, fcZero):
case convolve(fcNaN, fcNormal):
@@ -2929,7 +2930,7 @@
else if (api.getBitWidth()==128 && !isIEEE)
return initFromPPCDoubleDoubleAPInt(api);
else
- assert(0);
+ llvm_unreachable();
}
APFloat::APFloat(const APInt& api, bool isIEEE)
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index 30dc352..bd5abec 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cmath>
@@ -1386,7 +1387,7 @@
else
return x_old + 1;
} else
- assert(0 && "Error in APInt::sqrt computation");
+ LLVM_UNREACHABLE("Error in APInt::sqrt computation");
return x_old + 1;
}
@@ -2032,7 +2033,7 @@
char cdigit = str[i];
if (radix == 16) {
if (!isxdigit(cdigit))
- assert(0 && "Invalid hex digit in string");
+ LLVM_UNREACHABLE("Invalid hex digit in string");
if (isdigit(cdigit))
digit = cdigit - '0';
else if (cdigit >= 'a')
@@ -2040,7 +2041,7 @@
else if (cdigit >= 'A')
digit = cdigit - 'A' + 10;
else
- assert(0 && "huh? we shouldn't get here");
+ LLVM_UNREACHABLE("huh? we shouldn't get here");
} else if (isdigit(cdigit)) {
digit = cdigit - '0';
assert((radix == 10 ||
@@ -2048,7 +2049,7 @@
(radix == 2 && (digit == 0 || digit == 1))) &&
"Invalid digit in string for given radix");
} else {
- assert(0 && "Invalid character in digit string");
+ LLVM_UNREACHABLE("Invalid character in digit string");
}
// Shift or multiply the value by the radix
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 0fe949c..400241f 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -693,7 +693,7 @@
ValNo++;
break;
default:
- assert(0 && "Internal error, unexpected NumOccurrences flag in "
+ LLVM_UNREACHABLE("Internal error, unexpected NumOccurrences flag in "
"positional argument processing!");
}
}
diff --git a/lib/Support/Dwarf.cpp b/lib/Support/Dwarf.cpp
index fa99035..c2ce680 100644
--- a/lib/Support/Dwarf.cpp
+++ b/lib/Support/Dwarf.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/ErrorHandling.h"
#include <cassert>
@@ -83,7 +84,7 @@
case DW_TAG_lo_user: return "DW_TAG_lo_user";
case DW_TAG_hi_user: return "DW_TAG_hi_user";
}
- assert(0 && "Unknown Dwarf Tag");
+ LLVM_UNREACHABLE("Unknown Dwarf Tag");
return "";
}
@@ -94,7 +95,7 @@
case DW_CHILDREN_no: return "CHILDREN_no";
case DW_CHILDREN_yes: return "CHILDREN_yes";
}
- assert(0 && "Unknown Dwarf ChildrenFlag");
+ LLVM_UNREACHABLE("Unknown Dwarf ChildrenFlag");
return "";
}
@@ -205,7 +206,7 @@
case DW_AT_APPLE_major_runtime_vers: return "DW_AT_APPLE_major_runtime_vers";
case DW_AT_APPLE_runtime_class: return "DW_AT_APPLE_runtime_class";
}
- assert(0 && "Unknown Dwarf Attribute");
+ LLVM_UNREACHABLE("Unknown Dwarf Attribute");
return "";
}
@@ -235,7 +236,7 @@
case DW_FORM_ref_udata: return "FORM_ref_udata";
case DW_FORM_indirect: return "FORM_indirect";
}
- assert(0 && "Unknown Dwarf Form Encoding");
+ LLVM_UNREACHABLE("Unknown Dwarf Form Encoding");
return "";
}
@@ -310,7 +311,7 @@
case DW_OP_lo_user: return "OP_lo_user";
case DW_OP_hi_user: return "OP_hi_user";
}
- assert(0 && "Unknown Dwarf Operation Encoding");
+ LLVM_UNREACHABLE("Unknown Dwarf Operation Encoding");
return "";
}
@@ -336,7 +337,7 @@
case DW_ATE_lo_user: return "ATE_lo_user";
case DW_ATE_hi_user: return "ATE_hi_user";
}
- assert(0 && "Unknown Dwarf Attribute Encoding");
+ LLVM_UNREACHABLE("Unknown Dwarf Attribute Encoding");
return "";
}
@@ -350,7 +351,7 @@
case DW_DS_leading_separate: return "DS_leading_separate";
case DW_DS_trailing_separate: return "DS_trailing_separate";
}
- assert(0 && "Unknown Dwarf Decimal Sign Attribute");
+ LLVM_UNREACHABLE("Unknown Dwarf Decimal Sign Attribute");
return "";
}
@@ -364,7 +365,7 @@
case DW_END_lo_user: return "END_lo_user";
case DW_END_hi_user: return "END_hi_user";
}
- assert(0 && "Unknown Dwarf Endianity");
+ LLVM_UNREACHABLE("Unknown Dwarf Endianity");
return "";
}
@@ -377,7 +378,7 @@
case DW_ACCESS_protected: return "ACCESS_protected";
case DW_ACCESS_private: return "ACCESS_private";
}
- assert(0 && "Unknown Dwarf Accessibility");
+ LLVM_UNREACHABLE("Unknown Dwarf Accessibility");
return "";
}
@@ -389,7 +390,7 @@
case DW_VIS_exported: return "VIS_exported";
case DW_VIS_qualified: return "VIS_qualified";
}
- assert(0 && "Unknown Dwarf Visibility");
+ LLVM_UNREACHABLE("Unknown Dwarf Visibility");
return "";
}
@@ -401,7 +402,7 @@
case DW_VIRTUALITY_virtual: return "VIRTUALITY_virtual";
case DW_VIRTUALITY_pure_virtual: return "VIRTUALITY_pure_virtual";
}
- assert(0 && "Unknown Dwarf Virtuality");
+ LLVM_UNREACHABLE("Unknown Dwarf Virtuality");
return "";
}
@@ -431,7 +432,7 @@
case DW_LANG_lo_user: return "LANG_lo_user";
case DW_LANG_hi_user: return "LANG_hi_user";
}
- assert(0 && "Unknown Dwarf Language");
+ LLVM_UNREACHABLE("Unknown Dwarf Language");
return "";
}
@@ -444,7 +445,7 @@
case DW_ID_down_case: return "ID_down_case";
case DW_ID_case_insensitive: return "ID_case_insensitive";
}
- assert(0 && "Unknown Dwarf Identifier Case");
+ LLVM_UNREACHABLE("Unknown Dwarf Identifier Case");
return "";
}
@@ -458,7 +459,7 @@
case DW_CC_lo_user: return "CC_lo_user";
case DW_CC_hi_user: return "CC_hi_user";
}
- assert(0 && "Unknown Dwarf Calling Convention");
+ LLVM_UNREACHABLE("Unknown Dwarf Calling Convention");
return "";
}
@@ -471,7 +472,7 @@
case DW_INL_declared_not_inlined: return "INL_declared_not_inlined";
case DW_INL_declared_inlined: return "INL_declared_inlined";
}
- assert(0 && "Unknown Dwarf Inline Code");
+ LLVM_UNREACHABLE("Unknown Dwarf Inline Code");
return "";
}
@@ -482,7 +483,7 @@
case DW_ORD_row_major: return "ORD_row_major";
case DW_ORD_col_major: return "ORD_col_major";
}
- assert(0 && "Unknown Dwarf Array Order");
+ LLVM_UNREACHABLE("Unknown Dwarf Array Order");
return "";
}
@@ -493,7 +494,7 @@
case DW_DSC_label: return "DSC_label";
case DW_DSC_range: return "DSC_range";
}
- assert(0 && "Unknown Dwarf Discriminant Descriptor");
+ LLVM_UNREACHABLE("Unknown Dwarf Discriminant Descriptor");
return "";
}
@@ -514,7 +515,7 @@
case DW_LNS_set_epilogue_begin: return "LNS_set_epilogue_begin";
case DW_LNS_set_isa: return "LNS_set_isa";
}
- assert(0 && "Unknown Dwarf Line Number Standard");
+ LLVM_UNREACHABLE("Unknown Dwarf Line Number Standard");
return "";
}
@@ -529,7 +530,7 @@
case DW_LNE_lo_user: return "LNE_lo_user";
case DW_LNE_hi_user: return "LNE_hi_user";
}
- assert(0 && "Unknown Dwarf Line Number Extended Opcode Encoding");
+ LLVM_UNREACHABLE("Unknown Dwarf Line Number Extended Opcode Encoding");
return "";
}
@@ -544,7 +545,7 @@
case DW_MACINFO_end_file: return "MACINFO_end_file";
case DW_MACINFO_vendor_ext: return "MACINFO_vendor_ext";
}
- assert(0 && "Unknown Dwarf Macinfo Type Encodings");
+ LLVM_UNREACHABLE("Unknown Dwarf Macinfo Type Encodings");
return "";
}
@@ -580,7 +581,7 @@
case DW_CFA_lo_user: return "CFA_lo_user";
case DW_CFA_hi_user: return "CFA_hi_user";
}
- assert(0 && "Unknown Dwarf Call Frame Instruction Encodings");
+ LLVM_UNREACHABLE("Unknown Dwarf Call Frame Instruction Encodings");
return "";
}
diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp
index 2a5d906..f2e247c 100644
--- a/lib/Support/ErrorHandling.cpp
+++ b/lib/Support/ErrorHandling.cpp
@@ -44,7 +44,9 @@
exit(1);
}
-void llvm_unreachable(void) {
+void llvm_unreachable(const char *msg) {
+ if (msg)
+ errs() << msg << "\n";
abort();
}
}
diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp
index 41c730e..0f61067 100644
--- a/lib/Support/FoldingSet.cpp
+++ b/lib/Support/FoldingSet.cpp
@@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <cstring>
@@ -50,7 +51,7 @@
else if (sizeof(long) == sizeof(long long)) {
AddInteger((unsigned long long)I);
} else {
- assert(0 && "unexpected sizeof(long)");
+ LLVM_UNREACHABLE("unexpected sizeof(long)");
}
}
void FoldingSetNodeID::AddInteger(long long I) {