xref: /llvm-project/compiler-rt/test/BlocksRuntime/nestedimport.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 //  nestedimport.m
88c1441f8SAlexey Samsonov //  testObjects
98c1441f8SAlexey Samsonov //
108c1441f8SAlexey Samsonov //  Created by Blaine Garst on 6/24/08.
118c1441f8SAlexey Samsonov //
128c1441f8SAlexey Samsonov // pure C nothing more needed
138c1441f8SAlexey Samsonov // CONFIG
148c1441f8SAlexey Samsonov 
158c1441f8SAlexey Samsonov 
168c1441f8SAlexey Samsonov #include <stdio.h>
178c1441f8SAlexey Samsonov #include <stdlib.h>
188c1441f8SAlexey Samsonov 
198c1441f8SAlexey Samsonov 
208c1441f8SAlexey Samsonov int Global = 0;
218c1441f8SAlexey Samsonov 
228c1441f8SAlexey Samsonov void callVoidVoid(void (^closure)(void)) {
238c1441f8SAlexey Samsonov     closure();
248c1441f8SAlexey Samsonov }
258c1441f8SAlexey Samsonov 
main(int argc,char * argv[])268c1441f8SAlexey Samsonov int main(int argc, char *argv[]) {
278c1441f8SAlexey Samsonov     int i = 1;
288c1441f8SAlexey Samsonov 
298c1441f8SAlexey Samsonov     void (^vv)(void) = ^{
308c1441f8SAlexey Samsonov         if (argc > 0) {
318c1441f8SAlexey Samsonov             callVoidVoid(^{ Global = i; });
328c1441f8SAlexey Samsonov         }
338c1441f8SAlexey Samsonov     };
348c1441f8SAlexey Samsonov 
358c1441f8SAlexey Samsonov     i = 2;
368c1441f8SAlexey Samsonov     vv();
378c1441f8SAlexey Samsonov     if (Global != 1) {
388c1441f8SAlexey Samsonov         printf("%s: error, Global not set to captured value\n", argv[0]);
398c1441f8SAlexey Samsonov         exit(1);
408c1441f8SAlexey Samsonov     }
418c1441f8SAlexey Samsonov     printf("%s: success\n", argv[0]);
428c1441f8SAlexey Samsonov     return 0;
438c1441f8SAlexey Samsonov }
44