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" } { "" } } */
7 /* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */
9 #include "../objc-obj-c++-shared/Object1.h"
10 #include "../objc-obj-c++-shared/next-mapping.h"
13 #ifdef __NEXT_RUNTIME__
14 #include <objc/objc-runtime.h>
17 #include <objc/objc-api.h>
18 #define METHOD Method_t
19 #define method_get_types(M) (M)->method_types
22 extern int sscanf(const char *str, const char *format, ...);
23 extern void abort(void);
24 #define CHECK_IF(expr) if(!(expr)) abort()
26 enum Enum { one, two, three, four };
29 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en;
30 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3;
33 @implementation ArrayTest
34 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; }
35 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; }
41 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
43 static void scan_initial(const char *pattern) {
44 totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
45 sscanf(method_get_types(meth), pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
46 &offs4, &offs5, &offs6, &offs7);
47 CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2);
51 cls = objc_get_class("ArrayTest");
53 meth = class_get_instance_method(cls, @selector(str:with:and:));
55 /* Here we have the complication that 'enum Enum' could be encoded
56 as 'i' on __NEXT_RUNTIME_, and (most likely) as 'I' on the GNU
57 runtime. So we get the @encode(enum Enum), then put it into the
58 string in place of the traditional 'i'.
60 /* scan_initial("r*%u@%u:%u*%u*%u[4i]%u"); */
64 sprintf (pattern, "r*%%u@%%u:%%u*%%u*%%u[4%s]%%u", @encode(enum Enum));
65 scan_initial(pattern);
68 CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *));
69 CHECK_IF(totsize == offs4 + sizeof(enum Enum *));
70 meth = class_get_instance_method(cls, @selector(meth1:with:with:));
71 scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u");
72 CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *));
73 CHECK_IF(totsize == offs4 + sizeof(int *));