summaryrefslogtreecommitdiffstats
path: root/test/SemaObjC
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaObjC')
-rw-r--r--test/SemaObjC/block-type-safety.m17
-rw-r--r--test/SemaObjC/compare-qualified-class.m30
-rw-r--r--test/SemaObjC/comptypes-5.m4
-rw-r--r--test/SemaObjC/conflict-nonfragile-abi2.m34
-rw-r--r--test/SemaObjC/crash-label.m11
-rw-r--r--test/SemaObjC/default-synthesize-1.m116
-rw-r--r--test/SemaObjC/deref-interface.m2
-rw-r--r--test/SemaObjC/iboutletcollection-attr.m30
-rw-r--r--test/SemaObjC/method-lookup-3.m5
-rw-r--r--test/SemaObjC/method-no-context.m3
-rw-r--r--test/SemaObjC/nonnull.m2
-rw-r--r--test/SemaObjC/property-and-ivar-use.m36
-rw-r--r--test/SemaObjC/property-not-lvalue.m6
-rw-r--r--test/SemaObjC/protocol-attribute.m6
-rw-r--r--test/SemaObjC/protocols.m4
-rw-r--r--test/SemaObjC/static-ivar-ref-1.m18
-rw-r--r--test/SemaObjC/synth-provisional-ivars.m50
-rw-r--r--test/SemaObjC/warn-strict-selector-match.m75
18 files changed, 431 insertions, 18 deletions
diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m
index 402a658..c13e806 100644
--- a/test/SemaObjC/block-type-safety.m
+++ b/test/SemaObjC/block-type-safety.m
@@ -104,3 +104,20 @@ void test3() {
f4(^(NSArray<P2>* a) { }); // expected-error {{incompatible block pointer types passing 'void (^)(NSArray<P2> *)' to parameter of type 'void (^)(id<P>)'}}
}
+// rdar : //8302845
+@protocol Foo @end
+
+@interface Baz @end
+
+@interface Baz(FooConformance) <Foo>
+@end
+
+@implementation Baz @end
+
+int test4 () {
+ id <Foo> (^b)() = ^{ // Doesn't work
+ return (Baz *)0;
+ };
+ return 0;
+}
+
diff --git a/test/SemaObjC/compare-qualified-class.m b/test/SemaObjC/compare-qualified-class.m
new file mode 100644
index 0000000..cb2b26a
--- /dev/null
+++ b/test/SemaObjC/compare-qualified-class.m
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar:// 8191774
+
+@protocol SomeProtocol
+@end
+
+@protocol SomeProtocol1
+@end
+
+@interface SomeObject <SomeProtocol>
+@end
+
+int main () {
+ Class <SomeProtocol> classA;
+ Class <SomeProtocol> classB;
+ Class <SomeProtocol, SomeProtocol1> classC;
+ Class <SomeProtocol1> classD;
+ void * pv = 0;
+ Class c = (Class)0;;
+ if (pv)
+ return classA == pv;
+
+ if (c)
+ return classA == c;
+
+ return classA == classB || classA == classC ||
+ classC == classA ||
+ classA == classD; // expected-warning {{comparison of distinct pointer types ('Class<SomeProtocol> *' and 'Class<SomeProtocol1> *')}}
+}
+
diff --git a/test/SemaObjC/comptypes-5.m b/test/SemaObjC/comptypes-5.m
index aaf6446..46300e3 100644
--- a/test/SemaObjC/comptypes-5.m
+++ b/test/SemaObjC/comptypes-5.m
@@ -26,8 +26,8 @@ int main()
MyOtherClass<MyProtocol> *obj_c_super_p_q = nil;
MyClass<MyProtocol> *obj_c_cat_p_q = nil;
- obj_c_cat_p = obj_id_p;
- obj_c_super_p = obj_id_p;
+ obj_c_cat_p = obj_id_p;
+ obj_c_super_p = obj_id_p;
obj_id_p = obj_c_cat_p; /* Ok */
obj_id_p = obj_c_super_p; /* Ok */
diff --git a/test/SemaObjC/conflict-nonfragile-abi2.m b/test/SemaObjC/conflict-nonfragile-abi2.m
new file mode 100644
index 0000000..e4b513f
--- /dev/null
+++ b/test/SemaObjC/conflict-nonfragile-abi2.m
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -verify -fsyntax-only %s
+// rdar : // 8225011
+
+int glob; // expected-note {{global variable declared here}}
+
+@interface I
+@property int glob; // expected-note {{property declared here}}
+@property int p;
+@property int le;
+@property int l;
+@property int ls;
+@property int r;
+@end
+
+@implementation I
+- (int) Meth { return glob; } // expected-warning {{when default property synthesis is on, 'glob' lookup will access}}
+@synthesize glob;
+// rdar: // 8248681
+- (int) Meth1: (int) p {
+ extern int le;
+ int l = 1;
+ static int ls;
+ register int r;
+ p = le + ls + r;
+ return l;
+}
+@dynamic p;
+@dynamic le;
+@dynamic l;
+@dynamic ls;
+@dynamic r;
+@end
+
+
diff --git a/test/SemaObjC/crash-label.m b/test/SemaObjC/crash-label.m
index d0a5ae4..ffcb463 100644
--- a/test/SemaObjC/crash-label.m
+++ b/test/SemaObjC/crash-label.m
@@ -2,8 +2,9 @@
- (NSDictionary*) _executeScript:(NSString *)source { // expected-error 2 {{expected a type}} \
// expected-error {{missing context for method declaration}}
- Exit: [nilArgs release]; // expected-error {{use of undeclared identifier}}
- }
- - (NSDictionary *) _setupKernelStandardMode:(NSString *)source { // expected-error 2 {{expected a type}} \
-expected-error {{missing context for method declaration}}
- Exit: if(_ciKernel && !success ) { // expected-error {{use of undeclared identifier}} // expected-error 2 {{expected}}
+Exit: [nilArgs release]; // expected-error {{use of undeclared identifier}}
+}
+- (NSDictionary *) _setupKernelStandardMode:(NSString *)source { // expected-error 2 {{expected a type}} \
+expected-error {{missing context for method declaration}} \
+expected-note{{to match this '{'}}
+ Exit: if(_ciKernel && !success ) { // expected-error {{use of undeclared identifier}} // expected-error 2 {{expected}} expected-note{{to match this '{'}}
diff --git a/test/SemaObjC/default-synthesize-1.m b/test/SemaObjC/default-synthesize-1.m
new file mode 100644
index 0000000..374fa83
--- /dev/null
+++ b/test/SemaObjC/default-synthesize-1.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+
+@interface NSObject
+- (void) release;
+- (id) retain;
+@end
+@class NSString;
+
+@interface SynthItAll : NSObject
+@property int howMany;
+@property (retain) NSString* what;
+@end
+
+@implementation SynthItAll
+//@synthesize howMany, what;
+@end
+
+
+@interface SynthSetter : NSObject
+@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair
+@property (nonatomic, retain) NSString* what;
+@end
+
+@implementation SynthSetter
+//@synthesize howMany, what;
+
+- (int) howMany {
+ return howMany;
+}
+// - (void) setHowMany: (int) value
+
+- (NSString*) what {
+ return what;
+}
+// - (void) setWhat: (NSString*) value
+@end
+
+
+@interface SynthGetter : NSObject
+@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair
+@property (nonatomic, retain) NSString* what;
+@end
+
+@implementation SynthGetter
+//@synthesize howMany, what;
+
+// - (int) howMany
+- (void) setHowMany: (int) value {
+ howMany = value;
+}
+
+// - (NSString*) what
+- (void) setWhat: (NSString*) value {
+ if (what != value) {
+ [what release];
+ what = [value retain];
+ }
+}
+@end
+
+
+@interface SynthNone : NSObject
+@property int howMany;
+@property (retain) NSString* what;
+@end
+
+@implementation SynthNone
+//@synthesize howMany, what; // REM: Redundant anyway
+
+- (int) howMany {
+ return howMany;
+}
+- (void) setHowMany: (int) value {
+ howMany = value;
+}
+
+- (NSString*) what {
+ return what;
+}
+- (void) setWhat: (NSString*) value {
+ if (what != value) {
+ [what release];
+ what = [value retain];
+ }
+}
+@end
+
+// rdar://8349319
+// No default synthesis if implementation has getter (readonly) and setter(readwrite) methods.
+@interface DSATextSearchResult
+@property(assign,readonly) float relevance;
+@property(assign,readonly) char isTitleMatch;
+@end
+
+@interface DSANodeSearchResult : DSATextSearchResult {}
+@end
+
+
+@implementation DSATextSearchResult
+-(char)isTitleMatch {
+ return (char)0;
+}
+
+-(float)relevance {
+ return 0.0;
+}
+@end
+
+@implementation DSANodeSearchResult
+-(id)initWithNode:(id )node relevance:(float)relevance isTitleMatch:(char)isTitleMatch {
+ relevance = 0.0;
+ isTitleMatch = 'a';
+ return self;
+}
+@end
+
diff --git a/test/SemaObjC/deref-interface.m b/test/SemaObjC/deref-interface.m
index c7096bd..255e1d0 100644
--- a/test/SemaObjC/deref-interface.m
+++ b/test/SemaObjC/deref-interface.m
@@ -6,7 +6,7 @@
@implementation NSView
- (id)initWithView:(id)realView {
- *(NSView *)self = *(NSView *)realView; // expected-error {{indirection cannot be to an interface in non-fragile ABI}}
+ *(NSView *)self = *(NSView *)realView; // expected-error {{cannot assign to class object in non-fragile ABI}}
}
@end
diff --git a/test/SemaObjC/iboutletcollection-attr.m b/test/SemaObjC/iboutletcollection-attr.m
new file mode 100644
index 0000000..fb64e3a
--- /dev/null
+++ b/test/SemaObjC/iboutletcollection-attr.m
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s
+// rdar: // 8308053
+
+@interface I {
+ __attribute__((iboutletcollection(I))) id ivar1;
+ __attribute__((iboutletcollection(id))) id ivar2;
+ __attribute__((iboutletcollection())) id ivar3;
+ __attribute__((iboutletcollection)) id ivar4;
+}
+@property (nonatomic, retain) __attribute__((iboutletcollection(I))) id prop1;
+@property (nonatomic, retain) __attribute__((iboutletcollection(id))) id prop2;
+@property (nonatomic, retain) __attribute__((iboutletcollection())) id prop3;
+@property (nonatomic, retain) __attribute__((iboutletcollection)) id prop4;
+@end
+
+typedef void *PV;
+@interface BAD {
+ __attribute__((iboutletcollection(I, 1))) id ivar1; // expected-error {{attribute requires 1 argument(s)}}
+ __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(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')}}
+@end
+
diff --git a/test/SemaObjC/method-lookup-3.m b/test/SemaObjC/method-lookup-3.m
index 18a9982..882b3d1 100644
--- a/test/SemaObjC/method-lookup-3.m
+++ b/test/SemaObjC/method-lookup-3.m
@@ -50,3 +50,8 @@ void f4(id a0, Abstract *a1) {
void f5(id a0, Abstract *a1) {
[ a0 setZ: a1];
}
+
+// pr7861
+void f6(id<A> a0) {
+ Abstract *l = [a0 x];
+}
diff --git a/test/SemaObjC/method-no-context.m b/test/SemaObjC/method-no-context.m
index c88205df..3c45bee 100644
--- a/test/SemaObjC/method-no-context.m
+++ b/test/SemaObjC/method-no-context.m
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-- im0 { int a; return 0; // expected-error{{missing context for method declaration}}
+- im0 { // expected-note{{to match this '{'}} expected-error{{missing context for method declaration}}
+ int a; return 0;
// expected-error{{expected '}'}}
diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m
index 642f50f..15fee74 100644
--- a/test/SemaObjC/nonnull.m
+++ b/test/SemaObjC/nonnull.m
@@ -43,3 +43,5 @@ foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
func6((NSObject*) 0); // no-warning
func7((NSObject*) 0); // no-warning
}
+
+void func5(int) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
diff --git a/test/SemaObjC/property-and-ivar-use.m b/test/SemaObjC/property-and-ivar-use.m
new file mode 100644
index 0000000..b9235c1
--- /dev/null
+++ b/test/SemaObjC/property-and-ivar-use.m
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// Do not issue error if 'ivar' used previously belongs to the inherited class
+// and has same name as @dynalic property in current class.
+
+typedef signed char BOOL;
+
+@protocol IDEBuildable
+@property (readonly) BOOL hasRecursiveDependencyCycle;
+@end
+
+@protocol IDEBuildableProduct <IDEBuildable>
+@end
+
+@interface IDEBuildableSupportMixIn
+@property (readonly) BOOL hasRecursiveDependencyCycle;
+@end
+
+@interface Xcode3TargetBuildable <IDEBuildable>
+{
+ IDEBuildableSupportMixIn *_buildableMixIn;
+}
+@end
+
+@interface Xcode3TargetProduct : Xcode3TargetBuildable <IDEBuildableProduct>
+@end
+
+@implementation Xcode3TargetBuildable
+- (BOOL)hasRecursiveDependencyCycle
+{
+ return [_buildableMixIn hasRecursiveDependencyCycle];
+}
+@end
+
+@implementation Xcode3TargetProduct
+@dynamic hasRecursiveDependencyCycle;
+@end
diff --git a/test/SemaObjC/property-not-lvalue.m b/test/SemaObjC/property-not-lvalue.m
index 55eec3e..3d95d26 100644
--- a/test/SemaObjC/property-not-lvalue.m
+++ b/test/SemaObjC/property-not-lvalue.m
@@ -15,8 +15,8 @@ typedef struct NSSize {
void foo() {
Foo *f;
- f.size.width = 2.2; // expected-error {{expression is not assignable using property assignment syntax}}
- f.size.inner.dim = 200; // expected-error {{expression is not assignable using property assignment syntax}}
+ f.size.width = 2.2; // expected-error {{expression is not assignable}}
+ f.size.inner.dim = 200; // expected-error {{expression is not assignable}}
}
// radar 7628953
@@ -28,7 +28,7 @@ void foo() {
@implementation Gorf
- (void)MyView_sharedInit {
- self.size.width = 2.2; // expected-error {{expression is not assignable using property assignment syntax}}
+ self.size.width = 2.2; // expected-error {{expression is not assignable}}
}
- (NSSize)size {}
@end
diff --git a/test/SemaObjC/protocol-attribute.m b/test/SemaObjC/protocol-attribute.m
index e04a39b..52c9803 100644
--- a/test/SemaObjC/protocol-attribute.m
+++ b/test/SemaObjC/protocol-attribute.m
@@ -3,7 +3,7 @@
__attribute ((unavailable))
@protocol FwProto; // expected-note{{marked unavailable}}
-Class <FwProto> cFw = 0; // expected-warning {{'FwProto' is unavailable}}
+Class <FwProto> cFw = 0; // expected-error {{'FwProto' is unavailable}}
__attribute ((deprecated)) @protocol MyProto1
@@ -35,12 +35,12 @@ Class <MyProto1> clsP1 = 0; // expected-warning {{'MyProto1' is deprecated}}
@protocol FwProto @end // expected-note{{marked unavailable}}
-@interface MyClass2 <FwProto> // expected-warning {{'FwProto' is unavailable}}
+@interface MyClass2 <FwProto> // expected-error {{'FwProto' is unavailable}}
@end
__attribute ((unavailable)) __attribute ((deprecated)) @protocol XProto; // expected-note{{marked unavailable}}
-id <XProto> idX = 0; // expected-warning {{'XProto' is unavailable}} expected-warning {{'XProto' is deprecated}}
+id <XProto> idX = 0; // expected-error {{'XProto' is unavailable}} expected-warning {{'XProto' is deprecated}}
int main ()
{
diff --git a/test/SemaObjC/protocols.m b/test/SemaObjC/protocols.m
index 8447fe2..ca38f20 100644
--- a/test/SemaObjC/protocols.m
+++ b/test/SemaObjC/protocols.m
@@ -61,3 +61,7 @@
@protocol B < A > // expected-error{{protocol has circular dependency}}
@end
+@protocol P
+- (int)test:(int)param, ..; // expected-warning{{type specifier missing}} \
+ // expected-error{{expected ';' after method prototype}}
+@end
diff --git a/test/SemaObjC/static-ivar-ref-1.m b/test/SemaObjC/static-ivar-ref-1.m
index cd5e055..d9f99f5 100644
--- a/test/SemaObjC/static-ivar-ref-1.m
+++ b/test/SemaObjC/static-ivar-ref-1.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown -ast-print %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ast-print %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -ast-print %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ast-print %s 2>&1 | FileCheck %s
@interface current
{
@@ -14,5 +14,17 @@ current *pc;
int foo()
{
- return pc->ivar2 + (*pc).ivar + pc->ivar1;
+ return pc->ivar2 + (*pc).ivar + pc->ivar1;
}
+
+// CHECK: @interface current{
+// CHECK: int ivar;
+// CHECK: int ivar1;
+// CHECK: int ivar2;
+// CHECK: }
+// CHECK: @end
+// CHECK: current *pc;
+// CHECK: int foo() {
+// CHECK: return pc->ivar2 + (*pc).ivar + pc->ivar1;
+// CHECK: }
+
diff --git a/test/SemaObjC/synth-provisional-ivars.m b/test/SemaObjC/synth-provisional-ivars.m
new file mode 100644
index 0000000..973c771
--- /dev/null
+++ b/test/SemaObjC/synth-provisional-ivars.m
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+
+int bar;
+
+@interface I
+{
+ int _bar;
+}
+@property int PROP;
+@property int PROP1;
+@property int PROP2;
+@property int PROP3;
+@property int PROP4;
+
+@property int bar;
+@property int bar1;
+
+@end
+
+@implementation I
+- (int) Meth { return PROP; } // expected-note {{'PROP' declared here}}
+
+@dynamic PROP1;
+- (int) Meth1 { return PROP1; } // expected-error {{use of undeclared identifier 'PROP1'}}
+
+- (int) Meth2 { return PROP2; } // expected-error {{use of undeclared identifier 'PROP2'}}
+@dynamic PROP2;
+
+- (int) Meth3 { return PROP3; } // expected-error {{use of undeclared identifier 'PROP3'}}
+@synthesize PROP3=IVAR;
+
+- (int) Meth4 { return PROP4; }
+@synthesize PROP4=PROP4;
+
+- (int) Meth5 { return bar; } // expected-error {{use of undeclared identifier 'bar'}}
+@synthesize bar = _bar;
+
+- (int) Meth6 { return bar1; }
+
+@end
+
+@implementation I(CAT)
+- (int) Meth { return PROP1; } // expected-error {{use of undeclared identifier 'PROP1'}}
+@end
+
+@implementation I(r8251648)
+- (int) Meth1: (int) bar {
+ return bar; // expected-warning {{local declaration of 'bar' hides instance variable}}
+}
+@end
diff --git a/test/SemaObjC/warn-strict-selector-match.m b/test/SemaObjC/warn-strict-selector-match.m
new file mode 100644
index 0000000..8ac0ca4
--- /dev/null
+++ b/test/SemaObjC/warn-strict-selector-match.m
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -Wstrict-selector-match -fsyntax-only -verify %s
+
+@interface Foo
+-(int) method; // expected-note {{using}}
+@end
+
+@interface Bar
+-(float) method; // expected-note {{also found}}
+@end
+
+int main() { [(id)0 method]; } // expected-warning {{multiple methods named 'method' found [-Wstrict-selector-match]}}
+
+@interface Object @end
+
+@interface Class1
+- (void)setWindow:(Object *)wdw; // expected-note {{using}}
+@end
+
+@interface Class2
+- (void)setWindow:(Class1 *)window; // expected-note {{also found}}
+@end
+
+id foo(void) {
+ Object *obj = 0;
+ id obj2 = obj;
+ [obj setWindow:0]; // expected-warning {{Object' may not respond to 'setWindow:'}}
+ [obj2 setWindow:0]; // expected-warning {{multiple methods named 'setWindow:' found [-Wstrict-selector-match]}}
+ return obj;
+}
+
+@protocol MyObject
+- (id)initWithData:(Object *)data; // expected-note {{using}} \
+ // expected-note {{passing argument to parameter 'data' here}}
+@end
+
+@protocol SomeOther
+- (id)initWithData:(int)data; // expected-note {{also found}}
+@end
+
+@protocol MyCoding
+- (id)initWithData:(id<MyObject, MyCoding>)data; // expected-note {{also found}}
+@end
+
+@interface NTGridDataObject: Object <MyCoding>
+{
+ Object<MyCoding> *_data;
+}
++ (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data;
+@end
+
+@implementation NTGridDataObject
+- (id)initWithData:(id<MyObject, MyCoding>)data {
+ return data;
+}
++ (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data
+{
+ NTGridDataObject *result = [(id)0 initWithData:data]; // expected-warning {{multiple methods named 'initWithData:' found [-Wstrict-selector-match]}} \
+ expected-warning {{sending 'id<MyObject,MyCoding>' to parameter of incompatible type 'Object *'}}
+ return result;
+}
+@end
+
+@interface Base
+- (unsigned)port;
+@end
+
+@interface Derived: Base
+- (Object *)port;
++ (Protocol *)port;
+@end
+
+void foo1(void) {
+ [(Class)0 port]; // OK - gcc issues warning but there is only one Class method so no ambiguity to warn
+}
+
OpenPOWER on IntegriCloud