OSDN Git Service

In gcc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / proto-qual-1.m
1 /* Check that protocol qualifiers are compiled and encoded properly.  */
2 /* Author: Ziemowit Laski <zlaski@apple.com>  */
3
4 /* { dg-do run } */
5 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
6
7 #include <objc/Protocol.h>
8 #ifndef __NEXT_RUNTIME__
9 #include <objc/objc-api.h>
10 #endif
11 #include "../objc-obj-c++-shared/next-mapping.h"
12
13 /* The encoded parameter sizes will be rounded up to match pointer alignment.  */
14 #define ROUND(s,a) (a * ((s + a - 1) / a))
15 #define aligned_sizeof(T) ROUND(sizeof(T),__alignof(void *))
16
17 extern int sscanf(const char *str, const char *format, ...);
18 extern void abort(void);
19 #define CHECK_IF(expr) if(!(expr)) abort()
20
21 @protocol Retain
22 + (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2;
23 - (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2;
24 @end
25
26 @interface Foo <Retain>
27 + (oneway void)retainArgument:(out bycopy id)arg with:(in signed char **)arg2;
28 @end
29
30 @implementation Foo
31 + (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2 { }
32 - (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2 { return nil; }
33 @end
34
35 Protocol *proto;
36 struct objc_method_description *meth;
37 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
38 struct objc_method_description meth_object;
39 #endif
40 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
41
42 static void scan_initial(const char *pattern) {
43   totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
44   sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
45       &offs4, &offs5, &offs6, &offs7);
46   CHECK_IF(!offs0 && offs1 == aligned_sizeof(id) && offs2 == offs1 + aligned_sizeof(SEL) && totsize >= offs2);
47 }
48
49 int main(void) {
50   proto = @protocol(Retain);
51 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
52   meth_object = protocol_getMethodDescription (proto,
53                   @selector(address:with:), YES, YES);
54   meth = &meth_object;
55 #else
56   meth = [proto descriptionForInstanceMethod: @selector(address:with:)];
57 #endif
58   scan_initial("O@%u@%u:%uNR@%uo^^S%u");
59   CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(unsigned));
60 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
61   meth_object = protocol_getMethodDescription (proto,
62                   @selector(retainArgument:with:), YES, NO);
63   meth = &meth_object;
64 #else
65   meth = [proto descriptionForClassMethod: @selector(retainArgument:with:)];
66 #endif
67   scan_initial("Vv%u@%u:%uOo@%un^*%u");
68   CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(char **));
69   return 0;
70 }