d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
[official-gcc.git] / gcc / testsuite / objc.dg / pr103639.m
blobc46e0d42c178d1f119cb193d3a2c44b49e327066
1 /* PR objc/103639 */
2 /* { dg-do run } */
3 /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
4 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* { dg-additional-sources "../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */
6 /* { dg-additional-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
7 /* { dg-additional-options "-Wno-objc-root-class" } */
9 #import "../objc-obj-c++-shared/TestsuiteObject.m"
10 #ifndef __NEXT_RUNTIME__
11 #include <objc/NXConstStr.h>
12 #else
13 #include "../objc-obj-c++-shared/nsconstantstring-class.h"
14 #endif
16 extern int printf (const char *, ...);
17 #include <stdlib.h>
19 /* A mini-array implementation that can be used to test fast
20     enumeration.  You create the array with some objects; you can
21     mutate the array, and you can fast-enumerate it.
22  */
23 @interface MyArray : TestsuiteObject
25   unsigned int length;
26   id *objects;
27   unsigned long mutated;
29 - (id) initWithLength: (unsigned int)l  objects: (id *)o;
30 - (void) mutate;
31 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state
32                                      objects:(id *)stackbuf 
33                                        count:(unsigned long)len;
34 @end
36 @implementation MyArray : TestsuiteObject
37 - (id) initWithLength: (unsigned int)l
38               objects: (id *)o
40   length = l;
41   objects = o;
42   mutated = 0;
43   return self;
45 - (void) mutate
47   mutated = 1;
49 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState*)state 
50                                      objects: (id*)stackbuf
51                                        count: (unsigned long)len
53   unsigned long i, batch_size;
55   /* We keep how many objects we served in the state->state counter.  So the next batch
56      will contain up to length - state->state objects.  */
57   batch_size = length - state->state;
59   /* Make obvious adjustments.  */
60   if (batch_size < 0)
61     batch_size = 0;
63   if (batch_size > len)
64     batch_size = len;
66   /* Copy the objects.  */
67   for (i = 0; i < batch_size; i++)
68     stackbuf[i] = objects[i];
70   state->state += batch_size;
71   state->itemsPtr = stackbuf;
72   state->mutationsPtr = &mutated;
74   return batch_size;
76 @end
78 int check = 0;
80 int
81 main()
83   id *objects = malloc (sizeof (id) * 2);
84   objects[0] = @"a";
85   objects[1] = @"b";
87   MyArray *array = [[MyArray alloc] initWithLength: 2 objects: objects];
89   int someVar = 0;
90   for (id object in array) {
91     switch (someVar) {
92       case 0:
93         break;
94     }
95     ++check;
96   }
98   if (check != 2)
99     abort ();
100   return 0;