OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / objc-foreach-5.m
1 /* FIXME: Run this test with the GNU runtime as well.  */
2 /* { dg-do compile { target *-*-darwin* } } */
3 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
4 /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
5 /* { dg-additional-options "-framework Foundation" { target { *-*-darwin* } } } */
6
7 #include <Foundation/NSArray.h>
8 #include <Foundation/NSAutoreleasePool.h>
9
10 NSArray * createTestVictim(unsigned capacity) {
11     NSMutableArray * arr = [[NSMutableArray alloc] initWithCapacity:capacity];
12     int x = 0;
13
14     for(x = 0; x < capacity; x++) {
15         NSNumber * num = [NSNumber numberWithInteger:x];
16         [arr addObject:num];
17     }
18     
19     NSArray * immutableCopy = [arr copy];
20     [arr release];
21     
22     return immutableCopy;
23 }
24
25 void addStuffUp(NSArray * values) {
26     NSInteger accumulator = 0;
27 //    for (id item in values) {
28     id item;
29     for (item in values) {
30         accumulator += [item integerValue];
31     }
32 }
33
34 int main (int argc, char const* argv[]) {
35     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
36     NSArray * target = createTestVictim(10);
37     addStuffUp(target);
38     [pool release];
39     return 0;
40 }
41 /* { dg-final { scan-assembler "_addStuffUp:" } } */