Teach VariadicMethodTypeChecker that CF references are valid arguments to variadic Objective-C methods.

llvm-svn: 127797
This commit is contained in:
Ted Kremenek 2011-03-17 04:01:35 +00:00
parent 3e5ad5932e
commit 6fa1daede5
2 changed files with 8 additions and 1 deletions

View File

@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "ClangSACheckers.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@ -594,6 +595,10 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg,
// Ignore pointer constants.
if (isa<loc::ConcreteInt>(msg.getArgSVal(I, state)))
continue;
// Ignore CF references, which can be toll-free bridged.
if (cocoa::isCFObjectRef(ArgTy))
continue;
// Generate only one error node to use for all bug reports.
if (!errorNode.hasValue()) {

View File

@ -11,7 +11,8 @@
//===----------------------------------------------------------------------===//
#define nil (void*)0
typedef const struct __CFString * CFStringRef;
extern const CFStringRef kCGImageSourceShouldCache __attribute__((visibility("default")));
typedef signed char BOOL;
typedef struct _NSZone NSZone;
typedef unsigned int NSUInteger;
@ -70,6 +71,7 @@ void f(id a, id<P> b, C* c, C<P> *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
[[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, 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 *'}}
}