1 /* Check if array arguments of ObjC methods are decayed to pointer types
3 (1) The _encodings_ for the array arguments should remain to be '[4i]' and
4 such, since this has been the case since at least gcc 3.3.
5 (2) However, when building the static C functions out of ObjC method signatures,
6 we need to decay the arrays into pointers (as C does).
7 (3) If array size is not known (e.g., 'int a[]'), then the type shall be
8 encoded as a pointer. */
10 /* Contributed by Alexander Malmberg <alexander@malmberg.org> */
12 #include "../objc-obj-c++-shared/Object1.h"
13 #include "../objc-obj-c++-shared/next-mapping.h"
16 #define CHECK_IF(expr) if(!(expr)) abort()
18 #ifdef __NEXT_RUNTIME__
21 #include <objc/objc-api.h>
22 #define METHOD Method_t
23 #define method_get_types(M) (M)->method_types
26 @interface Test : Object
28 -(void) test2: (int [5])a with: (int [])b;
29 -(id) test3: (Test **)b; /* { dg-message "previous declaration of .\\-\\(id\\)test3:\\(Test \\*\\*\\)b." } */
33 -(void) test2: (int [5])a with: (int [])b
37 -(void) test3: (Test [3][4])b { /* { dg-warning "conflicting types for .\\-\\(void\\)test3:\\(Test \\\[3\\\]\\\[4\\\]\\)b." } */
41 int bb[6] = { 0, 1, 2, 3, 4, 5 };
46 int offs1, offs2, offs3, offs4, offs5, offs6;
48 int main(int argc, char **argv)
50 Class testClass = objc_get_class("Test");
54 CHECK_IF (bb[3] == 3);
55 [*c test2: b with: bb + 4];
56 CHECK_IF (bb[3] == 4);
58 [*c test2: bb with: bb + 5];
59 CHECK_IF (bb[3] == 5);
61 meth = class_get_instance_method(testClass, @selector(test2:with:));
62 offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
63 sscanf(method_get_types(meth), "v%d@%d:%d[%di]%d^i%d", &offs1, &offs2, &offs3,
64 &offs4, &offs5, &offs6);
65 CHECK_IF (!offs2 && offs4 == 5 && offs3 > 0);
66 CHECK_IF (offs5 == 2 * offs3 && offs6 == 3 * offs3 && offs1 == 4 * offs3);
68 meth = class_get_instance_method(testClass, @selector(test3:));
69 offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
70 sscanf(method_get_types(meth), "v%d@%d:%d[%d[%d{Test=#f}]]%d", &offs1, &offs2, &offs3,
71 &offs4, &offs5, &offs6);
72 CHECK_IF (!offs2 && offs4 == 3 && offs5 == 4 && offs3 > 0);
73 CHECK_IF (offs6 == 2 * offs3 && offs1 == 3 * offs3);