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>. */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8 #include "../objc-obj-c++-shared/runtime.h"
12 extern int sscanf(const char *str, const char *format, ...);
13 extern void abort(void);
14 #define CHECK_IF(expr) if(!(expr)) abort()
16 enum Enum { one, two, three, four };
19 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en;
20 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3;
23 @implementation ArrayTest
24 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; }
25 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; }
31 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
33 static void scan_initial(const char *pattern) {
34 totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
35 sscanf(method_getTypeEncoding(meth), pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
36 &offs4, &offs5, &offs6, &offs7);
37 CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2);
41 cls = objc_getClass("ArrayTest");
43 meth = class_getInstanceMethod(cls, @selector(str:with:and:));
45 /* Here we have the complication that 'enum Enum' could be encoded
46 as 'i' on __NEXT_RUNTIME_, and (most likely) as 'I' on the GNU
47 runtime. So we get the @encode(enum Enum), then put it into the
48 string in place of the traditional 'i'.
50 /* scan_initial("r*%u@%u:%u*%u*%u[4i]%u"); */
54 sprintf (pattern, "r*%%u@%%u:%%u*%%u*%%u[4%s]%%u", @encode(enum Enum));
55 scan_initial(pattern);
58 CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *));
59 CHECK_IF(totsize == offs4 + sizeof(enum Enum *));
60 meth = class_getInstanceMethod(cls, @selector(meth1:with:with:));
61 scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u");
62 CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *));
63 CHECK_IF(totsize == offs4 + sizeof(int *));