diff options
Diffstat (limited to 'test/SemaObjC')
35 files changed, 486 insertions, 170 deletions
diff --git a/test/SemaObjC/assign-rvalue-message.m b/test/SemaObjC/assign-rvalue-message.m new file mode 100644 index 0000000..7e05c89 --- /dev/null +++ b/test/SemaObjC/assign-rvalue-message.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fobjc-nonfragile-abi %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -fobjc-nonfragile-abi %s +// rdar://9005189 + +@interface Foo +@end + +struct Bar { + int x; +}; + +@implementation Foo { + struct Bar bar; +} + +- (const struct Bar)bar { + return bar; +} + +- (void)baz { + bar.x = 0; + [self bar].x = 10; // expected-error {{assigning to 'readonly' return result of an objective-c message not allowed}} +} +@end diff --git a/test/SemaObjC/attr-objc-gc.m b/test/SemaObjC/attr-objc-gc.m index 47da653..9ca12c9 100644 --- a/test/SemaObjC/attr-objc-gc.m +++ b/test/SemaObjC/attr-objc-gc.m @@ -1,8 +1,30 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s static id __attribute((objc_gc(weak))) a; static id __attribute((objc_gc(strong))) b; static id __attribute((objc_gc())) c; // expected-error{{'objc_gc' attribute requires parameter 1 to be a string}} static id __attribute((objc_gc(123))) d; // expected-error{{'objc_gc' attribute requires parameter 1 to be a string}} -static id __attribute((objc_gc(foo, 456))) e; // expected-error{{attribute requires 1 argument(s)}} +static id __attribute((objc_gc(foo, 456))) e; // expected-error{{attribute takes one argument}} static id __attribute((objc_gc(hello))) f; // expected-warning{{'objc_gc' attribute argument not supported: 'hello'}} + +static int __attribute__((objc_gc(weak))) g; // expected-warning {{'objc_gc' only applies to pointer types; type here is 'int'}} + +static __weak int h; // expected-warning {{'__weak' only applies to pointer types; type here is 'int'}} + +// TODO: it would be great if this reported as __weak +#define WEAK __weak +static WEAK int h; // expected-warning {{'objc_gc' only applies to pointer types; type here is 'int'}} + +/* expected-warning {{'__weak' only applies to pointer types; type here is 'int'}}*/ static __we\ +ak int i; + +// rdar://problem/9126213 +void test2(id __attribute((objc_gc(strong))) *strong, + id __attribute((objc_gc(weak))) *weak) { + void *opaque; + opaque = strong; + strong = opaque; + + opaque = weak; + weak = opaque; +} diff --git a/test/SemaObjC/auto-objective-c.m b/test/SemaObjC/auto-objective-c.m deleted file mode 100644 index 5467e24..0000000 --- a/test/SemaObjC/auto-objective-c.m +++ /dev/null @@ -1,33 +0,0 @@ -// RUN: %clang_cc1 -x objective-c -fblocks -fsyntax-only -verify %s - -@interface I -{ - id pi; -} -- (id) Meth; -@end - -// Objective-C does not support trailing return types, so check we don't get -// the C++ diagnostic suggesting we forgot one. -auto noTrailingReturnType(); // expected-error {{'auto' not allowed in function return type}} - -typedef int (^P) (int x); - -@implementation I -- (id) Meth { - auto p = [pi Meth]; - return p; -} - -- (P) bfunc { - auto my_block = ^int (int x) {return x; }; - my_block(1); - return my_block; -} -@end - - -// rdar://9036633 -int main() { - auto int auto_i = 7; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} -} diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m index c13e806..ebc6777 100644 --- a/test/SemaObjC/block-type-safety.m +++ b/test/SemaObjC/block-type-safety.m @@ -121,3 +121,20 @@ int test4 () { return 0; } +// rdar:// 9118343 + +@protocol NSCopying @end + +@interface NSAllArray <NSCopying> +@end + +@interface NSAllArray (FooConformance) <Foo> +@end + +int test5() { + NSAllArray *(^block)(id); + id <Foo> (^genericBlock)(id); + genericBlock = block; + return 0; +} + diff --git a/test/SemaObjC/call-super-2.m b/test/SemaObjC/call-super-2.m index 84a625c..d77b759 100644 --- a/test/SemaObjC/call-super-2.m +++ b/test/SemaObjC/call-super-2.m @@ -35,8 +35,8 @@ id objc_getClass(const char *s); @implementation Derived + (int) class_func1 { - int i = (size_t)[self class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} - return i + (size_t)[super class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} + int i = (size_t)[self class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}} + return i + (size_t)[super class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}} } + (int) class_func2 { @@ -55,8 +55,8 @@ id objc_getClass(const char *s); } + (int) class_func5 { - int i = (size_t)[Derived class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} - return i + (size_t)[Object class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} + int i = (size_t)[Derived class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}} + return i + (size_t)[Object class_func0]; // expected-warning {{class method '+class_func0' not found (return type defaults to 'id')}} } + (int) class_func6 { @@ -68,7 +68,7 @@ id objc_getClass(const char *s); } - (int) instance_func1 { - int i = (size_t)[self instance_func0]; // expected-warning {{method '-instance_func0' not found (return type defaults to 'id'))}} + int i = (size_t)[self instance_func0]; // expected-warning {{instance method '-instance_func0' not found (return type defaults to 'id'))}} return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0')}} } - (int) instance_func2 @@ -85,8 +85,8 @@ id objc_getClass(const char *s); } - (int) instance_func5 { - int i = (size_t)[Derived instance_func1]; // expected-warning {{method '+instance_func1' not found (return type defaults to 'id')}} - return i + (size_t)[Object instance_func1]; // expected-warning {{method '+instance_func1' not found (return type defaults to 'id')}} + int i = (size_t)[Derived instance_func1]; // expected-warning {{class method '+instance_func1' not found (return type defaults to 'id')}} + return i + (size_t)[Object instance_func1]; // expected-warning {{class method '+instance_func1' not found (return type defaults to 'id')}} } - (int) instance_func6 { diff --git a/test/SemaObjC/class-message-protocol-lookup.m b/test/SemaObjC/class-message-protocol-lookup.m new file mode 100644 index 0000000..ae64ea8 --- /dev/null +++ b/test/SemaObjC/class-message-protocol-lookup.m @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9224670 + +@interface RandomObject { +@private +} ++ (id)alloc; +@end + +@protocol TestProtocol +- (void)nothingInteresting; +@end + +@protocol Test2Protocol ++ (id)alloc; +- (id)alloc2; // expected-note 2 {{method declared here}} +@end + +@implementation RandomObject +- (void) Meth { + Class<TestProtocol> c = [c alloc]; // expected-warning {{class method '+alloc' not found (return type defaults to 'id')}} + Class<Test2Protocol> c1 = [c1 alloc2]; // expected-warning {{instance method 'alloc2' found instead of class method 'alloc2'}} + Class<Test2Protocol> c2 = [c2 alloc]; // ok +} ++ (id)alloc { return 0; } +@end + +int main () +{ + Class<TestProtocol> c = [c alloc]; // expected-warning {{class method '+alloc' not found (return type defaults to 'id')}} + Class<Test2Protocol> c1 = [c1 alloc2]; // expected-warning {{instance method 'alloc2' found instead of class method 'alloc2'}} + Class<Test2Protocol> c2 = [c2 alloc]; // ok + return 0; +} diff --git a/test/SemaObjC/class-unavail-warning.m b/test/SemaObjC/class-unavail-warning.m new file mode 100644 index 0000000..426ac77 --- /dev/null +++ b/test/SemaObjC/class-unavail-warning.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9092208 + +__attribute__((unavailable("not available"))) +@interface MyClass { // expected-note 5 {{function has been explicitly marked unavailable here}} +@public + void *_test; +} + +- (id)self; +- new; ++ (void)addObject:(id)anObject; + +@end + +int main() { + [MyClass new]; // expected-error {{'MyClass' is unavailable: not available}} + [MyClass self]; // expected-error {{'MyClass' is unavailable: not available}} + [MyClass addObject:((void *)0)]; // expected-error {{'MyClass' is unavailable: not available}} + + MyClass *foo = [MyClass new]; // expected-error 2 {{'MyClass' is unavailable: not available}} + + return 0; +} diff --git a/test/SemaObjC/comptypes-4.m b/test/SemaObjC/comptypes-4.m index 56b23b2..adc324c 100644 --- a/test/SemaObjC/comptypes-4.m +++ b/test/SemaObjC/comptypes-4.m @@ -12,7 +12,7 @@ int main() MyClass *obj_cp; obj_cp = obj_p; - obj_p = obj_cp; + obj_p = obj_cp; // expected-warning {{incompatible pointer types assigning to 'MyClass<MyProtocol> *' from 'MyClass *'}} if (obj_cp == obj_p) foo(); diff --git a/test/SemaObjC/conditional-expr-8.m b/test/SemaObjC/conditional-expr-8.m new file mode 100644 index 0000000..6799983 --- /dev/null +++ b/test/SemaObjC/conditional-expr-8.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9296866 + +@interface NSResponder +@end + + +@interface NSView : NSResponder +@end + +@interface WebView : NSView +@end + +@protocol WebDocumentView +@end + +@implementation NSView + +- (void) FUNC : (id)s { + WebView *m_webView; + NSView <WebDocumentView> *documentView; + NSView *coordinateView = s ? documentView : m_webView; +} +@end + diff --git a/test/SemaObjC/exprs.m b/test/SemaObjC/exprs.m index 13c34e5..d7c1223 100644 --- a/test/SemaObjC/exprs.m +++ b/test/SemaObjC/exprs.m @@ -9,12 +9,12 @@ Class test1(Class X) { // rdar://6079877 void test2() { id str = @"foo" - "bar\0" // expected-warning {{literal contains NUL character}} + "bar\0" // no-warning @"baz" " blarg"; id str2 = @"foo" "bar" @"baz" - " b\0larg"; // expected-warning {{literal contains NUL character}} + " b\0larg"; // no-warning if (@encode(int) == "foo") { } // expected-warning {{result of comparison against @encode is unspecified}} diff --git a/test/SemaObjC/foreach.m b/test/SemaObjC/foreach.m index 0f7fd9e..c865374 100644 --- a/test/SemaObjC/foreach.m +++ b/test/SemaObjC/foreach.m @@ -16,3 +16,33 @@ void f(NSArray *a) { for (id thisKey in keys); for (id thisKey in keys); } + +/* // rdar://9072298 */ +@protocol NSObject @end + +@interface NSObject <NSObject> { + Class isa; +} +@end + +typedef struct { + unsigned long state; + id *itemsPtr; + unsigned long *mutationsPtr; + unsigned long extra[5]; +} NSFastEnumerationState; + +@protocol NSFastEnumeration + +- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len; + +@end + +int main () +{ + NSObject<NSFastEnumeration>* collection = ((void*)0); + for (id thing in collection) { } + + return 0; +} + diff --git a/test/SemaObjC/format-arg-attribute.m b/test/SemaObjC/format-arg-attribute.m index 98dff3a..6edb8fd 100644 --- a/test/SemaObjC/format-arg-attribute.m +++ b/test/SemaObjC/format-arg-attribute.m @@ -5,16 +5,16 @@ extern NSString *fa2 (const NSString *) __attribute__((format_arg(1))); extern NSString *fa3 (NSString *) __attribute__((format_arg(1))); -extern void fc1 (const NSString *) __attribute__((format_arg)); // expected-error {{attribute requires 1 argument(s)}} -extern void fc2 (const NSString *) __attribute__((format_arg())); // expected-error {{attribute requires 1 argument(s)}} -extern void fc3 (const NSString *) __attribute__((format_arg(1, 2))); // expected-error {{attribute requires 1 argument(s)}} +extern void fc1 (const NSString *) __attribute__((format_arg)); // expected-error {{attribute takes one argument}} +extern void fc2 (const NSString *) __attribute__((format_arg())); // expected-error {{attribute takes one argument}} +extern void fc3 (const NSString *) __attribute__((format_arg(1, 2))); // expected-error {{attribute takes one argument}} struct s1 { int i; } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to functions}} union u1 { int i; } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to functions}} enum e1 { E1V0 } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to functions}} extern NSString *ff3 (const NSString *) __attribute__((format_arg(3-2))); -extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{attribute requires 1 argument(s)}} +extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{attribute takes one argument}} /* format_arg formats must take and return a string. */ extern NSString *fi0 (int) __attribute__((format_arg(1))); // expected-error {{format argument not a string type}} diff --git a/test/SemaObjC/iboutletcollection-attr.m b/test/SemaObjC/iboutletcollection-attr.m index 217daa7..5c82c83 100644 --- a/test/SemaObjC/iboutletcollection-attr.m +++ b/test/SemaObjC/iboutletcollection-attr.m @@ -16,13 +16,13 @@ typedef void *PV; @interface BAD { - __attribute__((iboutletcollection(I, 1))) id ivar1; // expected-error {{attribute requires 1 argument(s)}} + __attribute__((iboutletcollection(I, 1))) id ivar1; // expected-error {{attribute takes one argument}} __attribute__((iboutletcollection(B))) id ivar2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribute}} __attribute__((iboutletcollection(PV))) id ivar3; // expected-error {{invalid type 'PV' as argument of iboutletcollection attribute}} __attribute__((iboutletcollection(PV))) void *ivar4; // expected-error {{ivar with iboutletcollection attribute must have object type (invalid 'void *')}} __attribute__((iboutletcollection(int))) id ivar5; // expected-error {{type argument of iboutletcollection attribute cannot be a builtin type}} } -@property (nonatomic, retain) __attribute__((iboutletcollection(I,2,3))) id prop1; // expected-error {{attribute requires 1 argument(s)}} +@property (nonatomic, retain) __attribute__((iboutletcollection(I,2,3))) id prop1; // expected-error {{attribute takes one argument}} @property (nonatomic, retain) __attribute__((iboutletcollection(B))) id prop2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribute}} @property __attribute__((iboutletcollection(BAD))) int prop3; // expected-error {{property with iboutletcollection attribute must have object type (invalid 'int')}} diff --git a/test/SemaObjC/idiomatic-parentheses.m b/test/SemaObjC/idiomatic-parentheses.m index 011efbc..39e97e2 100644 --- a/test/SemaObjC/idiomatic-parentheses.m +++ b/test/SemaObjC/idiomatic-parentheses.m @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wparentheses %s -// Don't warn about some common ObjC idioms unless we have -Wparentheses on. +// Don't warn about some common ObjC idioms unless we have -Widiomatic-parentheses on. // <rdar://problem/7382435> @interface Object diff --git a/test/SemaObjC/ignore-weakimport-method.m b/test/SemaObjC/ignore-weakimport-method.m index f80312a..d71cebf 100644 --- a/test/SemaObjC/ignore-weakimport-method.m +++ b/test/SemaObjC/ignore-weakimport-method.m @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s - @interface foo + (void) cx __attribute__((weak_import)); - (void) x __attribute__((weak_import)); diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index 06e4711..2b14bff 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -35,3 +35,15 @@ extern struct foo x; } @end +@interface TwoIvars { + int a; + int b; +} +@end + +@implementation TwoIvars ++ (int)classMethod { + return a + b; // expected-error{{instance variable 'a' accessed in class method}} \ + // expected-error{{instance variable 'b' accessed in class method}} +} +@end diff --git a/test/SemaObjC/method-arg-decay.m b/test/SemaObjC/method-arg-decay.m deleted file mode 100644 index 6e11e97..0000000 --- a/test/SemaObjC/method-arg-decay.m +++ /dev/null @@ -1,98 +0,0 @@ -// RUN: %clang_cc1 -analyzer-check-objc-mem -verify %s -typedef signed char BOOL; -typedef int NSInteger; -typedef unsigned int NSUInteger; -typedef struct _NSZone NSZone; -@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; -@protocol NSObject - (BOOL)isEqual:(id)object; -@end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; -@end @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; -@end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; -@end @interface NSObject <NSObject> { -} -@end extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); -@interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; -@end @class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; -typedef struct { -} - NSFastEnumerationState; -@protocol NSFastEnumeration - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; -@end @class NSString; -typedef struct _NSRange { -} - NSRange; -@interface NSValue (NSValueRangeExtensions) + (NSValue *)valueWithRange:(NSRange)range; -- (id)objectAtIndex:(NSUInteger)index; -@end typedef unsigned short unichar; -@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length; -@end @class NSArray, NSDictionary, NSString, NSError; -@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count; -@end extern NSString *NSAccessibilityRoleDescription(NSString *role, NSString *subrole) ; -@interface NSResponder : NSObject <NSCoding> { -} -@end @protocol NSAnimatablePropertyContainer - (id)animator; -@end extern NSString *NSAnimationTriggerOrderIn ; -@interface NSView : NSResponder <NSAnimatablePropertyContainer> { -} -@end @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView; -@interface NSWindowController : NSResponder <NSCoding> { -} -@end @class NSArray, NSFont, NSTabViewItem; -@interface NSTabView : NSView { -} -- (NSArray *)tabViewItems; -- (NSString *)label; -@end typedef enum { -PBXNoItemChanged = 0x00, PBXProjectItemChanged = 0x01, PBXReferenceChanged = 0x02, PBXGroupChanged = 0x04, PBXTargetChanged = 0x08, PBXBuildPhaseChanged = 0x10, PBXBuildFileChanged = 0x20, PBXBreakpointChanged = 0x40, } - PBXArchiveMask; -@interface PBXModule : NSWindowController { -} -@end typedef enum { -PBXFindMatchContains, PBXFindMatchStartsWith, PBXFindMatchWholeWords, PBXFindMatchEndsWith } - PBXFindMatchStyle; -@protocol PBXSelectableText - (NSString *)selectedString; -@end @protocol PBXFindableText <PBXSelectableText> - (BOOL)findText:(NSString *)string ignoreCase:(BOOL)ignoreCase matchStyle:(PBXFindMatchStyle)matchStyle backwards:(BOOL)backwards wrap:(BOOL)wrap; -@end @class PBXProjectDocument, PBXProject, PBXAttributedStatusView; -@interface PBXProjectModule : PBXModule <PBXFindableText> { -} -@end @class PBXBookmark; -@protocol PBXSelectionTarget - (NSObject <PBXSelectionTarget> *) performAction:(id)action withSelection:(NSArray *)selection; // expected-note {{method declared here}} -@end @class XCPropertyDictionary, XCPropertyCondition, XCPropertyConditionSet, XCMutablePropertyConditionSet; -extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExposedModulesOnly); -@interface NSString (StringUtilities) - (NSString *) trimToLength:(NSInteger)length preserveRange:(NSRange)range; -- (id) objectOfType:(Class)type matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data; -@end @class XCControlView; -@protocol XCDockViewHeader - (NSImage *) headerImage; -@end @class XCDockableTabModule; -@interface XCExtendedTabView : NSTabView <XCDockViewHeader> { -} -@end @class PBXProjectDocument, PBXFileReference, PBXModule, XCWindowTool; -@interface XCPerspectiveModule : PBXProjectModule <PBXSelectionTarget> { // expected-note {{required for direct or indirect protocol 'PBXSelectionTarget'}} - XCExtendedTabView *_perspectivesTabView; -} -- (PBXModule *) moduleForTab:(NSTabViewItem *)item; // expected-note {{method definition for 'moduleForTab:' not found}} -@end -@implementation XCPerspectiveModule // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} -+ (void) openForProjectDocument:(PBXProjectDocument *)projectDocument { -} -- (PBXModule *) type:(Class)type inPerspective:(id)perspectiveIdentifer matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data { - NSArray *allItems = [_perspectivesTabView tabViewItems]; - NSInteger i, c = [allItems count]; - for (i = 0; - i < c; - i++) { - NSTabViewItem *item = [allItems objectAtIndex:i]; - if ([[item label] isEqual:perspectiveIdentifer]) { - PBXProjectModule *pModule = (PBXProjectModule *)[self moduleForTab:item]; - PBXModule *obj = [XCFindPossibleKeyModules(pModule, (BOOL)0) objectOfType:type matchingFunction:comparator usingData:data]; - } - } - return 0; -} -- (BOOL)buffer:(char *)buf containsAnyPrompts:(char *[])prompts -{ - prompts++; - return (BOOL)0; -} -@end diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m index 388e447..0a1b1cd 100644 --- a/test/SemaObjC/method-bad-param.m +++ b/test/SemaObjC/method-bad-param.m @@ -26,7 +26,7 @@ foo somefunc2() {} // expected-error {{Objective-C interface type 'foo' cannot b // rdar://6780761 void f0(foo *a0) { extern void g0(int x, ...); - g0(1, *(foo*)0); // expected-error {{cannot pass object with interface type 'foo' by-value through variadic function}} + g0(1, *(foo*)a0); // expected-error {{cannot pass object with interface type 'foo' by-value through variadic function}} } // rdar://8421082 diff --git a/test/SemaObjC/method-not-defined.m b/test/SemaObjC/method-not-defined.m index 78bf650..ed68b22 100644 --- a/test/SemaObjC/method-not-defined.m +++ b/test/SemaObjC/method-not-defined.m @@ -7,7 +7,7 @@ void test() { Foo *fooObj; id obj; - [[Foo alloc] init]; // expected-warning {{method '+alloc' not found (return type defaults to 'id')}} expected-warning {{method '-init' not found (return type defaults to 'id')}} - [fooObj notdefined]; // expected-warning {{method '-notdefined' not found (return type defaults to 'id')}} - [obj whatever:1 :2 :3]; // expected-warning {{method '-whatever:::' not found (return type defaults to 'id'))}} + [[Foo alloc] init]; // expected-warning {{class method '+alloc' not found (return type defaults to 'id')}} expected-warning {{instance method '-init' not found (return type defaults to 'id')}} + [fooObj notdefined]; // expected-warning {{instance method '-notdefined' not found (return type defaults to 'id')}} + [obj whatever:1 :2 :3]; // expected-warning {{instance method '-whatever:::' not found (return type defaults to 'id'))}} } diff --git a/test/SemaObjC/method-prototype-scope.m b/test/SemaObjC/method-prototype-scope.m index 2184172..b08faa6 100644 --- a/test/SemaObjC/method-prototype-scope.m +++ b/test/SemaObjC/method-prototype-scope.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wduplicate-method-arg -verify %s // rdar://8877730 @@ -11,7 +11,7 @@ int object; - doSomethingElseWith:(id)object; -- (NSString *)doSomethingWith:(NSString *)object and:(NSArray *)object; // expected-warning {{redefinition of method parameter 'object'}} \ +- (NSString *)doSomethingWith:(NSString *)object and:(NSArray *)object; // expected-warning {{redeclaration of method parameter 'object'}} \ // expected-note {{previous declaration is here}} @end diff --git a/test/SemaObjC/method-sentinel-attr.m b/test/SemaObjC/method-sentinel-attr.m index 5375408..274e936 100644 --- a/test/SemaObjC/method-sentinel-attr.m +++ b/test/SemaObjC/method-sentinel-attr.m @@ -13,7 +13,7 @@ - (void) foo8 : (int)x, ... __attribute__ ((__sentinel__("a"))); // expected-error {{'sentinel' attribute requires parameter 1 to be an integer constant}} - (void) foo9 : (int)x, ... __attribute__ ((__sentinel__(-1))); // expected-error {{'sentinel' parameter 1 less than zero}} - (void) foo10 : (int)x, ... __attribute__ ((__sentinel__(1,1))); -- (void) foo11 : (int)x, ... __attribute__ ((__sentinel__(1,1,3))); // expected-error {{attribute requires 0, 1 or 2 argument(s)}} +- (void) foo11 : (int)x, ... __attribute__ ((__sentinel__(1,1,3))); // expected-error {{attribute takes no more than 2 arguments}} - (void) foo12 : (int)x, ... ATTR; // expected-note {{method has been explicitly marked sentinel here}} // rdar://7975788 diff --git a/test/SemaObjC/missing-atend-metadata.m b/test/SemaObjC/missing-atend-metadata.m new file mode 100644 index 0000000..434706d --- /dev/null +++ b/test/SemaObjC/missing-atend-metadata.m @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s + +@interface I0 +@end + +@implementation I0 // expected-error {{'@end' is missing in implementation context}} +- meth { return 0; } + +@interface I1 : I0 +@end + +@implementation I1 // expected-error {{'@end' is missing in implementation context}} +-(void) im0 { self = [super init]; } // expected-warning {{nstance method '-init' not found }} + +@interface I2 : I0 +- I2meth; +@end + +@implementation I2 // expected-error {{'@end' is missing in implementation context}} +- I2meth { return 0; } + +@implementation I2(CAT) // expected-error {{'@end' is missing in implementation context}} diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m index 6c45d97..76c6ffa 100644 --- a/test/SemaObjC/nonnull.m +++ b/test/SemaObjC/nonnull.m @@ -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 + diff --git a/test/SemaObjC/objc-qualified-property-lookup.m b/test/SemaObjC/objc-qualified-property-lookup.m new file mode 100644 index 0000000..daf583d --- /dev/null +++ b/test/SemaObjC/objc-qualified-property-lookup.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9078584 + +@interface NSObject @end + +@protocol TextInput +-editRange; +@end + +@interface I { + NSObject<TextInput>* editor; +} +- (id) Meth; +@end + +@implementation I +- (id) Meth { + return editor.editRange; +} +@end + diff --git a/test/SemaObjC/property-13.m b/test/SemaObjC/property-13.m index 6d56dab..2ca3416 100644 --- a/test/SemaObjC/property-13.m +++ b/test/SemaObjC/property-13.m @@ -48,7 +48,7 @@ void abort(void); int main () { Test *x = [[Test alloc] init]; - /* 1. Test of a requred property */ + /* 1. Test of a required property */ x.required1 = 100; if (x.required1 != 100) abort (); diff --git a/test/SemaObjC/property-lookup-in-id.m b/test/SemaObjC/property-lookup-in-id.m new file mode 100644 index 0000000..86da48e --- /dev/null +++ b/test/SemaObjC/property-lookup-in-id.m @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9106929 + +typedef struct objc_class *Class; + +typedef struct objc_object { + Class isa; +} *id; + + +typedef struct __FSEventStream* FSEventStreamRef; + +extern id NSApp; + +@interface FileSystemMonitor { + + FSEventStreamRef fsEventStream; +} +@property(assign) FSEventStreamRef fsEventStream; + +@end + +@implementation FileSystemMonitor +@synthesize fsEventStream; + +- (void)startFSEventGathering:(id)sender +{ + fsEventStream = [NSApp delegate].fsEventStream; // expected-warning {{warning: instance method '-delegate' not found (return type defaults to 'id')}} \ + // expected-error {{property 'fsEventStream' not found on object of type 'id'}} + +} +@end + diff --git a/test/SemaObjC/protocol-attribute.m b/test/SemaObjC/protocol-attribute.m index 52c9803..178774c 100644 --- a/test/SemaObjC/protocol-attribute.m +++ b/test/SemaObjC/protocol-attribute.m @@ -40,7 +40,7 @@ Class <MyProto1> clsP1 = 0; // expected-warning {{'MyProto1' is deprecated}} __attribute ((unavailable)) __attribute ((deprecated)) @protocol XProto; // expected-note{{marked unavailable}} -id <XProto> idX = 0; // expected-error {{'XProto' is unavailable}} expected-warning {{'XProto' is deprecated}} +id <XProto> idX = 0; // expected-error {{'XProto' is unavailable}} int main () { diff --git a/test/SemaObjC/self-declared-in-block.m b/test/SemaObjC/self-declared-in-block.m new file mode 100644 index 0000000..4bd7202 --- /dev/null +++ b/test/SemaObjC/self-declared-in-block.m @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -verify %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -verify %s +// rdar://9154582 + +@interface Blocky @end + +@implementation Blocky { + int _a; +} +- (void)doAThing { + ^{ + char self; // expected-note {{declared here}} + _a; // expected-error {{instance variable '_a' cannot be accessed because 'self' has been redeclared}} + }(); +} + +@end + + +// rdar://9284603 +@interface ShadowSelf +{ + int _anIvar; +} +@end + +@interface C { + int _cIvar; +} +@end + +@implementation ShadowSelf +- (void)doSomething { + __typeof(self) newSelf = self; + { + __typeof(self) self = newSelf; + (void)_anIvar; + } + { + C* self; // expected-note {{declared here}} + (void) _anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}} + } +} +- (void)doAThing { + ^{ + id self; // expected-note {{declared here}} + (void)_anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}} + }(); +} +@end + diff --git a/test/SemaObjC/self-in-function.m b/test/SemaObjC/self-in-function.m new file mode 100644 index 0000000..9027a94 --- /dev/null +++ b/test/SemaObjC/self-in-function.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s +// rdar://9181463 + +typedef struct objc_class *Class; + +typedef struct objc_object { + Class isa; +} *id; + +@interface NSObject ++ (id) alloc; +@end + + +void foo(Class self) { + [self alloc]; + (^() { + [self alloc]; + })(); +} + +void bar(Class self) { + Class y = self; + [y alloc]; +} + diff --git a/test/SemaObjC/sizeof-interface.m b/test/SemaObjC/sizeof-interface.m index 9d85f1f5..3fe3964 100644 --- a/test/SemaObjC/sizeof-interface.m +++ b/test/SemaObjC/sizeof-interface.m @@ -43,7 +43,7 @@ int g2[ sizeof(I0) // expected-error {{invalid application of 'sizeof' to inte @synthesize p0 = _p0; @end -typedef struct { @defs(I1) } I1_defs; // expected-error {{invalid application of @defs in non-fragile ABI}} +typedef struct { @defs(I1); } I1_defs; // expected-error {{invalid application of @defs in non-fragile ABI}} // FIXME: This is currently broken due to the way the record layout we // create is tied to whether we have seen synthesized properties. Ugh. diff --git a/test/SemaObjC/special-dep-unavail-warning.m b/test/SemaObjC/special-dep-unavail-warning.m index b7a2d66..1d07a49 100644 --- a/test/SemaObjC/special-dep-unavail-warning.m +++ b/test/SemaObjC/special-dep-unavail-warning.m @@ -27,7 +27,7 @@ @end -@class C; +@class C; // expected-note 5 {{forward class is declared here}} void test(C *c) { [c depInA]; // expected-warning {{'depInA' maybe deprecated because receiver type is unknown}} @@ -36,10 +36,8 @@ void test(C *c) { [c unavailMeth1]; // expected-warning {{'unavailMeth1' maybe unavailable because receiver type is unknown}} [c depInA2]; // expected-warning {{'depInA2' maybe deprecated because receiver type is unknown}} [c unavailMeth2]; // expected-warning {{'unavailMeth2' maybe unavailable because receiver type is unknown}} - [c depunavailInA]; // expected-warning {{'depunavailInA' maybe deprecated because receiver type is unknown}} \ - // expected-warning {{'depunavailInA' maybe unavailable because receiver type is unknown}} - [c depunavailInA1]; // expected-warning {{'depunavailInA1' maybe deprecated because receiver type is unknown}} \ - // expected-warning {{'depunavailInA1' maybe unavailable because receiver type is unknown}} + [c depunavailInA]; // expected-warning {{'depunavailInA' maybe unavailable because receiver type is unknown}} + [c depunavailInA1];// expected-warning {{'depunavailInA1' maybe unavailable because receiver type is unknown}} [c FuzzyMeth]; // expected-warning {{'FuzzyMeth' maybe deprecated because receiver type is unknown}} [c FuzzyMeth1]; // expected-warning {{'FuzzyMeth1' maybe deprecated because receiver type is unknown}} diff --git a/test/SemaObjC/uninit-variables.m b/test/SemaObjC/uninit-variables.m index 63c2140..b5c4918 100644 --- a/test/SemaObjC/uninit-variables.m +++ b/test/SemaObjC/uninit-variables.m @@ -1,10 +1,10 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fblocks %s -verify // Duplicated from uninit-variables.c. // Test just to ensure the analysis is working. int test1() { int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization}} - return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; // expected-warning{{variable 'x' is uninitialized when used here}} } // Test ObjC fast enumeration. diff --git a/test/SemaObjC/unqualified-to-qualified-class-warn.m b/test/SemaObjC/unqualified-to-qualified-class-warn.m new file mode 100644 index 0000000..e6fa138 --- /dev/null +++ b/test/SemaObjC/unqualified-to-qualified-class-warn.m @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9091389 + +@protocol Fooable +- (void)foo; +@end + +@protocol SubFooable <Fooable> +@end + +@interface AClass +@end + +@interface BClass : AClass <SubFooable> +@end + +@implementation BClass +- (void)foo { +} +@end + +void functionTakingAClassConformingToAProtocol(AClass <Fooable> *instance) { // expected-note {{passing argument to parameter 'instance' here}} +} + +int main () { + AClass *aobject = 0; + BClass *bobject = 0; + functionTakingAClassConformingToAProtocol(aobject); // expected-warning {{incompatible pointer types passing 'AClass *' to parameter of type 'AClass<Fooable> *'}} + functionTakingAClassConformingToAProtocol(bobject); // Shouldn't warn - does implement Fooable + return 0; +} + +// rdar://9267196 +@interface NSObject @end + +@protocol MyProtocol +@end + +@interface MyClass : NSObject +{ +} +@end + +@implementation MyClass +@end + +@interface MySubclass : MyClass <MyProtocol> +{ +} +@end + +@interface MyTestClass : NSObject +{ +@private + NSObject <MyProtocol> *someObj; +} + +@property (nonatomic, assign) NSObject <MyProtocol> *someObj; + +@end + +@implementation MyTestClass + +@synthesize someObj; + +- (void)someMethod +{ + MySubclass *foo; + [self setSomeObj:foo]; // no warning here! +} + +@end diff --git a/test/SemaObjC/warn-write-strings.m b/test/SemaObjC/warn-write-strings.m index 450d0a6..163c864 100644 --- a/test/SemaObjC/warn-write-strings.m +++ b/test/SemaObjC/warn-write-strings.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s +// RUN: %clang_cc1 -verify -fsyntax-only -fconst-strings %s // PR4804 char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}} diff --git a/test/SemaObjC/weak-attr-ivar.m b/test/SemaObjC/weak-attr-ivar.m index d5bbb01..e3d96da 100644 --- a/test/SemaObjC/weak-attr-ivar.m +++ b/test/SemaObjC/weak-attr-ivar.m @@ -72,3 +72,13 @@ typedef enum { Foo_HUH_NONE } FooHUHCode; } @end +// rdar://problem/9123040 +@interface Test1 { +@public + id ivar __attribute__((objc_gc(weak))); +} +@property (assign) id prop __attribute((objc_gc(weak))); +@end +void test1(Test1 *t) { + id *(__attribute__((objc_gc(strong))) x) = &t->ivar; // expected-warning {{initializing '__strong id *' with an expression of type '__weak id *' discards qualifiers}} +} |