OSDN Git Service

Add NIOS2 support. Code from SourceyG++.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / type-size-2.m
1 /* Make sure that array arguments to methods are given the size of pointers.  */
2 /* As in the case of ivars, arrays without size (e.g., 'int []') are
3    encoded as pointers.  */
4 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
5 /* { dg-do run } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7 #include "../objc-obj-c++-shared/Object1.h"
8 #include "../objc-obj-c++-shared/next-mapping.h"
9 //#include <objc/objc.h>
10 #ifdef __NEXT_RUNTIME__
11 #include <objc/objc-runtime.h>
12 #define METHOD Method
13 #else
14 #include <objc/objc-api.h>
15 #define METHOD Method_t
16 #define method_get_types(M) (M)->method_types
17 #endif
18
19 extern int sscanf(const char *str, const char *format, ...);
20 extern void abort(void);
21 #define CHECK_IF(expr) if(!(expr)) abort()
22
23 enum Enum { one, two, three, four };
24
25 @interface ArrayTest
26 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en;
27 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3;
28 @end
29
30 @implementation ArrayTest
31 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; }
32 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; }
33 @end
34
35 Class cls;
36 METHOD meth ;
37
38 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
39
40 static void scan_initial(const char *pattern) {
41   totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
42   sscanf(method_get_types(meth), pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
43       &offs4, &offs5, &offs6, &offs7);
44   CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2);
45 }
46
47 int main(void) {
48   cls = objc_get_class("ArrayTest");
49
50   meth = class_get_instance_method(cls, @selector(str:with:and:));
51   scan_initial("r*%u@%u:%u*%u*%u[4i]%u");
52   CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *));
53   CHECK_IF(totsize == offs4 + sizeof(enum Enum *));
54   meth = class_get_instance_method(cls, @selector(meth1:with:with:));
55   scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u");
56   CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *));
57   CHECK_IF(totsize == offs4 + sizeof(int *));                                           
58   return 0;
59 }
60
61 #include "../objc-obj-c++-shared/Object1-implementation.h"