[cfe-commits] r48896 - in /cfe/trunk: lib/Analysis/BasicObjCFoundationChecks.cpp test/Analysis-Apple/NSString.m
Ted Kremenek
kremenek at apple.com
Thu Mar 27 14:23:57 PDT 2008
Author: kremenek
Date: Thu Mar 27 16:23:57 2008
New Revision: 48896
URL: http://llvm.org/viewvc/llvm-project?rev=48896&view=rev
Log:
Add line SourceLocation to NSString checks.
Added test case to test warning about passing 'nil' to NSString's compare: method.
Added:
cfe/trunk/test/Analysis-Apple/NSString.m
Modified:
cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=48896&r1=48895&r2=48896&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Thu Mar 27 16:23:57 2008
@@ -43,7 +43,7 @@
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 @@
//===----------------------------------------------------------------------===//
-void BasicObjCFoundationChecks::RegisterError(NodeTy* N,
+void BasicObjCFoundationChecks::Warn(NodeTy* N,
Expr* E, const char *msg) {
Errors.push_back(AnnotatedPath<ValueState>());
@@ -135,7 +135,7 @@
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 @@
// 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;
Added: cfe/trunk/test/Analysis-Apple/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis-Apple/NSString.m?rev=48896&view=auto
==============================================================================
--- cfe/trunk/test/Analysis-Apple/NSString.m (added)
+++ cfe/trunk/test/Analysis-Apple/NSString.m Thu Mar 27 16:23:57 2008
@@ -0,0 +1,9 @@
+// RUN: clang -grsimple -verify %s
+
+#include <Foundation/NSString.h>
+#include <Foundation/NSObjCRuntime.h>
+
+NSComparisonResult f1(NSString* s) {
+ NSString *aString = nil;
+ return [s compare:aString]; // expected-warning {{Argument to NSString method 'compare:' cannot be nil.}}
+}
More information about the cfe-commits
mailing list