[cfe-commits] r129615 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/SemaObjC/nonnull.m

Fariborz Jahanian fjahanian at apple.com
Fri Apr 15 15:06:22 PDT 2011


Author: fjahanian
Date: Fri Apr 15 17:06:22 2011
New Revision: 129615

URL: http://llvm.org/viewvc/llvm-project?rev=129615&view=rev
Log:
Enforce nonnull __attribute__ on Objective-C method calls.
// rdar://9287695

Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/nonnull.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=129615&r1=129614&r2=129615&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Apr 15 17:06:22 2011
@@ -324,6 +324,12 @@
                        Args[NumArgs-1]->getLocEnd());
     }
   }
+  // diagnose nonnull arguments.
+  for (specific_attr_iterator<NonNullAttr>
+       i = Method->specific_attr_begin<NonNullAttr>(),
+       e = Method->specific_attr_end<NonNullAttr>(); i != e; ++i) {
+    CheckNonNullArguments(*i, Args, lbrac);
+  }
 
   DiagnoseSentinelCalls(Method, lbrac, Args, NumArgs);
   return IsError;

Modified: cfe/trunk/test/SemaObjC/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?rev=129615&r1=129614&r2=129615&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.m (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Fri Apr 15 17:06:22 2011
@@ -67,3 +67,30 @@
   _dispatch_queue_push_list(_head._do);  // no warning
 }
 
+// rdar://9287695
+#define NULL (void*)0
+
+ at interface NSObject 
+- (void)doSomethingWithNonNullPointer:(void *)ptr :(int)iarg : (void*)ptr1 __attribute__((nonnull(1, 3)));
++ (void)doSomethingClassyWithNonNullPointer:(void *)ptr __attribute__((nonnull(1)));
+ at end
+
+extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
+
+ at interface IMP 
+{
+  void * vp;
+}
+ at end
+
+ at implementation IMP
+- (void) Meth {
+  NSObject *object;
+  [object doSomethingWithNonNullPointer:NULL:1:NULL]; // expected-warning 2 {{null passed to a callee which requires a non-null argument}}
+  [object doSomethingWithNonNullPointer:vp:1:NULL]; // expected-warning {{null passed to a callee which requires a non-null argument}}
+  [NSObject doSomethingClassyWithNonNullPointer:NULL]; // expected-warning {{null passed to a callee which requires a non-null argument}}
+  DoSomethingNotNull(NULL); // expected-warning {{null passed to a callee which requires a non-null argument}}
+  [object doSomethingWithNonNullPointer:vp:1:vp];
+}
+ at end
+





More information about the cfe-commits mailing list