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// testfilerunner CONFIG
7
8#import <stdio.h>
9#import <Block.h>
10
11int global;
12
13void (^gblock)(int) = ^(int x){ global = x; };
14
15int main(int argc, char *argv[]) {
16 gblock(1);
17 if (global != 1) {
18 printf(format: "%s: *** did not set global to 1\n", argv[0]);
19 return 1;
20 }
21 void (^gblockcopy)(int) = Block_copy(gblock);
22 if (gblockcopy != gblock) {
23 printf(format: "global copy %p not a no-op %p\n", (void *)gblockcopy, (void *)gblock);
24 return 1;
25 }
26 Block_release(gblockcopy);
27 gblock(3);
28 if (global != 3) {
29 printf(format: "%s: *** did not set global to 3\n", argv[0]);
30 return 1;
31 }
32 gblockcopy = Block_copy(gblock);
33 gblockcopy(5);
34 if (global != 5) {
35 printf(format: "%s: *** did not set global to 5\n", argv[0]);
36 return 1;
37 }
38 printf(format: "%s: Success!\n", argv[0]);
39 return 0;
40}
41
42

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