Improve error messages on assertion failure.
[oota-llvm.git] / include / llvm / Value.h
index 255105f28801ebdc749bc4cc7e4cb9b07182bd46..aece4ce2439682c5e052d7ba3358a7962d619694 100644 (file)
@@ -110,6 +110,8 @@ public:
   inline use_const_iterator use_begin() const { return Uses.begin(); }
   inline use_iterator       use_end()         { return Uses.end();   }
   inline use_const_iterator use_end()   const { return Uses.end();   }
+  inline User              *use_back()        { return Uses.back();  }
+  inline const User        *use_back()  const { return Uses.back();  }
 
   inline void use_push_back(User *I)   { Uses.push_back(I); }
   User *use_remove(use_iterator &I);
@@ -186,19 +188,24 @@ template <class X> class real_type <class UseTy<X> > { typedef X *Type; };
 //  if (isa<Type>(myVal)) { ... }
 //
 template <class X, class Y>
-inline bool isa(Y Val) { return X::classof(Val); }
+inline bool isa(Y Val) {
+  assert(Val && "isa<Ty>(NULL) invoked!");
+  return X::classof(Val);
+}
 
 
 // cast<X> - Return the argument parameter cast to the specified type.  This
 // casting operator asserts that the type is correct, so it does not return null
-// on failure.  Used Like this:
+// on failure.  But it will correctly return NULL when the input is NULL.
+// Used Like this:
 //
 //  cast<      Instruction>(myVal)->getParent()
 //  cast<const Instruction>(myVal)->getParent()
 //
 template <class X, class Y>
 inline X *cast(Y Val) {
-  assert(isa<X>(Val) && "Invalid cast argument type!");
+  assert((Val == 0 || isa<X>(Val)) &&
+         "cast<Ty>() argument of uncompatible type!");
   return (X*)(real_type<Y>::Type)Val;
 }