Teach VariadicMethodTypeChecker about pointers attributed as 'NSObject'.

llvm-svn: 127798
This commit is contained in:
Ted Kremenek 2011-03-17 04:10:25 +00:00
parent 6fa1daede5
commit 70727343cf
2 changed files with 11 additions and 4 deletions

View File

@ -596,6 +596,10 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg,
if (isa<loc::ConcreteInt>(msg.getArgSVal(I, state))) if (isa<loc::ConcreteInt>(msg.getArgSVal(I, state)))
continue; continue;
// Ignore pointer types annotated with 'NSObject' attribute.
if (C.getASTContext().isObjCNSObjectType(ArgTy))
continue;
// Ignore CF references, which can be toll-free bridged. // Ignore CF references, which can be toll-free bridged.
if (cocoa::isCFObjectRef(ArgTy)) if (cocoa::isCFObjectRef(ArgTy))
continue; continue;

View File

@ -61,7 +61,11 @@ typedef struct {} NSFastEnumerationState;
@protocol P; @protocol P;
@class C; @class C;
void f(id a, id<P> b, C* c, C<P> *d) { typedef struct FooType * __attribute__ ((NSObject)) FooType;
typedef struct BarType * BarType;
void f(id a, id<P> b, C* c, C<P> *d, FooType fooType, BarType barType) {
[NSArray arrayWithObjects:@"Hello", a, b, c, d, nil]; [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];
[NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{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 *'}}
@ -72,9 +76,8 @@ void f(id a, id<P> b, C* c, C<P> *d) {
[[[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", "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", (void*) 0, nil] autorelease]; // no-warning
[[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning
[[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", fooType, nil] autorelease]; // no-warning
[[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", barType, nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'BarType'}}
[[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}}
} }
int main() {
f(nil, nil, nil, nil);
}