]> granicus.if.org Git - clang/commitdiff
Teach VariadicMethodTypeChecker about pointers attributed as 'NSObject'.
authorTed Kremenek <kremenek@apple.com>
Thu, 17 Mar 2011 04:10:25 +0000 (04:10 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 17 Mar 2011 04:10:25 +0000 (04:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127798 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
test/Analysis/variadic-method-types.m

index 51847094dadb8b16d69ed90bf96c1873ebaef883..60c437c1e6f2b2a38047711c6dfd0f58ade69e9d 100644 (file)
@@ -596,6 +596,10 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg,
     if (isa<loc::ConcreteInt>(msg.getArgSVal(I, state)))
       continue;
     
+    // Ignore pointer types annotated with 'NSObject' attribute.
+    if (C.getASTContext().isObjCNSObjectType(ArgTy))
+      continue;
+    
     // Ignore CF references, which can be toll-free bridged.
     if (cocoa::isCFObjectRef(ArgTy))
       continue;
index 7d199134355f64c79ebc174a95d8cb40e9cb04b6..1f8f6b448cae520ef253ce20b95e63733bdce9bd 100644 (file)
@@ -61,7 +61,11 @@ typedef struct {} NSFastEnumerationState;
 @protocol P;
 @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:@"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", (void*) 0, 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 *'}}
 }
 
-int main() {
-  f(nil, nil, nil, nil);
-}