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/Object.h>
15 #define CHECK_IF(expr) if(!(expr)) abort()
17 #ifdef __NEXT_RUNTIME__
19 #define OBJC_GETCLASS objc_getClass
20 #define CLASS_GETINSTANCEMETHOD class_getInstanceMethod
22 #include <objc/objc-api.h>
23 #define METHOD Method_t
24 #define OBJC_GETCLASS objc_get_class
25 #define CLASS_GETINSTANCEMETHOD class_get_instance_method
28 @interface Test : Object
30 -(void) test2: (int [5])a with: (int [])b;
31 -(id) test3: (Test **)b; /* { dg-warning "previous declaration of .\\-\\(id\\)test3:\\(Test \\*\\*\\)b." } */
35 -(void) test2: (int [5])a with: (int [])b
39 -(void) test3: (Test [3][4])b { /* { dg-warning "conflicting types for .\\-\\(void\\)test3:\\(Test \\\[3\\\]\\\[4\\\]\\)b." } */
43 int bb[6] = { 0, 1, 2, 3, 4, 5 };
48 int offs1, offs2, offs3, offs4, offs5, offs6;
50 int main(int argc, char **argv)
52 Class testClass = OBJC_GETCLASS("Test");
56 CHECK_IF (bb[3] == 3);
57 [*c test2: b with: bb + 4];
58 CHECK_IF (bb[3] == 4);
60 [*c test2: bb with: bb + 5];
61 CHECK_IF (bb[3] == 5);
63 meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test2:with:));
64 offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
65 sscanf(meth->method_types, "v%d@%d:%d[%di]%d^i%d", &offs1, &offs2, &offs3,
66 &offs4, &offs5, &offs6);
67 CHECK_IF (!offs2 && offs4 == 5 && offs3 > 0);
68 CHECK_IF (offs5 == 2 * offs3 && offs6 == 3 * offs3 && offs1 == 4 * offs3);
70 meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test3:));
71 offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1;
72 sscanf(meth->method_types, "v%d@%d:%d[%d[%d{Test=#f}]]%d", &offs1, &offs2, &offs3,
73 &offs4, &offs5, &offs6);
74 CHECK_IF (!offs2 && offs4 == 3 && offs5 == 4 && offs3 > 0);
75 CHECK_IF (offs6 == 2 * offs3 && offs1 == 3 * offs3);