llvm-project
69 строк · 1.7 Кб
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-exception
5
6// CONFIG
7
8
9#include <stdio.h>10#include <stdbool.h>11#include <stdlib.h>12#include <Block.h>13
14int
15main(int argc, char *argv[])16{
17__block int var = 0;18void (^b)(void) = ^{ var++; };19
20//sanity(b);21b();22printf("%s: success!\n", argv[0]);23return 0;24}
25
26
27#if 128/* replicated internal data structures: BEWARE, MAY CHANGE!!! */
29
30enum {31BLOCK_REFCOUNT_MASK = (0xffff),32BLOCK_NEEDS_FREE = (1 << 24),33BLOCK_HAS_COPY_DISPOSE = (1 << 25),34BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed35BLOCK_IS_GC = (1 << 27),36BLOCK_IS_GLOBAL = (1 << 28),37};38
39struct byref_id {40struct byref_id *forwarding;41int flags;//refcount;42int size;43void (*byref_keep)(struct byref_id *dst, struct byref_id *src);44void (*byref_destroy)(struct byref_id *);45int var;46};47struct Block_basic2 {48void *isa;49int Block_flags; // int32_t50int Block_size; // XXX should be packed into Block_flags51void (*Block_invoke)(void *);52void (*Block_copy)(void *dst, void *src);53void (*Block_dispose)(void *);54struct byref_id *ref;55};56
57void sanity(void *arg) {58struct Block_basic2 *bb = (struct Block_basic2 *)arg;59if ( ! (bb->Block_flags & BLOCK_HAS_COPY_DISPOSE)) {60printf("missing copy/dispose helpers for byref data\n");61exit(1);62}63struct byref_id *ref = bb->ref;64if (ref->forwarding != ref) {65printf("forwarding pointer should be %p but is %p\n", ref, ref->forwarding);66exit(1);67}68}
69#endif70
71
72
73