summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC
diff options
context:
space:
mode:
authorJames Y Knight <jyknight@google.com>2019-10-17 15:18:59 +0000
committerJames Y Knight <jyknight@google.com>2019-10-17 15:18:59 +0000
commit1c982af0599781bdb049f898a2d512656c807485 (patch)
tree568c90b2662a2ad2c91f52fc4838fd1607abb95c /clang/test/SemaObjC
parent92e498d58cf47f4c1266cedba981a0c2cee171d0 (diff)
downloadbcm5719-llvm-1c982af0599781bdb049f898a2d512656c807485.tar.gz
bcm5719-llvm-1c982af0599781bdb049f898a2d512656c807485.zip
[ObjC] Add some additional test cases around pointer conversions.
This is especially important for Objective-C++, which is entirely missing this testing at the moment. This annotates with "FIXME" the cases which I change in the next patch -- I primarily wanted to document the current state of things so that the effect of the code change is made clear. Differential Revision: https://reviews.llvm.org/D67982 llvm-svn: 375124
Diffstat (limited to 'clang/test/SemaObjC')
-rw-r--r--clang/test/SemaObjC/class-method-self.m2
-rw-r--r--clang/test/SemaObjC/comptypes-1.m81
-rw-r--r--clang/test/SemaObjC/comptypes-7.m7
3 files changed, 61 insertions, 29 deletions
diff --git a/clang/test/SemaObjC/class-method-self.m b/clang/test/SemaObjC/class-method-self.m
index b1e37bfe58f..821160c8841 100644
--- a/clang/test/SemaObjC/class-method-self.m
+++ b/clang/test/SemaObjC/class-method-self.m
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
-typedef struct objc_class *Class;
@interface XX
- (void)addObserver:(XX*)o; // expected-note 2{{passing argument to parameter 'o' here}}
@@ -23,4 +22,3 @@ static XX *obj;
[obj addObserver:whatever]; // expected-warning {{incompatible pointer types sending 'Class' to parameter of type 'XX *'}}
}
@end
-
diff --git a/clang/test/SemaObjC/comptypes-1.m b/clang/test/SemaObjC/comptypes-1.m
index 997ef19c1b4..9b62f974927 100644
--- a/clang/test/SemaObjC/comptypes-1.m
+++ b/clang/test/SemaObjC/comptypes-1.m
@@ -1,12 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
#define nil (void *)0;
-#define Nil (void *)0;
extern void foo();
@protocol MyProtocol
- (void) foo;
++ (void) bar;
@end
@interface MyClass
@@ -22,7 +22,8 @@ int main()
id<MyProtocol> obj_p = nil;
MyClass *obj_c = nil;
MyOtherClass *obj_cp = nil;
- Class obj_C = Nil;
+ Class obj_C = nil;
+ Class<MyProtocol> obj_CP = nil;
/* Assigning to an 'id' variable should never
generate a warning. */
@@ -30,12 +31,15 @@ int main()
obj = obj_c; /* Ok */
obj = obj_cp; /* Ok */
obj = obj_C; /* Ok */
-
+ obj = obj_CP; /* Ok */
+
/* Assigning to a 'MyClass *' variable should always generate a
warning, unless done from an 'id'. */
obj_c = obj; /* Ok */
- obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyOtherClass *'}}
+ obj_c = obj_p; // expected-warning {{assigning to 'MyClass *' from incompatible type 'id<MyProtocol>'}}
+ obj_c = obj_cp; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyOtherClass *'}}
obj_c = obj_C; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'Class'}}
+ obj_c = obj_CP; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'Class<MyProtocol>'}}
/* Assigning to an 'id<MyProtocol>' variable should generate a
warning if done from a 'MyClass *' (which doesn't implement
@@ -45,6 +49,7 @@ int main()
obj_p = obj_c; // expected-warning {{assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}}
obj_p = obj_cp; /* Ok */
obj_p = obj_C; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'Class'}}
+ obj_p = obj_CP; // FIXME -- should warn {{assigning to 'id<MyProtocol>' from incompatible type 'Class<MyProtocol>'}}
/* Assigning to a 'MyOtherClass *' variable should always generate
a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
@@ -53,37 +58,67 @@ int main()
obj_cp = obj_c; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'MyClass *'}}
obj_cp = obj_p; /* Ok */
obj_cp = obj_C; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'Class'}}
+ obj_cp = obj_CP; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'Class<MyProtocol>'}}
+
+ obj_C = obj; // Ok
+ obj_C = obj_p; // expected-warning {{incompatible pointer types assigning to 'Class' from 'id<MyProtocol>'}}
+ obj_C = obj_c; // expected-warning {{incompatible pointer types assigning to 'Class' from 'MyClass *'}}
+ obj_C = obj_cp; // expected-warning {{incompatible pointer types assigning to 'Class' from 'MyOtherClass *'}}
+ obj_C = obj_CP; // Ok
+
+ obj_CP = obj; // Ok
+ obj_CP = obj_p; // expected-warning {{assigning to 'Class<MyProtocol>' from incompatible type 'id<MyProtocol>'}}
+ obj_CP = obj_c; // expected-warning {{incompatible pointer types assigning to 'Class<MyProtocol>' from 'MyClass *}}
+ obj_CP = obj_cp; // expected-warning {{incompatible pointer types assigning to 'Class<MyProtocol>' from 'MyOtherClass *'}}
+ obj_CP = obj_C; // Ok
/* Any comparison involving an 'id' must be without warnings. */
- if (obj == obj_p) foo() ; /* Ok */ /*Bogus warning here in 2.95.4*/
- if (obj_p == obj) foo() ; /* Ok */
- if (obj == obj_c) foo() ; /* Ok */
- if (obj_c == obj) foo() ; /* Ok */
- if (obj == obj_cp) foo() ; /* Ok */
- if (obj_cp == obj) foo() ; /* Ok */
- if (obj == obj_C) foo() ; /* Ok */
- if (obj_C == obj) foo() ; /* Ok */
+ if (obj == obj_p) foo(); /* Ok */ /*Bogus warning here in 2.95.4*/
+ if (obj_p == obj) foo(); /* Ok */
+ if (obj == obj_c) foo(); /* Ok */
+ if (obj_c == obj) foo(); /* Ok */
+ if (obj == obj_cp) foo(); /* Ok */
+ if (obj_cp == obj) foo(); /* Ok */
+ if (obj == obj_C) foo(); /* Ok */
+ if (obj_C == obj) foo(); /* Ok */
+ if (obj == obj_CP) foo(); /* Ok */
+ if (obj_CP == obj) foo(); /* Ok */
/* Any comparison between 'MyClass *' and anything which is not an 'id'
must generate a warning. */
- if (obj_p == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
+ if (obj_c == obj_p) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'id<MyProtocol>')}}
+ if (obj_p == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
+
+ if (obj_c == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
+ if (obj_cp == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
- if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
- if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
+ if (obj_c == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
+ if (obj_C == obj_c) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyClass *')}}
- if (obj_c == obj_C) foo() ;
- if (obj_C == obj_c) foo() ;
+ if (obj_c == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class<MyProtocol>')}}
+ if (obj_CP == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyClass *')}}
/* Any comparison between 'MyOtherClass *' (which implements
MyProtocol) and an 'id' implementing MyProtocol are Ok. */
- if (obj_cp == obj_p) foo() ; /* Ok */
- if (obj_p == obj_cp) foo() ; /* Ok */
+ if (obj_p == obj_cp) foo(); /* Ok */
+ if (obj_cp == obj_p) foo(); /* Ok */
+
+ if (obj_p == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class')}}
+ if (obj_C == obj_p) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'id<MyProtocol>')}}
+
+ if (obj_p == obj_CP) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class<MyProtocol>')}}
+ if (obj_CP == obj_p) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class<MyProtocol>' and 'id<MyProtocol>')}}
+
+ /* Comparisons between MyOtherClass * and Class types is a warning */
+ if (obj_cp == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}}
+ if (obj_C == obj_cp) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}}
+ if (obj_cp == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class<MyProtocol>')}}
+ if (obj_CP == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyOtherClass *')}}
- if (obj_p == obj_C) foo() ;
- if (obj_C == obj_p) foo() ;
- if (obj_cp == obj_C) foo() ;
- if (obj_C == obj_cp) foo() ;
+ /* Comparisons between a Class and a Class<MyProtocol> are ok */
+ if (obj_C == obj_CP) foo(); /* Ok */
+ if (obj_CP == obj_C) foo(); /* Ok */
return 0;
}
diff --git a/clang/test/SemaObjC/comptypes-7.m b/clang/test/SemaObjC/comptypes-7.m
index dde504b8606..4623cfd6922 100644
--- a/clang/test/SemaObjC/comptypes-7.m
+++ b/clang/test/SemaObjC/comptypes-7.m
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
#define nil (void *)0;
-#define Nil (void *)0;
extern void foo();
@@ -17,7 +16,7 @@ int main()
id obj = nil;
id <MyProtocol> obj_p = nil;
MyClass *obj_c = nil;
- Class obj_C = Nil;
+ Class obj_C = nil;
int i = 0;
int *j = nil;
@@ -66,8 +65,8 @@ int main()
if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
- Class bar1 = Nil;
- Class <MyProtocol> bar = Nil;
+ Class bar1 = nil;
+ Class <MyProtocol> bar = nil;
bar = bar1;
bar1 = bar;
OpenPOWER on IntegriCloud