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
10 * Created by Blaine Garst on 10/28/08.
12 * This just tests that the compiler is issuing the proper helper routines
13 * CONFIG C rdar://6175959
18 #include <Block_private.h>
22 int DisposeCalled
= 0;
24 // local copy instead of libSystem.B.dylib copy
25 void _Block_object_assign(void *destAddr
, const void *object
, const int isWeak
) {
26 //printf("_Block_object_assign(%p, %p, %d) called\n", destAddr, object, isWeak);
30 void _Block_object_dispose(const void *object
, const int isWeak
) {
31 //printf("_Block_object_dispose(%p, %d) called\n", object, isWeak);
40 typedef struct MyStruct
*__attribute__((NSObject
)) MyStruct_t
;
42 int main(int argc
, char *argv
[]) {
43 if (__APPLE_CC__
< 5627) {
44 printf("need compiler version %d, have %d\n", 5627, __APPLE_CC__
);
49 MyStruct_t xp
= (MyStruct_t
)&X
;
51 void (^myBlock
)(void) = ^{ printf("field is %ld\n", xp
->field
); };
52 // should be a copy helper generated with a calls to above routines
54 struct Block_layout
*bl
= (struct Block_layout
*)(void *)myBlock
;
55 if ((bl
->flags
& BLOCK_HAS_COPY_DISPOSE
) != BLOCK_HAS_COPY_DISPOSE
) {
56 printf("no copy dispose!!!!\n");
59 // call helper routines directly. These will, in turn, we hope, call the stubs above
61 //printf("destbuffer is at %p, block at %p\n", destBuffer, (void *)bl);
62 //printf("dump is %s\n", _Block_dump(myBlock));
63 bl
->descriptor
->copy(destBuffer
, bl
);
64 bl
->descriptor
->dispose(bl
);
65 if (AssignCalled
== 0) {
66 printf("did not call assign helper!\n");
69 if (DisposeCalled
== 0) {
70 printf("did not call dispose helper\n");
73 printf("%s: Success!\n", argv
[0]);