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