1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6// -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil; -*-
7// CONFIG
8
9#import <stdio.h>
10#import <stdlib.h>
11#import <string.h>
12
13typedef struct {
14 unsigned long ps[30];
15 int qs[30];
16} BobTheStruct;
17
18int main (int argc, const char * argv[]) {
19 __block BobTheStruct fiddly;
20 BobTheStruct copy;
21
22 void (^incrementFiddly)() = ^{
23 int i;
24 for(i=0; i<30; i++) {
25 fiddly.ps[i]++;
26 fiddly.qs[i]++;
27 }
28 };
29
30 memset(&fiddly, 0xA5, sizeof(fiddly));
31 memset(s: &copy, c: 0x2A, n: sizeof(copy));
32
33 int i;
34 for(i=0; i<30; i++) {
35 fiddly.ps[i] = i * i * i;
36 fiddly.qs[i] = -i * i * i;
37 }
38
39 copy = fiddly;
40 incrementFiddly();
41
42 if ( &copy == &fiddly ) {
43 printf(format: "%s: struct wasn't copied.", argv[0]);
44 exit(status: 1);
45 }
46 for(i=0; i<30; i++) {
47 //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]);
48 if ( (fiddly.ps[i] != copy.ps[i] + 1) || (fiddly.qs[i] != copy.qs[i] + 1) ) {
49 printf(format: "%s: struct contents were not incremented.", argv[0]);
50 exit(status: 1);
51 }
52 }
53
54 printf(format: "%s: success\n", argv[0]);
55 return 0;
56}
57

source code of compiler-rt/test/BlocksRuntime/byrefstruct.c