tsan: fix deadlock detector lit test output
[blocksruntime.git] / test / BlocksRuntime / byrefsanity.c
blobdfa16b0ddd6a9e7c826e35dece8f211b1dac74b6
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
7 // CONFIG
10 #include <stdio.h>
11 #include <stdbool.h>
12 #include <stdlib.h>
13 #include <Block.h>
15 int
16 main(int argc, char *argv[])
18 __block int var = 0;
19 void (^b)(void) = ^{ var++; };
21 //sanity(b);
22 b();
23 printf("%s: success!\n", argv[0]);
24 return 0;
28 #if 1
29 /* replicated internal data structures: BEWARE, MAY CHANGE!!! */
31 enum {
32 BLOCK_REFCOUNT_MASK = (0xffff),
33 BLOCK_NEEDS_FREE = (1 << 24),
34 BLOCK_HAS_COPY_DISPOSE = (1 << 25),
35 BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed
36 BLOCK_IS_GC = (1 << 27),
37 BLOCK_IS_GLOBAL = (1 << 28),
40 struct byref_id {
41 struct byref_id *forwarding;
42 int flags;//refcount;
43 int size;
44 void (*byref_keep)(struct byref_id *dst, struct byref_id *src);
45 void (*byref_destroy)(struct byref_id *);
46 int var;
48 struct Block_basic2 {
49 void *isa;
50 int Block_flags; // int32_t
51 int Block_size; // XXX should be packed into Block_flags
52 void (*Block_invoke)(void *);
53 void (*Block_copy)(void *dst, void *src);
54 void (*Block_dispose)(void *);
55 struct byref_id *ref;
58 void sanity(void *arg) {
59 struct Block_basic2 *bb = (struct Block_basic2 *)arg;
60 if ( ! (bb->Block_flags & BLOCK_HAS_COPY_DISPOSE)) {
61 printf("missing copy/dispose helpers for byref data\n");
62 exit(1);
64 struct byref_id *ref = bb->ref;
65 if (ref->forwarding != ref) {
66 printf("forwarding pointer should be %p but is %p\n", ref, ref->forwarding);
67 exit(1);
70 #endif