summaryrefslogtreecommitdiff
path: root/lib/BlocksRuntime/tests/objectassign.c
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-02-14 08:38:30 +0000
committerAlexey Samsonov <samsonov@google.com>2014-02-14 08:38:30 +0000
commitdb75ada3a3169f4bc4b9f9f04b42a5075d264743 (patch)
tree93631b13cadee6e4a9ac6e452ed06534ee5102fc /lib/BlocksRuntime/tests/objectassign.c
parent5c8699e6a78818c59ece2c60f77ad630b1b6eb86 (diff)
downloadcompiler-rt-db75ada3a3169f4bc4b9f9f04b42a5075d264743.tar.gz
Move BlocksRuntime to lib/ directory
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201390 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/BlocksRuntime/tests/objectassign.c')
-rw-r--r--lib/BlocksRuntime/tests/objectassign.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/BlocksRuntime/tests/objectassign.c b/lib/BlocksRuntime/tests/objectassign.c
new file mode 100644
index 000000000..1c4f48414
--- /dev/null
+++ b/lib/BlocksRuntime/tests/objectassign.c
@@ -0,0 +1,76 @@
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+/*
+ * objectassign.c
+ * testObjects
+ *
+ * Created by Blaine Garst on 10/28/08.
+ *
+ * This just tests that the compiler is issuing the proper helper routines
+ * CONFIG C rdar://6175959
+ */
+
+
+#include <stdio.h>
+#include <Block_private.h>
+
+
+int AssignCalled = 0;
+int DisposeCalled = 0;
+
+// local copy instead of libSystem.B.dylib copy
+void _Block_object_assign(void *destAddr, const void *object, const int isWeak) {
+ //printf("_Block_object_assign(%p, %p, %d) called\n", destAddr, object, isWeak);
+ AssignCalled = 1;
+}
+
+void _Block_object_dispose(const void *object, const int isWeak) {
+ //printf("_Block_object_dispose(%p, %d) called\n", object, isWeak);
+ DisposeCalled = 1;
+}
+
+struct MyStruct {
+ long isa;
+ long field;
+};
+
+typedef struct MyStruct *__attribute__((NSObject)) MyStruct_t;
+
+int main(int argc, char *argv[]) {
+ if (__APPLE_CC__ < 5627) {
+ printf("need compiler version %d, have %d\n", 5627, __APPLE_CC__);
+ return 0;
+ }
+ // create a block
+ struct MyStruct X;
+ MyStruct_t xp = (MyStruct_t)&X;
+ xp->field = 10;
+ void (^myBlock)(void) = ^{ printf("field is %ld\n", xp->field); };
+ // should be a copy helper generated with a calls to above routines
+ // Lets find out!
+ struct Block_layout *bl = (struct Block_layout *)(void *)myBlock;
+ if ((bl->flags & BLOCK_HAS_COPY_DISPOSE) != BLOCK_HAS_COPY_DISPOSE) {
+ printf("no copy dispose!!!!\n");
+ return 1;
+ }
+ // call helper routines directly. These will, in turn, we hope, call the stubs above
+ long destBuffer[256];
+ //printf("destbuffer is at %p, block at %p\n", destBuffer, (void *)bl);
+ //printf("dump is %s\n", _Block_dump(myBlock));
+ bl->descriptor->copy(destBuffer, bl);
+ bl->descriptor->dispose(bl);
+ if (AssignCalled == 0) {
+ printf("did not call assign helper!\n");
+ return 1;
+ }
+ if (DisposeCalled == 0) {
+ printf("did not call dispose helper\n");
+ return 1;
+ }
+ printf("%s: Success!\n", argv[0]);
+ return 0;
+}