[PATCH] D19966: [scan-build] fix warnings emitted on LLVM Transforms code base

Apelete Seketeli via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 06:10:28 PDT 2016


apelete created this revision.
apelete added reviewers: arsenm, tstellarAMD, sunfish, reames, majnemer, nadav, ributzka.
apelete added a subscriber: llvm-commits.
Herald added a subscriber: mzolotukhin.

Fix logic error warnings of the type "called C++ object pointer is
null" emitted by Clang Static Analyzer on the following files:

- lib/Transforms/Scalar/ScalarReplAggregates.cpp,
- lib/Transforms/Scalar/StructurizeCFG.cpp,
- lib/Transforms/Scalar/TailRecursionElimination.cpp,
- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp,
- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp,
- lib/Transforms/Scalar/ConstantHoisting.cpp,
- lib/Transforms/Vectorize/SLPVectorizer.cpp.

Signed-off-by: Apelete Seketeli <apelete at seketeli.net>

http://reviews.llvm.org/D19966

Files:
  lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  lib/Transforms/Scalar/ConstantHoisting.cpp
  lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  lib/Transforms/Scalar/ScalarReplAggregates.cpp
  lib/Transforms/Scalar/StructurizeCFG.cpp
  lib/Transforms/Scalar/TailRecursionElimination.cpp
  lib/Transforms/Vectorize/SLPVectorizer.cpp

Index: lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2818,6 +2818,7 @@
   // instructions into different buckets based on the insert lane.
   SmallVector<Instruction *, 16> Visited;
   for (auto I = CSEWorkList.begin(), E = CSEWorkList.end(); I != E; ++I) {
+    assert((I && *I) && "worklist does not contain any reachable block");
     assert((I == CSEWorkList.begin() || !DT->dominates(*I, *std::prev(I))) &&
            "Worklist not sorted properly!");
     BasicBlock *BB = (*I)->getBlock();
@@ -2919,6 +2920,7 @@
 
   calculateDependencies(Bundle, true, SLP);
 
+  assert(Bundle && "is an empty instruction bundle");
   // Now try to schedule the new bundle. As soon as the bundle is "ready" it
   // means that there are no cyclic dependencies and we can schedule it.
   // Note that's important that we don't "schedule" the bundle yet (see
Index: lib/Transforms/Scalar/TailRecursionElimination.cpp
===================================================================
--- lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -590,6 +590,7 @@
   if (CI->isTailCall() && CannotTailCallElimCallsMarkedTail)
     return nullptr;
 
+  assert(F && "BasicBlock parent did not have an enclosing method");
   // As a special case, detect code like this:
   //   double fabs(double f) { return __builtin_fabs(f); } // a 'fabs' call
   // and disable this xform in this case, because the code generator will
Index: lib/Transforms/Scalar/StructurizeCFG.cpp
===================================================================
--- lib/Transforms/Scalar/StructurizeCFG.cpp
+++ lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -719,6 +719,8 @@
 
 /// \brief Create a new or reuse the previous node as flow node
 BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
+  assert(PrevNode && "cannot reuse null PrevNode as flow node");
+
   BasicBlock *Entry = PrevNode->getEntry();
 
   if (!PrevNode->isSubRegion()) {
Index: lib/Transforms/Scalar/ScalarReplAggregates.cpp
===================================================================
--- lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -1986,6 +1986,7 @@
 /// and recursively continue updating all of its uses.
 void SROA::RewriteBitCast(BitCastInst *BC, AllocaInst *AI, uint64_t Offset,
                           SmallVectorImpl<AllocaInst *> &NewElts) {
+  assert((BC && AI) && "BitCast and Alloca cannot be null" );
   RewriteForScalarRepl(BC, AI, Offset, NewElts);
   if (BC->getOperand(0) != AI)
     return;
Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1007,6 +1007,7 @@
       auto *BaseIE = cast<InsertElementInst>(State.getBase());
       auto *BdvIE = cast<InsertElementInst>(BDV);
       auto UpdateOperand = [&](int OperandIdx) {
+        assert(BaseIE && "base InsertElementInst must not be NULL");
         Value *InVal = BdvIE->getOperand(OperandIdx);
         Value *Base = getBaseForInput(InVal, BaseIE);
         BaseIE->setOperand(OperandIdx, Base);
Index: lib/Transforms/Scalar/ConstantHoisting.cpp
===================================================================
--- lib/Transforms/Scalar/ConstantHoisting.cpp
+++ lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -240,6 +240,7 @@
 Instruction *ConstantHoisting::
 findConstantInsertionPoint(const ConstantInfo &ConstInfo) const {
   assert(!ConstInfo.RebasedConstants.empty() && "Invalid constant info entry.");
+  assert(Entry && "Entry basic block cannot be NULL");
   // Collect all basic blocks.
   SmallPtrSet<BasicBlock *, 8> BBs;
   for (auto const &RCI : ConstInfo.RebasedConstants)
Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1309,6 +1309,8 @@
   if (StoreBB == DestBB || OtherBB == DestBB)
     return false;
 
+  assert(OtherBB && "BasicBlock needs to be not NULL");
+
   // Verify that the other block ends in a branch and is not otherwise empty.
   BasicBlock::iterator BBI(OtherBB->getTerminator());
   BranchInst *OtherBr = dyn_cast<BranchInst>(BBI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19966.56274.patch
Type: text/x-patch
Size: 4562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160505/35fb5cf9/attachment.bin>


More information about the llvm-commits mailing list