xref: /llvm-project/compiler-rt/test/BlocksRuntime/byrefcopyint.c (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
18c1441f8SAlexey Samsonov //
2*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
4*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
58c1441f8SAlexey Samsonov 
68c1441f8SAlexey Samsonov /*
78c1441f8SAlexey Samsonov  *  byrefcopyint.c
88c1441f8SAlexey Samsonov  *  testObjects
98c1441f8SAlexey Samsonov  *
108c1441f8SAlexey Samsonov  *  Created by Blaine Garst on 12/1/08.
118c1441f8SAlexey Samsonov  *
128c1441f8SAlexey Samsonov  */
138c1441f8SAlexey Samsonov 
148c1441f8SAlexey Samsonov //
158c1441f8SAlexey Samsonov //  byrefcopyid.m
168c1441f8SAlexey Samsonov //  testObjects
178c1441f8SAlexey Samsonov //
188c1441f8SAlexey Samsonov //  Created by Blaine Garst on 5/13/08.
198c1441f8SAlexey Samsonov //
208c1441f8SAlexey Samsonov 
218c1441f8SAlexey Samsonov // Tests copying of blocks with byref ints
228c1441f8SAlexey Samsonov // CONFIG rdar://6414583 -C99
238c1441f8SAlexey Samsonov 
248c1441f8SAlexey Samsonov #include <stdio.h>
258c1441f8SAlexey Samsonov #include <string.h>
268c1441f8SAlexey Samsonov #include <Block.h>
278c1441f8SAlexey Samsonov #include <Block_private.h>
288c1441f8SAlexey Samsonov 
298c1441f8SAlexey Samsonov 
308c1441f8SAlexey Samsonov 
318c1441f8SAlexey Samsonov 
328c1441f8SAlexey Samsonov typedef void (^voidVoid)(void);
338c1441f8SAlexey Samsonov 
348c1441f8SAlexey Samsonov voidVoid dummy;
358c1441f8SAlexey Samsonov 
callVoidVoid(voidVoid closure)368c1441f8SAlexey Samsonov void callVoidVoid(voidVoid closure) {
378c1441f8SAlexey Samsonov     closure();
388c1441f8SAlexey Samsonov }
398c1441f8SAlexey Samsonov 
408c1441f8SAlexey Samsonov 
testRoutine(const char * whoami)418c1441f8SAlexey Samsonov voidVoid testRoutine(const char *whoami) {
428c1441f8SAlexey Samsonov     __block int  dumbo = strlen(whoami);
438c1441f8SAlexey Samsonov     dummy = ^{
448c1441f8SAlexey Samsonov         //printf("incring dumbo from %d\n", dumbo);
458c1441f8SAlexey Samsonov         ++dumbo;
468c1441f8SAlexey Samsonov     };
478c1441f8SAlexey Samsonov 
488c1441f8SAlexey Samsonov 
498c1441f8SAlexey Samsonov     voidVoid copy = Block_copy(dummy);
508c1441f8SAlexey Samsonov 
518c1441f8SAlexey Samsonov 
528c1441f8SAlexey Samsonov     return copy;
538c1441f8SAlexey Samsonov }
548c1441f8SAlexey Samsonov 
main(int argc,char * argv[])558c1441f8SAlexey Samsonov int main(int argc, char *argv[]) {
568c1441f8SAlexey Samsonov     voidVoid array[100];
578c1441f8SAlexey Samsonov     for (int i = 0; i <  100; ++i) {
588c1441f8SAlexey Samsonov         array[i] = testRoutine(argv[0]);
598c1441f8SAlexey Samsonov         array[i]();
608c1441f8SAlexey Samsonov     }
618c1441f8SAlexey Samsonov     for (int i = 0; i <  100; ++i) {
628c1441f8SAlexey Samsonov         Block_release(array[i]);
638c1441f8SAlexey Samsonov     }
648c1441f8SAlexey Samsonov 
658c1441f8SAlexey Samsonov 
668c1441f8SAlexey Samsonov     printf("%s: success\n", argv[0]);
678c1441f8SAlexey Samsonov     return 0;
688c1441f8SAlexey Samsonov }
69