Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / objc.dg / call-super-2.m
blob836cad92126066f1749f2eca2c48e18d172e94d2
1 /* Check if casting 'self' or 'super' affects message lookup in the correct way.  */
2 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
3 /* { dg-do compile } */
5 #include "../objc-obj-c++-shared/TestsuiteObject.h"
6 /* NOTE: we are relying on the built-in type for objc_getClass being used
7    rather than the one that might come from including <objc/runtime.h>.  */
8 #include <stddef.h>
10 /* FIXME: This is temporary.  At the moment, the compiler, when
11    compiling for the GNU runtime and doing method checks, only
12    recognizes objc_get_class(), and not objc_getClass().  So
13    temporarily force objc_get_class() to be used.  */
14 #ifndef __NEXT_RUNTIME__
15 # define objc_getClass(C) objc_get_class(C)
16 #endif
18 /* FIXME: casting of super is not permitted by clang, so that many of the
19    tests here are testing non-portable code.  */
21 @protocol Func
22 + (int) class_func0;
23 - (int) instance_func0;
24 @end
26 @interface Derived: TestsuiteObject
27 + (int) class_func1;
28 + (int) class_func2;
29 + (int) class_func3;
30 + (int) class_func4;
31 + (int) class_func5;
32 + (int) class_func6;
33 + (int) class_func7;
34 - (int) instance_func1;
35 - (int) instance_func2;
36 - (int) instance_func3;
37 - (int) instance_func4;
38 - (int) instance_func5;
39 - (int) instance_func6;
40 - (int) instance_func7;
41 @end
43 @interface Derived (Categ)
44 + (int) categ_class_func1;
45 + (int) categ_class_func2;
46 - (int) categ_instance_func1;
47 - (int) categ_instance_func2;
48 @end
50 @implementation Derived
51 + (int) class_func1
53    int i = (size_t)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
54    return i + (size_t)[super class_func0];   /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
56 + (int) class_func2
58    int i = [(id <Func>)self class_func0];  /* { dg-warning ".\\-class_func0. not found in protocol" } */
59    i += [(id <Func>)super class_func0];    /* { dg-warning ".\\-class_func0. not found in protocol" } */
60    i += [(Class <Func>)self class_func0];
61    return i + [(Class <Func>)super class_func0];
63 + (int) class_func3
65    return [(TestsuiteObject <Func> *)super class_func0];
67 + (int) class_func4
69    return [(Derived <Func> *)super class_func0];
70 }   
71 + (int) class_func5
73    int i = (size_t)[Derived class_func0];    /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
74    return i + (size_t)[TestsuiteObject class_func0];  /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
76 + (int) class_func6
78    return (size_t)[objc_getClass("TestsuiteObject") class_func1];  /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
80 + (int) class_func7
82    return [objc_getClass("Derived") class_func1];
84 - (int) instance_func1
86    int i = (size_t)[self instance_func0];     /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
87    return i + (size_t)[super instance_func0]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
89 - (int) instance_func2
91    return [(id <Func>)super instance_func0];
93 - (int) instance_func3
95    return [(TestsuiteObject <Func> *)super instance_func0];
97 - (int) instance_func4
99    return [(Derived <Func> *)super instance_func0];
100 }   
101 - (int) instance_func5
103    int i = (size_t)[Derived instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+instance_func1." } */
104    return i + (size_t)[TestsuiteObject instance_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+instance_func1." } */
106 - (int) instance_func6
108    return (size_t)[objc_getClass("TestsuiteObject") class_func1]; /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func1." } */
110 - (int) instance_func7
112    return [objc_getClass("Derived") class_func1];
114 @end
116 @implementation Derived (Categ)
117 + (int) categ_class_func1
119    int i = (size_t)[self class_func0];       /* { dg-warning ".Derived. may not respond to .\\+class_func0." } */
120    i += [self class_func1];
121    i += [self categ_class_func2];
122    i += (size_t)[self categ_instance_func1]; /* { dg-warning ".Derived. may not respond to .\\+categ_instance_func1." } */
123    return i + (size_t)[super class_func0];   /* { dg-warning ".TestsuiteObject. may not respond to .\\+class_func0." } */
125 + (int) categ_class_func2
127    int i = [(id <Func>)self class_func0];  /* { dg-warning ".\\-class_func0. not found in protocol" } */
128    i += [(id <Func>)super class_func0];    /* { dg-warning ".\\-class_func0. not found in protocol" } */
129    i += [(Class <Func>)self class_func0];
130    return i + [(Class <Func>)super class_func0];
132 - (int) categ_instance_func1
134    int i = (size_t)[self instance_func0];    /* { dg-warning ".Derived. may not respond to .\\-instance_func0." } */
135    i += [(Derived <Func> *)self categ_instance_func2];
136    i += (size_t)[(TestsuiteObject <Func> *)self categ_instance_func2]; /* { dg-warning ".TestsuiteObject. may not respond to .\\-categ_instance_func2." } */
137    /* { dg-warning ".\\-categ_instance_func2. not found in protocol" "" { target *-*-* } .-1 } */
138    i += (size_t)[(id <Func>)self categ_instance_func2];  /* { dg-warning ".\\-categ_instance_func2. not found in protocol" } */
139    i += [(id)self categ_instance_func2];
140    return i + (size_t)[super instance_func0];   /* { dg-warning ".TestsuiteObject. may not respond to .\\-instance_func0." } */
142 - (int) categ_instance_func2
144    return [(id <Func>)super instance_func0];
146 @end
148 /* { dg-warning "messages without a matching method signature will be assumed to return .id. and accept .\.\.\.. as arguments" "" { target *-*-* } 0 } */