From a23043cb9c1ef021a9cf05cd62cce76cd03c0ba2 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Mon, 9 Jun 2014 22:53:16 +0000 Subject: [PATCH] Removing an "if (!this)" check from two print methods. The condition will 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. llvm-svn: 210497 --- llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp | 4 +++- llvm/lib/Analysis/IVUsers.cpp | 1 + llvm/lib/Analysis/LoopPass.cpp | 1 + llvm/lib/Analysis/RegionPass.cpp | 4 +++- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 1 + llvm/lib/IR/AsmWriter.cpp | 8 -------- llvm/lib/IR/Core.cpp | 2 ++ llvm/lib/Transforms/Instrumentation/DebugIR.cpp | 1 + 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp index bfab744..0d9d0ef 100644 --- a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -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; } }; diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp index c819bd3..0b94238 100644 --- a/llvm/lib/Analysis/IVUsers.cpp +++ b/llvm/lib/Analysis/IVUsers.cpp @@ -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'; } diff --git a/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp index 8df18e7..2c6e6e3 100644 --- a/llvm/lib/Analysis/LoopPass.cpp +++ b/llvm/lib/Analysis/LoopPass.cpp @@ -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; diff --git a/llvm/lib/Analysis/RegionPass.cpp b/llvm/lib/Analysis/RegionPass.cpp index 3c7798f..d11b332 100644 --- a/llvm/lib/Analysis/RegionPass.cpp +++ b/llvm/lib/Analysis/RegionPass.cpp @@ -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; } diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 9d822d3c..67b57fa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -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'; } diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index fc73a61..7afefdc 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -2156,10 +2156,6 @@ void NamedMDNode::print(raw_ostream &ROS) const { } void Type::print(raw_ostream &OS) const { - if (!this) { - OS << ""; - return; - } TypePrinting TP; TP.print(const_cast(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 value\n"; - return; - } formatted_raw_ostream OS(ROS); if (const Instruction *I = dyn_cast(this)) { const Function *F = I->getParent() ? I->getParent()->getParent() : nullptr; diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index aa373f6..f24704c 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -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(); diff --git a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp index 18bda1a..1bfef57 100644 --- a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp +++ b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp @@ -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); -- 2.7.4