summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2013-05-13 23:49:51 +0000
committerAnna Zaks <ganna@apple.com>2013-05-13 23:49:51 +0000
commit6afa8f1609f05b3e482503d3bd21e894202f911c (patch)
tree289b1c5506e37cf63cd83acb1c2407d2f86697b6 /clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
parenta76143eeee8dc578e2640064d2121db4b34c999d (diff)
downloadbcm5719-llvm-6afa8f1609f05b3e482503d3bd21e894202f911c.tar.gz
bcm5719-llvm-6afa8f1609f05b3e482503d3bd21e894202f911c.zip
[analyzer] Refactor: address Jordan’s code review of r181738.
(Modifying the checker to record that the values are no longer nil will be done separately.) llvm-svn: 181744
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index c723e4f29b0..ba779ff191c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -105,7 +105,7 @@ namespace {
bool CanBeSubscript = false) const;
void generateBugReport(ExplodedNode *N,
- llvm::raw_svector_ostream &os,
+ StringRef Msg,
SourceRange Range,
const Expr *Expr,
CheckerContext &C) const;
@@ -123,14 +123,10 @@ void NilArgChecker::warnIfNilExpr(const Expr *E,
const char *Msg,
CheckerContext &C) const {
ProgramStateRef State = C.getState();
- SVal SV = State->getSVal(E, C.getLocationContext());
- if (State->isNull(SV).isConstrainedTrue()) {
+ if (State->isNull(C.getSVal(E)).isConstrainedTrue()) {
if (ExplodedNode *N = C.generateSink()) {
- SmallString<128> sbuf;
- llvm::raw_svector_ostream os(sbuf);
- os << Msg;
- generateBugReport(N, os, E->getSourceRange(), E, C);
+ generateBugReport(N, Msg, E->getSourceRange(), E, C);
}
}
@@ -180,22 +176,22 @@ void NilArgChecker::warnIfNilArg(CheckerContext &C,
}
}
- generateBugReport(N, os, msg.getArgSourceRange(Arg),
+ generateBugReport(N, os.str(), msg.getArgSourceRange(Arg),
msg.getArgExpr(Arg), C);
}
}
void NilArgChecker::generateBugReport(ExplodedNode *N,
- llvm::raw_svector_ostream &os,
+ StringRef Msg,
SourceRange Range,
- const Expr *Expr,
+ const Expr *E,
CheckerContext &C) const {
if (!BT)
BT.reset(new APIMisuse("nil argument"));
- BugReport *R = new BugReport(*BT, os.str(), N);
+ BugReport *R = new BugReport(*BT, Msg, N);
R->addRange(Range);
- bugreporter::trackNullOrUndefValue(N, Expr, *R);
+ bugreporter::trackNullOrUndefValue(N, E, *R);
C.emitReport(R);
}
@@ -290,14 +286,16 @@ void NilArgChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
void NilArgChecker::checkPostStmt(const ObjCArrayLiteral *AL,
CheckerContext &C) const {
- for (unsigned i = 0; i < AL->getNumElements(); ++i) {
+ unsigned NumOfElements = AL->getNumElements();
+ for (unsigned i = 0; i < NumOfElements; ++i) {
warnIfNilExpr(AL->getElement(i), "Array element cannot be nil", C);
}
}
void NilArgChecker::checkPostStmt(const ObjCDictionaryLiteral *DL,
CheckerContext &C) const {
- for (unsigned i = 0; i < DL->getNumElements(); ++i) {
+ unsigned NumOfElements = DL->getNumElements();
+ for (unsigned i = 0; i < NumOfElements; ++i) {
ObjCDictionaryElement Element = DL->getKeyValueElement(i);
warnIfNilExpr(Element.Key, "Dictionary key cannot be nil", C);
warnIfNilExpr(Element.Value, "Dictionary value cannot be nil", C);
OpenPOWER on IntegriCloud