Skip to content

Commit

Permalink
Only log the visit of a return instruction if we in fact found a return
Browse files Browse the repository at this point in the history
instruction.

This avoids dereferencing null in the debug logging if the instruction
was not in fact a return instruction. This potential bug was found by
PVS-Studio.

This actually fixes the last of the "dereferenced a pointer before
checking it for null" reports in the recent PVS-Studio run. However,
there are quite a few reports of this nature that I did not do anything
to fix because they are pretty glaring false positives. They usually
took the form of quite clear correlated checks or a check made in
a separate function. I've even added asserts anywhere this correlation
wasn't pretty obvious and fundamental to the code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285988 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
chandlerc committed Nov 4, 2016
1 parent 0e7e3d2 commit 6c10c8c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/Transforms/ObjCARC/ObjCARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,12 +2086,11 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
SmallPtrSet<const BasicBlock *, 4> Visited;
for (BasicBlock &BB: F) {
ReturnInst *Ret = dyn_cast<ReturnInst>(&BB.back());

DEBUG(dbgs() << "Visiting: " << *Ret << "\n");

if (!Ret)
continue;

DEBUG(dbgs() << "Visiting: " << *Ret << "\n");

const Value *Arg = GetRCIdentityRoot(Ret->getOperand(0));

// Look for an ``autorelease'' instruction that is a predecessor of Ret and
Expand Down

0 comments on commit 6c10c8c

Please sign in to comment.