From: Ted Kremenek Date: Wed, 16 Mar 2011 00:22:51 +0000 (+0000) Subject: VariadicMethodTypeChecker: don't warn for null pointer constants passed to variadic... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d5fde2106af8e78cc1b97d6369ad0de5d0875491;p=clang VariadicMethodTypeChecker: don't warn for null pointer constants passed to variadic Objective-C methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127719 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp index 8677f08ab9..792b720b8f 100644 --- a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -584,12 +584,17 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg, // Verify that all arguments have Objective-C types. llvm::Optional errorNode; + const GRState *state = C.getState(); for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) { QualType ArgTy = msg.getArgType(I); if (ArgTy->isObjCObjectPointerType()) continue; + // Ignore pointer constants. + if (isa(msg.getArgSVal(I, state))) + continue; + // Generate only one error node to use for all bug reports. if (!errorNode.hasValue()) { errorNode = C.generateNode(); diff --git a/test/Analysis/variadic-method-types.m b/test/Analysis/variadic-method-types.m index bd1b227f9f..6f67d2f0d5 100644 --- a/test/Analysis/variadic-method-types.m +++ b/test/Analysis/variadic-method-types.m @@ -69,6 +69,7 @@ void f(id a, id

b, C* c, C

*d) { [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} }