[cfe-commits] r127605 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp test/Analysis/variadic-method-types.m
Ted Kremenek
kremenek at apple.com
Mon Mar 14 12:50:37 PDT 2011
Author: kremenek
Date: Mon Mar 14 14:50:37 2011
New Revision: 127605
URL: http://llvm.org/viewvc/llvm-project?rev=127605&view=rev
Log:
Tweak VariadicMethodTypeChecker to only create one ExplodedNode when issuing multiple warnings for the same message expression.
Also add a test case showing that we correctly report multiple warnings for the same message expression.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
cfe/trunk/test/Analysis/variadic-method-types.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127605&r1=127604&r2=127605&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Mon Mar 14 14:50:37 2011
@@ -502,10 +502,7 @@
bool
VariadicMethodTypeChecker::isVariadicMessage(const ObjCMessage &msg) const {
const ObjCMethodDecl *MD = msg.getMethodDecl();
- if (!MD)
- return false;
-
- if (!MD->isVariadic())
+ if (!MD || !MD->isVariadic())
return false;
Selector S = msg.getSelector();
@@ -586,13 +583,19 @@
return;
// Verify that all arguments have Objective-C types.
+ llvm::Optional<ExplodedNode*> errorNode;
+
for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) {
QualType ArgTy = msg.getArgType(I);
if (ArgTy->isObjCObjectPointerType())
continue;
- ExplodedNode *N = C.generateNode();
- if (!N)
+ // Generate only one error node to use for all bug reports.
+ if (!errorNode.hasValue()) {
+ errorNode = C.generateNode();
+ }
+
+ if (!errorNode.getValue())
continue;
llvm::SmallString<128> sbuf;
@@ -607,7 +610,8 @@
<< "' should be an Objective-C pointer type, not '"
<< ArgTy.getAsString() << "'";
- RangedBugReport *R = new RangedBugReport(*BT, os.str(), N);
+ RangedBugReport *R = new RangedBugReport(*BT, os.str(),
+ errorNode.getValue());
R->addRange(msg.getArgSourceRange(I));
C.EmitReport(R);
}
Modified: cfe/trunk/test/Analysis/variadic-method-types.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127605&r1=127604&r2=127605&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/variadic-method-types.m (original)
+++ cfe/trunk/test/Analysis/variadic-method-types.m Mon Mar 14 14:50:37 2011
@@ -63,7 +63,7 @@
void f(id a, id<P> b, C* c, C<P> *d) {
[NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];
- [NSArray arrayWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
+ [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
[NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
[NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}}
More information about the cfe-commits
mailing list