tsan: fix deadlock detector lit test output
[blocksruntime.git] / test / BlocksRuntime / objectassign.c
blob1c4f4841419e0f510cdac8a5b6ff9d8b4a35545d
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 /*
8 * objectassign.c
9 * testObjects
11 * Created by Blaine Garst on 10/28/08.
13 * This just tests that the compiler is issuing the proper helper routines
14 * CONFIG C rdar://6175959
18 #include <stdio.h>
19 #include <Block_private.h>
22 int AssignCalled = 0;
23 int DisposeCalled = 0;
25 // local copy instead of libSystem.B.dylib copy
26 void _Block_object_assign(void *destAddr, const void *object, const int isWeak) {
27 //printf("_Block_object_assign(%p, %p, %d) called\n", destAddr, object, isWeak);
28 AssignCalled = 1;
31 void _Block_object_dispose(const void *object, const int isWeak) {
32 //printf("_Block_object_dispose(%p, %d) called\n", object, isWeak);
33 DisposeCalled = 1;
36 struct MyStruct {
37 long isa;
38 long field;
41 typedef struct MyStruct *__attribute__((NSObject)) MyStruct_t;
43 int main(int argc, char *argv[]) {
44 if (__APPLE_CC__ < 5627) {
45 printf("need compiler version %d, have %d\n", 5627, __APPLE_CC__);
46 return 0;
48 // create a block
49 struct MyStruct X;
50 MyStruct_t xp = (MyStruct_t)&X;
51 xp->field = 10;
52 void (^myBlock)(void) = ^{ printf("field is %ld\n", xp->field); };
53 // should be a copy helper generated with a calls to above routines
54 // Lets find out!
55 struct Block_layout *bl = (struct Block_layout *)(void *)myBlock;
56 if ((bl->flags & BLOCK_HAS_COPY_DISPOSE) != BLOCK_HAS_COPY_DISPOSE) {
57 printf("no copy dispose!!!!\n");
58 return 1;
60 // call helper routines directly. These will, in turn, we hope, call the stubs above
61 long destBuffer[256];
62 //printf("destbuffer is at %p, block at %p\n", destBuffer, (void *)bl);
63 //printf("dump is %s\n", _Block_dump(myBlock));
64 bl->descriptor->copy(destBuffer, bl);
65 bl->descriptor->dispose(bl);
66 if (AssignCalled == 0) {
67 printf("did not call assign helper!\n");
68 return 1;
70 if (DisposeCalled == 0) {
71 printf("did not call dispose helper\n");
72 return 1;
74 printf("%s: Success!\n", argv[0]);
75 return 0;