Removing an "if (!this)" check from two print methods. The condition will
authorRichard Trieu <rtrieu@google.com>
Mon, 9 Jun 2014 22:53:16 +0000 (22:53 +0000)
committerRichard Trieu <rtrieu@google.com>
Mon, 9 Jun 2014 22:53:16 +0000 (22:53 +0000)
never be true in a well-defined context.  The checking for null pointers
has been moved into the caller logic so it does not rely on undefined behavior.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210497 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/IPA/CallGraphSCCPass.cpp
lib/Analysis/IVUsers.cpp
lib/Analysis/LoopPass.cpp
lib/Analysis/RegionPass.cpp
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/IR/AsmWriter.cpp
lib/IR/Core.cpp
lib/Transforms/Instrumentation/DebugIR.cpp

index bfab744d479f857d3ae541b6895c508e221d5645..0d9d0ef842c641d699b7829391d9654de6a91d31 100644 (file)
@@ -602,8 +602,10 @@ namespace {
 
     bool runOnSCC(CallGraphSCC &SCC) override {
       Out << Banner;
-      for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I)
+      for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
+        assert((*I)->getFunction() && "Expecting non-null Function");
         (*I)->getFunction()->print(Out);
+      }
       return false;
     }
   };
index c819bd319c6a10acc77949007344abe47489be04..0b94238e6631b20fef01ed354e6f6f9312205c8b 100644 (file)
@@ -287,6 +287,7 @@ void IVUsers::print(raw_ostream &OS, const Module *M) const {
       OS << ")";
     }
     OS << " in  ";
+    assert(UI->getUser() != nullptr && "Expected non-null User");
     UI->getUser()->print(OS);
     OS << '\n';
   }
index 8df18e75c64e243f619e3a92b0a8cb5c01f6f985..2c6e6e3ffff3b398c4e8e98c4801304c59178ddf 100644 (file)
@@ -45,6 +45,7 @@ public:
     for (Loop::block_iterator b = L->block_begin(), be = L->block_end();
          b != be;
          ++b) {
+      assert((*b) != nullptr && "Expecting non-null block");
       (*b)->print(Out);
     }
     return false;
index 3c7798f2f42b53eef2bdbc31de5461539ed35ed1..d11b3323cac6aae95866aab2b8f60d9dee74ba72 100644 (file)
@@ -195,8 +195,10 @@ public:
 
   bool runOnRegion(Region *R, RGPassManager &RGM) override {
     Out << Banner;
-    for (const auto &BB : R->blocks())
+    for (const auto &BB : R->blocks()) {
+      assert(BB != nullptr && "Expecting non-null Block");
       BB->print(Out);
+    }
 
     return false;
   }
index 9d822d3cb1aa1b632ce7424ec66232cdfb4df5ef..67b57fa2b4c1163f17c7d50b1f0ca34361d43fd7 100644 (file)
@@ -1867,6 +1867,7 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
     SmallString<8> StrVal;
     CFP->getValueAPF().toString(StrVal);
 
+    assert(CFP->getType() != nullptr && "Expecting non-null Type");
     CFP->getType()->print(AP.OutStreamer.GetCommentOS());
     AP.OutStreamer.GetCommentOS() << ' ' << StrVal << '\n';
   }
index fc73a61f9f7f1131da4d779010d194a994b4ef81..7afefdc7ac6f74d322f5e8994db6149810f43987 100644 (file)
@@ -2156,10 +2156,6 @@ void NamedMDNode::print(raw_ostream &ROS) const {
 }
 
 void Type::print(raw_ostream &OS) const {
-  if (!this) {
-    OS << "<null Type>";
-    return;
-  }
   TypePrinting TP;
   TP.print(const_cast<Type*>(this), OS);
 
@@ -2172,10 +2168,6 @@ void Type::print(raw_ostream &OS) const {
 }
 
 void Value::print(raw_ostream &ROS) const {
-  if (!this) {
-    ROS << "printing a <null> value\n";
-    return;
-  }
   formatted_raw_ostream OS(ROS);
   if (const Instruction *I = dyn_cast<Instruction>(this)) {
     const Function *F = I->getParent() ? I->getParent()->getParent() : nullptr;
index aa373f602a15c39851271f59536ade84f8a34b16..f24704c61cd833e6e726060b4fdeda4a7d2de137 100644 (file)
@@ -281,6 +281,7 @@ char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
   std::string buf;
   raw_string_ostream os(buf);
 
+  assert(unwrap(Ty) != nullptr && "Expecting non-null Type");
   unwrap(Ty)->print(os);
   os.flush();
 
@@ -531,6 +532,7 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
   std::string buf;
   raw_string_ostream os(buf);
 
+  assert(unwrap(Val) != nullptr && "Expecting non-null Value");
   unwrap(Val)->print(os);
   os.flush();
 
index 18bda1a3208f47491b1d0de8840f3b34d9b247d2..1bfef574ddb922ba21639a9c1cad4d8e308b1b3b 100644 (file)
@@ -352,6 +352,7 @@ private:
   }
 
   std::string getTypeName(Type *T) {
+    assert(T != nullptr && "Expecting non-null Type");
     std::string TypeName;
     raw_string_ostream TypeStream(TypeName);
     T->print(TypeStream);