Enforce nonnull __attribute__ on Objective-C method calls.

// rdar://9287695


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129615 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2011-04-15 22:06:22 +00:00
Родитель 7d2b8c1fcc
Коммит 5272adfe70
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -324,6 +324,12 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
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;

Просмотреть файл

@ -67,3 +67,30 @@ void func6(dispatch_object_t _head) {
_dispatch_queue_push_list(_head._do); // no warning
}
// rdar://9287695
#define NULL (void*)0
@interface NSObject
- (void)doSomethingWithNonNullPointer:(void *)ptr :(int)iarg : (void*)ptr1 __attribute__((nonnull(1, 3)));
+ (void)doSomethingClassyWithNonNullPointer:(void *)ptr __attribute__((nonnull(1)));
@end
extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
@interface IMP
{
void * vp;
}
@end
@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];
}
@end