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// CONFIG rdar://6255170
7
8#include <stdio.h>
9#include <stdbool.h>
10#include <stdlib.h>
11#include <Block.h>
12#include <Block_private.h>
13#include <assert.h>
14
15
16int
17main(int argc, char *argv[])
18{
19 __block int var = 0;
20 int shouldbe = 0;
21 void (^b)(void) = ^{ var++; /*printf("var is at %p with value %d\n", &var, var);*/ };
22 __typeof(b) _b;
23 //printf("before copy...\n");
24 b(); ++shouldbe;
25 size_t i;
26
27 for (i = 0; i < 10; i++) {
28 _b = Block_copy(b); // make a new copy each time
29 assert(_b);
30 ++shouldbe;
31 _b(); // should still update the stack
32 Block_release(_b);
33 }
34
35 //printf("after...\n");
36 b(); ++shouldbe;
37
38 if (var != shouldbe) {
39 printf(format: "Hmm, var is %d but should be %d\n", var, shouldbe);
40 return 1;
41 }
42 printf(format: "%s: Success!!\n", argv[0]);
43
44 return 0;
45}
46

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