| 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 <[email protected]>. */ |
| 5 |
/* { dg-do run } */ |
| 6 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 7 |
/* { dg-additional-options "-Wno-objc-root-class" } */ |
| 8 |
|
| 9 |
#include "../objc-obj-c++-shared/runtime.h" |
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
|
| 13 |
extern int sscanf(const char *str, const char *format, ...); |
| 14 |
extern void abort(void); |
| 15 |
#define CHECK_IF(expr) if(!(expr)) abort() |
| 16 |
|
| 17 |
enum Enum { one, two, three, four }; |
| 18 |
|
| 19 |
@interface ArrayTest |
| 20 |
- (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en; |
| 21 |
- (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3; |
| 22 |
@end |
| 23 |
|
| 24 |
@implementation ArrayTest |
| 25 |
- (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; } |
| 26 |
- (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; } |
| 27 |
@end |
| 28 |
|
| 29 |
Class cls; |
| 30 |
Method meth ; |
| 31 |
|
| 32 |
unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7; |
| 33 |
|
| 34 |
static void scan_initial(const char *pattern) { |
| 35 |
totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1; |
| 36 |
sscanf(method_getTypeEncoding(meth), pattern, &totsize, &offs0, &offs1, &offs2, &offs3, |
| 37 |
&offs4, &offs5, &offs6, &offs7); |
| 38 |
CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2); |
| 39 |
} |
| 40 |
|
| 41 |
int main(void) { |
| 42 |
cls = objc_getClass("ArrayTest"); |
| 43 |
|
| 44 |
meth = class_getInstanceMethod(cls, @selector(str:with:and:)); |
| 45 |
|
| 46 |
/* Here we have the complication that 'enum Enum' could be encoded |
| 47 |
as 'i' on __NEXT_RUNTIME_, and (most likely) as 'I' on the GNU |
| 48 |
runtime. So we get the @encode(enum Enum), then put it into the |
| 49 |
string in place of the traditional 'i'. |
| 50 |
*/ |
| 51 |
/* scan_initial("r*%u@%u:%u*%u*%u[4i]%u"); */ |
| 52 |
{ |
| 53 |
char pattern[1024]; |
| 54 |
|
| 55 |
sprintf (pattern, "r*%%u@%%u:%%u*%%u*%%u[4%s]%%u", @encode(enum Enum)); |
| 56 |
scan_initial(pattern); |
| 57 |
} |
| 58 |
|
| 59 |
CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *)); |
| 60 |
CHECK_IF(totsize == offs4 + sizeof(enum Enum *)); |
| 61 |
meth = class_getInstanceMethod(cls, @selector(meth1:with:with:)); |
| 62 |
scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u"); |
| 63 |
CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *)); |
| 64 |
CHECK_IF(totsize == offs4 + sizeof(int *)); |
| 65 |
return 0; |
| 66 |
} |