summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-03-27 21:23:57 +0000
committerTed Kremenek <kremenek@apple.com>2008-03-27 21:23:57 +0000
commit2e4e7ccb229a605151ffbbf24bc82dc470eb2a96 (patch)
treebf5863a3fc08e4ceb9aba5bf10ae1f90a46942b4 /clang/lib
parent27156c8c9f791741a5ee3a76d0aac94e3be55f54 (diff)
downloadbcm5719-llvm-2e4e7ccb229a605151ffbbf24bc82dc470eb2a96.tar.gz
bcm5719-llvm-2e4e7ccb229a605151ffbbf24bc82dc470eb2a96.zip
Add line SourceLocation to NSString checks.
Added test case to test warning about passing 'nil' to NSString's compare: method. llvm-svn: 48896
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/BasicObjCFoundationChecks.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/clang/lib/Analysis/BasicObjCFoundationChecks.cpp b/clang/lib/Analysis/BasicObjCFoundationChecks.cpp
index d2a2dd6a51b..d158067e56d 100644
--- a/clang/lib/Analysis/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/Analysis/BasicObjCFoundationChecks.cpp
@@ -43,7 +43,7 @@ class VISIBILITY_HIDDEN BasicObjCFoundationChecks : public GRSimpleAPICheck {
bool isNSString(ObjCInterfaceType* T, const char* suffix);
bool AuditNSString(NodeTy* N, ObjCMessageExpr* ME);
- void RegisterError(NodeTy* N, Expr* E, const char *msg);
+ void Warn(NodeTy* N, Expr* E, const char *msg);
public:
BasicObjCFoundationChecks(ASTContext& ctx, ValueStateManager* vmgr)
@@ -112,7 +112,7 @@ static inline bool isNil(RVal X) {
//===----------------------------------------------------------------------===//
-void BasicObjCFoundationChecks::RegisterError(NodeTy* N,
+void BasicObjCFoundationChecks::Warn(NodeTy* N,
Expr* E, const char *msg) {
Errors.push_back(AnnotatedPath<ValueState>());
@@ -135,7 +135,7 @@ void BasicObjCFoundationChecks::ReportResults(Diagnostic& D) {
SourceRange R = AN.getExpr()->getSourceRange();
- D.Report(diag, &AN.getString(), 1, &R, 1);
+ D.Report(L, diag, &AN.getString(), 1, &R, 1);
}
}
@@ -161,16 +161,30 @@ bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N,
// lexical comparisons.
std::string name = S.getName();
+ assert (!name.empty());
+ const char* cstr = &name[0];
+ unsigned len = name.size();
+
+
ValueState* St = N->getState();
- if (name == "compare:") {
- // Check if the compared NSString is nil.
- Expr * E = ME->getArg(0);
- RVal X = GetRVal(St, E);
+ switch (len) {
+ default:
+ break;
+ case 8:
+ if (!strcmp(cstr, "compare:")) {
+ // Check if the compared NSString is nil.
+ Expr * E = ME->getArg(0);
- if (isNil(X))
- RegisterError(N, E,
- "Argument to NSString method 'compare:' cannot be nil.");
+ if (isNil(GetRVal(St, E))) {
+ Warn(N, E, "Argument to NSString method 'compare:' cannot be nil.");
+ return false;
+ }
+
+ break;
+ }
+
+ break;
}
return false;
OpenPOWER on IntegriCloud