1 //
2 //                     The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 
7 //  -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil;  -*-
8 // CONFIG
9 
10 #import <stdio.h>
11 #import <stdlib.h>
12 #import <string.h>
13 
14 typedef struct {
15     unsigned long ps[30];
16     int qs[30];
17 } BobTheStruct;
18 
main(int argc,const char * argv[])19 int main (int argc, const char * argv[]) {
20     __block BobTheStruct fiddly;
21     BobTheStruct copy;
22 
23     void (^incrementFiddly)() = ^{
24         int i;
25         for(i=0; i<30; i++) {
26             fiddly.ps[i]++;
27             fiddly.qs[i]++;
28         }
29     };
30 
31     memset(&fiddly, 0xA5, sizeof(fiddly));
32     memset(&copy, 0x2A, sizeof(copy));
33 
34     int i;
35     for(i=0; i<30; i++) {
36         fiddly.ps[i] = i * i * i;
37         fiddly.qs[i] = -i * i * i;
38     }
39 
40     copy = fiddly;
41     incrementFiddly();
42 
43     if ( &copy == &fiddly ) {
44         printf("%s: struct wasn't copied.", argv[0]);
45         exit(1);
46     }
47     for(i=0; i<30; i++) {
48         //printf("[%d]: fiddly.ps: %lu, copy.ps: %lu, fiddly.qs: %d, copy.qs: %d\n", i, fiddly.ps[i], copy.ps[i], fiddly.qs[i], copy.qs[i]);
49         if ( (fiddly.ps[i] != copy.ps[i] + 1) || (fiddly.qs[i] != copy.qs[i] + 1) ) {
50             printf("%s: struct contents were not incremented.", argv[0]);
51             exit(1);
52         }
53     }
54 
55     printf("%s: success\n", argv[0]);
56     return 0;
57 }
58