diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m')
-rw-r--r-- | gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m b/gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m new file mode 100644 index 000000000..d02a8af21 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/objc.dg/type-size-2.m @@ -0,0 +1,65 @@ +/* Make sure that array arguments to methods are given the size of pointers. */ +/* As in the case of ivars, arrays without size (e.g., 'int []') are + encoded as pointers. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ +/* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ + +#include "../objc-obj-c++-shared/runtime.h" +#include <stdio.h> +#include <stdlib.h> + +extern int sscanf(const char *str, const char *format, ...); +extern void abort(void); +#define CHECK_IF(expr) if(!(expr)) abort() + +enum Enum { one, two, three, four }; + +@interface ArrayTest +- (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en; +- (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3; +@end + +@implementation ArrayTest +- (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; } +- (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; } +@end + +Class cls; +Method meth ; + +unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7; + +static void scan_initial(const char *pattern) { + totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1; + sscanf(method_getTypeEncoding(meth), pattern, &totsize, &offs0, &offs1, &offs2, &offs3, + &offs4, &offs5, &offs6, &offs7); + CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2); +} + +int main(void) { + cls = objc_getClass("ArrayTest"); + + meth = class_getInstanceMethod(cls, @selector(str:with:and:)); + + /* Here we have the complication that 'enum Enum' could be encoded + as 'i' on __NEXT_RUNTIME_, and (most likely) as 'I' on the GNU + runtime. So we get the @encode(enum Enum), then put it into the + string in place of the traditional 'i'. + */ + /* scan_initial("r*%u@%u:%u*%u*%u[4i]%u"); */ + { + char pattern[1024]; + + sprintf (pattern, "r*%%u@%%u:%%u*%%u*%%u[4%s]%%u", @encode(enum Enum)); + scan_initial(pattern); + } + + CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *)); + CHECK_IF(totsize == offs4 + sizeof(enum Enum *)); + meth = class_getInstanceMethod(cls, @selector(meth1:with:with:)); + scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u"); + CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *)); + CHECK_IF(totsize == offs4 + sizeof(int *)); + return 0; +} |