forked from OSchip/llvm-project
[analyzer] Rename addTrackNullOrUndefValueVisitor to trackNullOrUndefValue.
This helper function (in the clang::ento::bugreporter namespace) may add more than one visitor, but conceptually it's tracking a single use of a null or undefined value and should do so as best it can. Also, the BugReport parameter has been made a reference to underscore that it is non-optional. llvm-svn: 162720
This commit is contained in:
parent
72c5515bab
commit
a0f7d35afe
|
@ -225,8 +225,7 @@ public:
|
|||
|
||||
namespace bugreporter {
|
||||
|
||||
void addTrackNullOrUndefValueVisitor(const ExplodedNode *N, const Stmt *S,
|
||||
BugReport *R);
|
||||
void trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, BugReport &R);
|
||||
|
||||
const Stmt *GetDerefExpr(const ExplodedNode *N);
|
||||
const Stmt *GetDenomExpr(const ExplodedNode *N);
|
||||
|
|
|
@ -105,7 +105,7 @@ void AttrNonNullChecker::checkPreCall(const CallEvent &Call,
|
|||
// Highlight the range of the argument that was null.
|
||||
R->addRange(Call.getArgSourceRange(idx));
|
||||
if (const Expr *ArgE = Call.getArgExpr(idx))
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(errorNode, ArgE, R);
|
||||
bugreporter::trackNullOrUndefValue(errorNode, ArgE, *R);
|
||||
// Emit the bug report.
|
||||
C.EmitReport(R);
|
||||
}
|
||||
|
|
|
@ -432,7 +432,7 @@ void CFRetainReleaseChecker::checkPreStmt(const CallExpr *CE,
|
|||
|
||||
BugReport *report = new BugReport(*BT, description, N);
|
||||
report->addRange(Arg->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Arg, report);
|
||||
bugreporter::trackNullOrUndefValue(N, Arg, *report);
|
||||
C.EmitReport(report);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C,
|
|||
BugReport *report = new BugReport(*BT, os.str(), N);
|
||||
|
||||
report->addRange(S->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, S, report);
|
||||
bugreporter::trackNullOrUndefValue(N, S, *report);
|
||||
C.EmitReport(report);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ void CallAndMessageChecker::emitBadCall(BugType *BT, CheckerContext &C,
|
|||
BugReport *R = new BugReport(*BT, BT->getName(), N);
|
||||
if (BadE) {
|
||||
R->addRange(BadE->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, BadE, R);
|
||||
bugreporter::trackNullOrUndefValue(N, BadE, *R);
|
||||
}
|
||||
C.EmitReport(R);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C,
|
|||
BugReport *R = new BugReport(*BT, Desc, N);
|
||||
R->addRange(argRange);
|
||||
if (argEx)
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, argEx, R);
|
||||
bugreporter::trackNullOrUndefValue(N, argEx, *R);
|
||||
C.EmitReport(R);
|
||||
}
|
||||
return true;
|
||||
|
@ -335,7 +335,7 @@ void CallAndMessageChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
|
|||
|
||||
// FIXME: getTrackNullOrUndefValueVisitor can't handle "super" yet.
|
||||
if (const Expr *ReceiverE = ME->getInstanceReceiver())
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, ReceiverE, R);
|
||||
bugreporter::trackNullOrUndefValue(N, ReceiverE, *R);
|
||||
C.EmitReport(R);
|
||||
}
|
||||
return;
|
||||
|
@ -377,7 +377,7 @@ void CallAndMessageChecker::emitNilReceiverBug(CheckerContext &C,
|
|||
report->addRange(ME->getReceiverRange());
|
||||
// FIXME: This won't track "self" in messages to super.
|
||||
if (const Expr *receiver = ME->getInstanceReceiver()) {
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, receiver, report);
|
||||
bugreporter::trackNullOrUndefValue(N, receiver, *report);
|
||||
}
|
||||
C.EmitReport(report);
|
||||
}
|
||||
|
|
|
@ -166,8 +166,7 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S,
|
|||
buf.empty() ? BT_null->getDescription() : buf.str(),
|
||||
N);
|
||||
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, bugreporter::GetDerefExpr(N),
|
||||
report);
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N), *report);
|
||||
|
||||
for (SmallVectorImpl<SourceRange>::iterator
|
||||
I = Ranges.begin(), E = Ranges.end(); I!=E; ++I)
|
||||
|
@ -191,9 +190,8 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S,
|
|||
|
||||
BugReport *report =
|
||||
new BugReport(*BT_undef, BT_undef->getDescription(), N);
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N,
|
||||
bugreporter::GetDerefExpr(N),
|
||||
report);
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N),
|
||||
*report);
|
||||
report->disablePathPruning();
|
||||
C.EmitReport(report);
|
||||
}
|
||||
|
|
|
@ -39,12 +39,8 @@ void DivZeroChecker::reportBug(const char *Msg,
|
|||
if (!BT)
|
||||
BT.reset(new BuiltinBug("Division by zero"));
|
||||
|
||||
BugReport *R =
|
||||
new BugReport(*BT, Msg, N);
|
||||
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N,
|
||||
bugreporter::GetDenomExpr(N),
|
||||
R);
|
||||
BugReport *R = new BugReport(*BT, Msg, N);
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::GetDenomExpr(N), *R);
|
||||
C.EmitReport(R);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ void ObjCAtSyncChecker::checkPreStmt(const ObjCAtSynchronizedStmt *S,
|
|||
"for @synchronized"));
|
||||
BugReport *report =
|
||||
new BugReport(*BT_undef, BT_undef->getDescription(), N);
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Ex, report);
|
||||
bugreporter::trackNullOrUndefValue(N, Ex, *report);
|
||||
C.EmitReport(report);
|
||||
}
|
||||
return;
|
||||
|
@ -72,7 +72,7 @@ void ObjCAtSyncChecker::checkPreStmt(const ObjCAtSynchronizedStmt *S,
|
|||
"(no synchronization will occur)"));
|
||||
BugReport *report =
|
||||
new BugReport(*BT_null, BT_null->getDescription(), N);
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Ex, report);
|
||||
bugreporter::trackNullOrUndefValue(N, Ex, *report);
|
||||
|
||||
C.EmitReport(report);
|
||||
return;
|
||||
|
|
|
@ -55,7 +55,7 @@ void ReturnUndefChecker::checkPreStmt(const ReturnStmt *RS,
|
|||
|
||||
report->disablePathPruning();
|
||||
report->addRange(RetE->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, RetE, report);
|
||||
bugreporter::trackNullOrUndefValue(N, RetE, *report);
|
||||
|
||||
C.EmitReport(report);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ void UndefBranchChecker::checkBranchCondition(const Stmt *Condition,
|
|||
|
||||
// Emit the bug report.
|
||||
BugReport *R = new BugReport(*BT, BT->getDescription(), N);
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Ex, R);
|
||||
bugreporter::trackNullOrUndefValue(N, Ex, *R);
|
||||
R->addRange(Ex->getSourceRange());
|
||||
R->disablePathPruning();
|
||||
|
||||
|
|
|
@ -76,10 +76,10 @@ void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
|
|||
BugReport *report = new BugReport(*BT, OS.str(), N);
|
||||
if (Ex) {
|
||||
report->addRange(Ex->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Ex, report);
|
||||
bugreporter::trackNullOrUndefValue(N, Ex, *report);
|
||||
}
|
||||
else
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, B, report);
|
||||
bugreporter::trackNullOrUndefValue(N, B, *report);
|
||||
|
||||
report->disablePathPruning();
|
||||
C.EmitReport(report);
|
||||
|
|
|
@ -42,7 +42,7 @@ UndefinedArraySubscriptChecker::checkPreStmt(const ArraySubscriptExpr *A,
|
|||
// Generate a report for this bug.
|
||||
BugReport *R = new BugReport(*BT, BT->getName(), N);
|
||||
R->addRange(A->getIdx()->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, A->getIdx(), R);
|
||||
bugreporter::trackNullOrUndefValue(N, A->getIdx(), *R);
|
||||
C.EmitReport(R);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
|
|||
BugReport *R = new BugReport(*BT, str, N);
|
||||
if (ex) {
|
||||
R->addRange(ex->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, ex, R);
|
||||
bugreporter::trackNullOrUndefValue(N, ex, *R);
|
||||
}
|
||||
R->disablePathPruning();
|
||||
C.EmitReport(R);
|
||||
|
|
|
@ -224,7 +224,7 @@ bool UnixAPIChecker::ReportZeroByteAllocation(CheckerContext &C,
|
|||
BugReport *report = new BugReport(*BT_mallocZero, os.str(), N);
|
||||
|
||||
report->addRange(arg->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, arg, report);
|
||||
bugreporter::trackNullOrUndefValue(N, arg, *report);
|
||||
C.EmitReport(report);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -69,7 +69,7 @@ void VLASizeChecker::reportBug(VLASize_Kind Kind,
|
|||
|
||||
BugReport *report = new BugReport(*BT, os.str(), N);
|
||||
report->addRange(SizeE->getSourceRange());
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, SizeE, report);
|
||||
bugreporter::trackNullOrUndefValue(N, SizeE, *report);
|
||||
C.EmitReport(report);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ public:
|
|||
llvm::tie(StNonZero, StZero) = State->assume(cast<DefinedSVal>(V));
|
||||
if (StZero && !StNonZero) {
|
||||
// If we're returning 0, we should track where that 0 came from.
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, RetE, &BR);
|
||||
bugreporter::trackNullOrUndefValue(N, RetE, BR);
|
||||
|
||||
if (isa<Loc>(V)) {
|
||||
if (RetE->getType()->isObjCObjectPointerType())
|
||||
|
@ -435,9 +435,8 @@ TrackConstraintBRVisitor::VisitNode(const ExplodedNode *N,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void bugreporter::addTrackNullOrUndefValueVisitor(const ExplodedNode *N,
|
||||
const Stmt *S,
|
||||
BugReport *report) {
|
||||
void bugreporter::trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S,
|
||||
BugReport &report) {
|
||||
if (!S || !N)
|
||||
return;
|
||||
|
||||
|
@ -477,17 +476,17 @@ void bugreporter::addTrackNullOrUndefValueVisitor(const ExplodedNode *N,
|
|||
|
||||
// Mark both the variable region and its contents as interesting.
|
||||
SVal V = state->getRawSVal(loc::MemRegionVal(R));
|
||||
report->markInteresting(R);
|
||||
report->markInteresting(V);
|
||||
report.markInteresting(R);
|
||||
report.markInteresting(V);
|
||||
|
||||
// If the contents are symbolic, find out when they became null.
|
||||
if (V.getAsLocSymbol()) {
|
||||
BugReporterVisitor *ConstraintTracker
|
||||
= new TrackConstraintBRVisitor(cast<loc::MemRegionVal>(V), false);
|
||||
report->addVisitor(ConstraintTracker);
|
||||
report.addVisitor(ConstraintTracker);
|
||||
}
|
||||
|
||||
report->addVisitor(new FindLastStoreBRVisitor(V, R));
|
||||
report.addVisitor(new FindLastStoreBRVisitor(V, R));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -505,14 +504,14 @@ void bugreporter::addTrackNullOrUndefValueVisitor(const ExplodedNode *N,
|
|||
if (loc::MemRegionVal *L = dyn_cast<loc::MemRegionVal>(&V)) {
|
||||
const MemRegion *Base = L->getRegion()->getBaseRegion();
|
||||
if (isa<SymbolicRegion>(Base)) {
|
||||
report->markInteresting(Base);
|
||||
report->addVisitor(new TrackConstraintBRVisitor(loc::MemRegionVal(Base),
|
||||
report.markInteresting(Base);
|
||||
report.addVisitor(new TrackConstraintBRVisitor(loc::MemRegionVal(Base),
|
||||
false));
|
||||
}
|
||||
} else {
|
||||
// Otherwise, if the value came from an inlined function call,
|
||||
// we should at least make sure that function isn't pruned in our output.
|
||||
ReturnVisitor::addVisitorIfNecessary(N, S, *report);
|
||||
ReturnVisitor::addVisitorIfNecessary(N, S, report);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -555,7 +554,7 @@ PathDiagnosticPiece *NilReceiverBRVisitor::VisitNode(const ExplodedNode *N,
|
|||
// The receiver was nil, and hence the method was skipped.
|
||||
// Register a BugReporterVisitor to issue a message telling us how
|
||||
// the receiver was null.
|
||||
bugreporter::addTrackNullOrUndefValueVisitor(N, Receiver, &BR);
|
||||
bugreporter::trackNullOrUndefValue(N, Receiver, BR);
|
||||
// Issue a message saying that the method was skipped.
|
||||
PathDiagnosticLocation L(Receiver, BRC.getSourceManager(),
|
||||
N->getLocationContext());
|
||||
|
|
Loading…
Reference in New Issue