From 675d56222b6b98d2c22a17aaf69a036e57d5426a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= <edwintorok@gmail.com>
Date: Sat, 11 Jul 2009 20:10:48 +0000
Subject: 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
---
 lib/Analysis/AliasAnalysisCounter.cpp   |  5 +++--
 lib/Analysis/AliasSetTracker.cpp        |  3 ++-
 lib/Analysis/BasicAliasAnalysis.cpp     |  3 ++-
 lib/Analysis/ConstantFolding.cpp        |  7 ++++---
 lib/Analysis/IPA/Andersens.cpp          | 12 ++++++------
 lib/Analysis/LoopDependenceAnalysis.cpp |  3 ++-
 lib/Analysis/ScalarEvolution.cpp        | 21 +++++++++++----------
 7 files changed, 30 insertions(+), 24 deletions(-)

(limited to 'lib/Analysis')

diff --git a/lib/Analysis/AliasAnalysisCounter.cpp b/lib/Analysis/AliasAnalysisCounter.cpp
index 4362d7d..2ed11ac 100644
--- a/lib/Analysis/AliasAnalysisCounter.cpp
+++ b/lib/Analysis/AliasAnalysisCounter.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Streams.h"
 using namespace llvm;
 
@@ -131,7 +132,7 @@ AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
 
   const char *AliasString;
   switch (R) {
-  default: assert(0 && "Unknown alias type!");
+  default: LLVM_UNREACHABLE("Unknown alias type!");
   case NoAlias:   No++;   AliasString = "No alias"; break;
   case MayAlias:  May++;  AliasString = "May alias"; break;
   case MustAlias: Must++; AliasString = "Must alias"; break;
@@ -156,7 +157,7 @@ AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
 
   const char *MRString;
   switch (R) {
-  default:       assert(0 && "Unknown mod/ref type!");
+  default:       LLVM_UNREACHABLE("Unknown mod/ref type!");
   case NoModRef: NoMR++;     MRString = "NoModRef"; break;
   case Ref:      JustRef++;  MRString = "JustRef"; break;
   case Mod:      JustMod++;  MRString = "JustMod"; break;
diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp
index 18c2b66..7ba98dd 100644
--- a/lib/Analysis/AliasSetTracker.cpp
+++ b/lib/Analysis/AliasSetTracker.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Target/TargetData.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/Streams.h"
 using namespace llvm;
@@ -539,7 +540,7 @@ void AliasSet::print(std::ostream &OS) const {
   case Refs    : OS << "Ref       "; break;
   case Mods    : OS << "Mod       "; break;
   case ModRef  : OS << "Mod/Ref   "; break;
-  default: assert(0 && "Bad value for AccessTy!");
+  default: LLVM_UNREACHABLE("Bad value for AccessTy!");
   }
   if (isVolatile()) OS << "[volatile] ";
   if (Forward)
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index c474fe7..daa3c9a 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include <algorithm>
 using namespace llvm;
@@ -157,7 +158,7 @@ namespace {
 
     virtual void getArgumentAccesses(Function *F, CallSite CS,
                                      std::vector<PointerAccessInfo> &Info) {
-      assert(0 && "This method may not be called on this function!");
+      LLVM_UNREACHABLE("This method may not be called on this function!");
     }
 
     virtual void getMustAliases(Value *P, std::vector<Value*> &RetVals) { }
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index ffdc52c..7e6b877 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/MathExtras.h"
 #include <cerrno>
@@ -365,7 +366,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
     return 0;
   case Instruction::ICmp:
   case Instruction::FCmp:
-    assert(0 &&"This function is invalid for compares: no predicate specified");
+    LLVM_UNREACHABLE("This function is invalid for compares: no predicate specified");
   case Instruction::PtrToInt:
     // If the input is a inttoptr, eliminate the pair.  This requires knowing
     // the width of a pointer, so it can't be done in ConstantExpr::getCast.
@@ -690,7 +691,7 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
     return Context->getConstantFP(APFloat((float)V));
   if (Ty == Type::DoubleTy)
     return Context->getConstantFP(APFloat(V));
-  assert(0 && "Can only constant fold float/double");
+  LLVM_UNREACHABLE("Can only constant fold float/double");
   return 0; // dummy return to suppress warning
 }
 
@@ -709,7 +710,7 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
     return Context->getConstantFP(APFloat((float)V));
   if (Ty == Type::DoubleTy)
     return Context->getConstantFP(APFloat(V));
-  assert(0 && "Can only constant fold float/double");
+  LLVM_UNREACHABLE("Can only constant fold float/double");
   return 0; // dummy return to suppress warning
 }
 
diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp
index f453a6f..3f1dcb7 100644
--- a/lib/Analysis/IPA/Andersens.cpp
+++ b/lib/Analysis/IPA/Andersens.cpp
@@ -508,7 +508,7 @@ namespace {
 #ifndef NDEBUG
         V->dump();
 #endif
-        assert(0 && "Value does not have a node in the points-to graph!");
+        LLVM_UNREACHABLE("Value does not have a node in the points-to graph!");
       }
       return I->second;
     }
@@ -827,10 +827,10 @@ unsigned Andersens::getNodeForConstantPointer(Constant *C) {
       return getNodeForConstantPointer(CE->getOperand(0));
     default:
       cerr << "Constant Expr not yet handled: " << *CE << "\n";
-      assert(0);
+      llvm_unreachable();
     }
   } else {
-    assert(0 && "Unknown constant pointer!");
+    LLVM_UNREACHABLE("Unknown constant pointer!");
   }
   return 0;
 }
@@ -854,10 +854,10 @@ unsigned Andersens::getNodeForConstantPointerTarget(Constant *C) {
       return getNodeForConstantPointerTarget(CE->getOperand(0));
     default:
       cerr << "Constant Expr not yet handled: " << *CE << "\n";
-      assert(0);
+      llvm_unreachable();
     }
   } else {
-    assert(0 && "Unknown constant pointer!");
+    LLVM_UNREACHABLE("Unknown constant pointer!");
   }
   return 0;
 }
@@ -1244,7 +1244,7 @@ void Andersens::visitSelectInst(SelectInst &SI) {
 }
 
 void Andersens::visitVAArg(VAArgInst &I) {
-  assert(0 && "vaarg not handled yet!");
+  LLVM_UNREACHABLE("vaarg not handled yet!");
 }
 
 /// AddConstraintsForCall - Add constraints for a call with actual arguments
diff --git a/lib/Analysis/LoopDependenceAnalysis.cpp b/lib/Analysis/LoopDependenceAnalysis.cpp
index f605783..79f92a6 100644
--- a/lib/Analysis/LoopDependenceAnalysis.cpp
+++ b/lib/Analysis/LoopDependenceAnalysis.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Instructions.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Target/TargetData.h"
 using namespace llvm;
 
@@ -63,7 +64,7 @@ static Value *GetPointerOperand(Value *I) {
     return i->getPointerOperand();
   if (StoreInst *i = dyn_cast<StoreInst>(I))
     return i->getPointerOperand();
-  assert(0 && "Value is no load or store instruction!");
+  LLVM_UNREACHABLE("Value is no load or store instruction!");
   // Never reached.
   return 0;
 }
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index a9528cf..86a7613 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -75,6 +75,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ConstantRange.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/MathExtras.h"
@@ -147,21 +148,21 @@ SCEVCouldNotCompute::SCEVCouldNotCompute() :
   SCEV(scCouldNotCompute) {}
 
 void SCEVCouldNotCompute::Profile(FoldingSetNodeID &ID) const {
-  assert(0 && "Attempt to use a SCEVCouldNotCompute object!");
+  LLVM_UNREACHABLE("Attempt to use a SCEVCouldNotCompute object!");
 }
 
 bool SCEVCouldNotCompute::isLoopInvariant(const Loop *L) const {
-  assert(0 && "Attempt to use a SCEVCouldNotCompute object!");
+  LLVM_UNREACHABLE("Attempt to use a SCEVCouldNotCompute object!");
   return false;
 }
 
 const Type *SCEVCouldNotCompute::getType() const {
-  assert(0 && "Attempt to use a SCEVCouldNotCompute object!");
+  LLVM_UNREACHABLE("Attempt to use a SCEVCouldNotCompute object!");
   return 0;
 }
 
 bool SCEVCouldNotCompute::hasComputableLoopEvolution(const Loop *L) const {
-  assert(0 && "Attempt to use a SCEVCouldNotCompute object!");
+  LLVM_UNREACHABLE("Attempt to use a SCEVCouldNotCompute object!");
   return false;
 }
 
@@ -296,7 +297,7 @@ SCEVCommutativeExpr::replaceSymbolicValuesWithConcrete(
       else if (isa<SCEVUMaxExpr>(this))
         return SE.getUMaxExpr(NewOps);
       else
-        assert(0 && "Unknown commutative expr!");
+        LLVM_UNREACHABLE("Unknown commutative expr!");
     }
   }
   return this;
@@ -543,7 +544,7 @@ namespace {
         return operator()(LC->getOperand(), RC->getOperand());
       }
 
-      assert(0 && "Unknown SCEV kind!");
+      LLVM_UNREACHABLE("Unknown SCEV kind!");
       return false;
     }
   };
@@ -3488,7 +3489,7 @@ GetAddressedElementFromGlobal(GlobalVariable *GV,
         if (Idx >= ATy->getNumElements()) return 0;  // Bogus program
         Init = Constant::getNullValue(ATy->getElementType());
       } else {
-        assert(0 && "Unknown constant aggregate type!");
+        LLVM_UNREACHABLE("Unknown constant aggregate type!");
       }
       return 0;
     } else {
@@ -3898,7 +3899,7 @@ const SCEV *ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) {
           return getSMaxExpr(NewOps);
         if (isa<SCEVUMaxExpr>(Comm))
           return getUMaxExpr(NewOps);
-        assert(0 && "Unknown commutative SCEV type!");
+        LLVM_UNREACHABLE("Unknown commutative SCEV type!");
       }
     }
     // If we got here, all operands are loop invariant.
@@ -3949,7 +3950,7 @@ const SCEV *ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) {
     return getTruncateExpr(Op, Cast->getType());
   }
 
-  assert(0 && "Unknown SCEV type!");
+  LLVM_UNREACHABLE("Unknown SCEV type!");
   return 0;
 }
 
@@ -4260,7 +4261,7 @@ bool ScalarEvolution::isKnownPredicate(ICmpInst::Predicate Pred,
 
   switch (Pred) {
   default:
-    assert(0 && "Unexpected ICmpInst::Predicate value!");
+    LLVM_UNREACHABLE("Unexpected ICmpInst::Predicate value!");
     break;
   case ICmpInst::ICMP_SGT:
     Pred = ICmpInst::ICMP_SLT;
-- 
cgit v1.1