xref: /aosp_15_r20/external/compiler-rt/test/BlocksRuntime/byrefcopyint.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //
2*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
3*7c3d14c8STreehugger Robot //
4*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
5*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot /*
8*7c3d14c8STreehugger Robot  *  byrefcopyint.c
9*7c3d14c8STreehugger Robot  *  testObjects
10*7c3d14c8STreehugger Robot  *
11*7c3d14c8STreehugger Robot  *  Created by Blaine Garst on 12/1/08.
12*7c3d14c8STreehugger Robot  *
13*7c3d14c8STreehugger Robot  */
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot //
16*7c3d14c8STreehugger Robot //  byrefcopyid.m
17*7c3d14c8STreehugger Robot //  testObjects
18*7c3d14c8STreehugger Robot //
19*7c3d14c8STreehugger Robot //  Created by Blaine Garst on 5/13/08.
20*7c3d14c8STreehugger Robot //
21*7c3d14c8STreehugger Robot 
22*7c3d14c8STreehugger Robot // Tests copying of blocks with byref ints
23*7c3d14c8STreehugger Robot // CONFIG rdar://6414583 -C99
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot #include <stdio.h>
26*7c3d14c8STreehugger Robot #include <string.h>
27*7c3d14c8STreehugger Robot #include <Block.h>
28*7c3d14c8STreehugger Robot #include <Block_private.h>
29*7c3d14c8STreehugger Robot 
30*7c3d14c8STreehugger Robot 
31*7c3d14c8STreehugger Robot 
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot typedef void (^voidVoid)(void);
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot voidVoid dummy;
36*7c3d14c8STreehugger Robot 
callVoidVoid(voidVoid closure)37*7c3d14c8STreehugger Robot void callVoidVoid(voidVoid closure) {
38*7c3d14c8STreehugger Robot     closure();
39*7c3d14c8STreehugger Robot }
40*7c3d14c8STreehugger Robot 
41*7c3d14c8STreehugger Robot 
testRoutine(const char * whoami)42*7c3d14c8STreehugger Robot voidVoid testRoutine(const char *whoami) {
43*7c3d14c8STreehugger Robot     __block int  dumbo = strlen(whoami);
44*7c3d14c8STreehugger Robot     dummy = ^{
45*7c3d14c8STreehugger Robot         //printf("incring dumbo from %d\n", dumbo);
46*7c3d14c8STreehugger Robot         ++dumbo;
47*7c3d14c8STreehugger Robot     };
48*7c3d14c8STreehugger Robot 
49*7c3d14c8STreehugger Robot 
50*7c3d14c8STreehugger Robot     voidVoid copy = Block_copy(dummy);
51*7c3d14c8STreehugger Robot 
52*7c3d14c8STreehugger Robot 
53*7c3d14c8STreehugger Robot     return copy;
54*7c3d14c8STreehugger Robot }
55*7c3d14c8STreehugger Robot 
main(int argc,char * argv[])56*7c3d14c8STreehugger Robot int main(int argc, char *argv[]) {
57*7c3d14c8STreehugger Robot     voidVoid array[100];
58*7c3d14c8STreehugger Robot     for (int i = 0; i <  100; ++i) {
59*7c3d14c8STreehugger Robot         array[i] = testRoutine(argv[0]);
60*7c3d14c8STreehugger Robot         array[i]();
61*7c3d14c8STreehugger Robot     }
62*7c3d14c8STreehugger Robot     for (int i = 0; i <  100; ++i) {
63*7c3d14c8STreehugger Robot         Block_release(array[i]);
64*7c3d14c8STreehugger Robot     }
65*7c3d14c8STreehugger Robot 
66*7c3d14c8STreehugger Robot 
67*7c3d14c8STreehugger Robot     printf("%s: success\n", argv[0]);
68*7c3d14c8STreehugger Robot     return 0;
69*7c3d14c8STreehugger Robot }
70