brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 473bdef Raw
74 lines · c
1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5 6// CONFIG open rdar://64164747// was  rdar://58479768// was  rdar://6348320 9 10#include <stdio.h>11#include <Block.h>12 13int verbose = 0;14 15int main(int argc, char* argv[]) {16	17        if (argc > 1) verbose = 1;18        19	__block void (^recursive_local_block)(int);20		21	if (verbose) printf("recursive_local_block is a local recursive block\n");22	recursive_local_block = ^(int i) {23		if (verbose) printf("%d\n", i);24		if (i > 0) {25			recursive_local_block(i - 1);26		}27    };28 29	if (verbose) printf("recursive_local_block's address is %p, running it:\n", (void*)recursive_local_block);30	recursive_local_block(5);31 32	if (verbose) printf("Creating other_local_block: a local block that calls recursive_local_block\n");33 34	void (^other_local_block)(int) = ^(int i) {35		if (verbose) printf("other_local_block running\n");36		recursive_local_block(i);37    };38 39	if (verbose) printf("other_local_block's address is %p, running it:\n", (void*)other_local_block);40		41	other_local_block(5);42	43#if __APPLE_CC__ >= 562744	if (verbose) printf("Creating other_copied_block: a Block_copy of a block that will call recursive_local_block\n");45 46	void (^other_copied_block)(int) = Block_copy(^(int i) {47		if (verbose) printf("other_copied_block running\n");48		recursive_local_block(i);49    });50		51	if (verbose) printf("other_copied_block's address is %p, running it:\n", (void*)other_copied_block);52	53	other_copied_block(5);54#endif55 56	__block void (^recursive_copy_block)(int);57 58	if (verbose) printf("Creating recursive_copy_block: a Block_copy of a block that will call recursive_copy_block recursively\n");59 60	recursive_copy_block = Block_copy(^(int i) {61		if (verbose) printf("%d\n", i);62		if (i > 0) {63			recursive_copy_block(i - 1);64		}65    });66		67	if (verbose) printf("recursive_copy_block's address is %p, running it:\n", (void*)recursive_copy_block);68 69	recursive_copy_block(5);70        71        printf("%s: Success\n", argv[0]);72	return 0;73}74