xref: /llvm-project/compiler-rt/test/BlocksRuntime/dispatch_call_Block_with_release.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 #include <stdio.h>
78c1441f8SAlexey Samsonov #include <Block.h>
88c1441f8SAlexey Samsonov 
98c1441f8SAlexey Samsonov // CONFIG
108c1441f8SAlexey Samsonov 
callsomething(const char * format,int argument)118c1441f8SAlexey Samsonov void callsomething(const char *format, int argument) {
128c1441f8SAlexey Samsonov }
138c1441f8SAlexey Samsonov 
148c1441f8SAlexey Samsonov void
dispatch_call_Block_with_release2(void * block)158c1441f8SAlexey Samsonov dispatch_call_Block_with_release2(void *block)
168c1441f8SAlexey Samsonov {
178c1441f8SAlexey Samsonov         void (^b)(void) = (void (^)(void))block;
188c1441f8SAlexey Samsonov         b();
198c1441f8SAlexey Samsonov         Block_release(b);
208c1441f8SAlexey Samsonov }
218c1441f8SAlexey Samsonov 
main(int argc,char * argv[])228c1441f8SAlexey Samsonov int main(int argc, char *argv[]) {
238c1441f8SAlexey Samsonov      void (^b1)(void) = ^{ callsomething("argc is %d\n", argc); };
248c1441f8SAlexey Samsonov      void (^b2)(void) = ^{ callsomething("hellow world\n", 0); }; // global block now
258c1441f8SAlexey Samsonov 
268c1441f8SAlexey Samsonov      dispatch_call_Block_with_release2(Block_copy(b1));
278c1441f8SAlexey Samsonov      dispatch_call_Block_with_release2(Block_copy(b2));
288c1441f8SAlexey Samsonov      printf("%s: Success\n", argv[0]);
298c1441f8SAlexey Samsonov      return 0;
308c1441f8SAlexey Samsonov }
31