[llvm-commits] [llvm-gcc-4.2] r55726 - /llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/
Bill Wendling
isanbard at gmail.com
Wed Sep 3 13:48:24 PDT 2008
Author: void
Date: Wed Sep 3 15:48:23 2008
New Revision: 55726
URL: http://llvm.org/viewvc/llvm-project?rev=55726&view=rev
Log:
Add a slew of blocks tests from Apple's GCC r150332.
Added:
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5862465.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5988451.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5992047.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6084601.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6116917.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-args.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-as-object.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcglobal.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcivar.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcstrongcast.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgcivar.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-bad-def.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-storageclass.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-attribute.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-block.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-c99-off-default.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-call.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-codegen-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-complicated-type.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-conditional-test.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-const.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-continuation.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-copy-destroy.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-dup-invoke_impl.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-encoding.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-enum.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-error-global-byref.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-do.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-goto.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-nested-while.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-switch.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-while.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-block.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-implicit-byref.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-block.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-global-block.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-implicit-byref.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivar.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivarlayout.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal-exp.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-stack.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-static-test.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-misc.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-3.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global-copied-var-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-2.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-3.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nonnull-test.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-assignment.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type-match.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-1.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-exp.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readonly-diag.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgc.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgcivar.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-return.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-stabs.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-sync-compare-and-swap.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-parameter.c
llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-warn.c
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5862465.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5862465.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5862465.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5862465.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,11 @@
+/* APPLE LOCAL file 5862465 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+void enumerateObjectsWithOptions(unsigned int x, void (^block)(char *obj, unsigned int idx, signed char *stop))
+{
+ signed char stop = (signed char)0;
+ char *item;
+ unsigned int idx = 10;
+ for ( ; idx > 0 ; idx--)
+ block(item, idx, &stop);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5988451.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5988451.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5988451.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5988451.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,49 @@
+/* APPLE LOCAL file radar 5988451 */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fblocks" { target *-*-darwin* } } */
+/* { dg-do compile } */
+
+#import <Cocoa/Cocoa.h>
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_item_s *dispatch_item_t;
+
+typedef void (^dispatch_block_t)(dispatch_item_t item);
+
+void dispatch_call(dispatch_queue_t queue,
+ dispatch_block_t work,
+ dispatch_block_t completion,
+ void* context,
+ dispatch_item_t *item);
+
+void dispatch_apply_wait(dispatch_block_t work,
+ unsigned iterations,
+ void *context);
+
+
+
+ at interface TestController : NSObject {
+
+}
+
+-(IBAction) test:(id)sender;
+
+ at end
+
+ at implementation TestController
+
+-(IBAction)test:(id)sender
+{
+ dispatch_queue_t queue;
+
+ dispatch_call(queue,
+ ^(dispatch_item_t item) {
+ dispatch_apply_wait(^(dispatch_item_t item) {
+ [NSValue valueWithPointer:self];
+ },
+ 10,NULL);
+ },
+ ^(dispatch_item_t item) {NSLog(@"test");},
+ NULL, NULL);
+}
+
+
+ at end
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5992047.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5992047.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5992047.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-5992047.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,22 @@
+/* APPLE LOCAL file radar 5992047 */
+/* Check that with a previous declaration of _Block_destroy, test case
+ compiles with no error or ICE. */
+/* { dg-options "-fblocks" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+#define Block_destroy(xxx) _Block_destroy((const void *)(xxx))
+void _Block_destroy(const void *aBlock);
+
+typedef struct dispatch_item_s *dispatch_item_t;
+typedef void (^completion_block_t)(void);
+
+int main()
+{
+ completion_block_t X;
+
+ completion_block_t (^block)(dispatch_item_t) = ^(dispatch_item_t item) {
+ return X;
+ };
+
+ block(0);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6084601.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6084601.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6084601.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6084601.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,11 @@
+/* APPLE LOCAL file radar 6084601 */
+/* block are OK with -std=c99 when objective-c programs are involved. */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -std=c99 -Werror" { target *-*-darwin* } } */
+
+typedef int (^test_block_t)();
+
+int main(int argc, char **argv) {
+ test_block_t tb = ^(){ return 1; };
+
+ return tb();
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6116917.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6116917.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6116917.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-6116917.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,64 @@
+/* APPLE LOCAL file radar 6116917 */
+/* { dg-options "-mmacosx-version-min=10.6 -ObjC -Os -Wall -Wextra" { target *-*-darwin* } } */
+/* { dg-do run } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "-m64" } { "" } } */
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+//#include <Block_private.h>
+
+struct Block_basic {
+ void *isa;
+ int Block_flags; // int32_t
+ int Block_size; // XXX should be packed into Block_flags
+ void (*Block_invoke)(void *);
+ void (*Block_copy)(void *dst, void *src);
+ void (*Block_dispose)(void *);
+ //long params[0]; // generic space for const & byref hidden params, return value, variable on needs of course
+};
+
+
+void
+func(void (^b)(void))
+{
+ b();
+}
+
+void
+func2(void (^b)(void))
+{
+ b();
+}
+
+extern char **environ;
+
+int
+main(int argc __attribute__((unused)), char *argv[])
+{
+ struct Block_basic *bb;
+ long bbi_addr, bb_addr;
+
+ void (^stage1)(void) = ^{
+ void (^stage2)(void) = ^{
+ /* trick the compiler into slirping argc/argv into this Block */
+ if (environ == argv) {
+ fprintf(stdout, "You won the lottery! argv == environ\n");
+ }
+ };
+
+ func2(stage2);
+ };
+
+ bb = (void *)stage1;
+
+ bbi_addr = (long)bb->Block_invoke;
+ bb_addr = (long)bb;
+
+ if (labs(bbi_addr - bb_addr) > (64 * 1024)) {
+ func(stage1);
+ exit(EXIT_SUCCESS);
+ } else {
+ fprintf(stderr, "Blocks generated code on the stack! Block_copy() is not safe!\n");
+ exit(EXIT_FAILURE);
+ }
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-args.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-args.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-args.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-args.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,26 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void take(void*);
+
+void test() {
+ take(^(int x){});
+ take(^(int x, int y){});
+ take(^(int x, int y){});
+ take(^(int x, int x){}); /* { dg-error "redefinition of parameter" } */
+ /* { dg-error "previous definition" "" { target *-*-* } 11 } */
+
+
+ take(^(int x) { return x+1; });
+
+ int (^CP)(int) = ^(int x) { return x*x; };
+ take(CP);
+
+ int arg;
+ ^{return 1;}();
+ ^{return 2;}(arg); /* { dg-error "too many arguments to block call" } */
+ ^(void){return 3;}(1); /* { dg-error "too many arguments to block call" } */
+ ^(){return 4;}(arg); /* C style (...), ok. */
+ ^(int x, ...){return 5;}(arg, arg); /* Explicit varargs, ok. */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-as-object.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-as-object.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-as-object.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-as-object.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,24 @@
+/* APPLE LOCAL file radar 5809099 */
+/* compile-only test to test that we can cast back and forth a block pointer
+ type to an 'id' type and sending a message to an object of block pointer type.
+*/
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC" { target *-*-darwin* } } */
+#import <Foundation/Foundation.h>
+
+void bar() { }
+
+void foo() {
+ id object = [[NSObject new] init];
+ void (^x)(void) = ^{ bar(); };
+ void *y = (void *)x;
+ x = (void (^)(void))y;
+ /* Test for type-cast of an 'id' type to a block pointer. */
+ x = (void (^)(void))[object result];
+
+ /* Test for cat of a block pointer to an 'id'. */
+ object = (id)x;
+
+ /* Test for sending a message to a block pointer. */
+ [x result];
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcglobal.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcglobal.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcglobal.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcglobal.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,35 @@
+/* APPLE LOCAL file radar 5832193 */
+/* assigning a Block into a global should elicit a global write-barrier under GC */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc" { target *-*-darwin* } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+
+id objc_assign_global(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_ivar(id val, id dest, long offset) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_strongCast(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+
+void (^GlobalVoidVoid)(void);
+
+
+int main(char *argc, char *argv[]) {
+ int i = 0;
+ // assigning a Block into a global should elicit a global write-barrier under GC
+ GlobalVoidVoid = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ return GlobalInt - 1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcivar.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcivar.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcivar.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcivar.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,54 @@
+/* APPLE LOCAL file radar 5832193 */
+/* assigning a Block into an ivar should elicit a write-barrier under GC */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#ifdef objc_assign_ivar
+#define __objc_assign_ivar objc_assign_ivar
+#endif
+#include <Foundation/Foundation.h>
+
+#undef objc_assign_ivar
+
+void * _NSConcreteStackBlock;
+int GlobalInt = 0;
+
+id objc_assign_global(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_ivar_Fast(id val, id dest, ptrdiff_t offset) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_ivar(id val, id dest, ptrdiff_t offset) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_strongCast(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+ at interface TestObject : NSObject {
+ at public
+ void (^ivarBlock)(void);
+ id x;
+}
+ at end
+
+ at implementation TestObject
+ at end
+
+
+int main(char *argc, char *argv[]) {
+ int i = 0;
+ TestObject *to = [[TestObject alloc] init];
+ // assigning a Block into an ivar should elicit a write-barrier under GC
+ to->ivarBlock = ^ { | i | ++i; }; // fails to gen write-barrier /* { dg-warning "has been deprecated in blocks" } */
+ //to->x = to; // gens write-barrier
+ return GlobalInt - 1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcstrongcast.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcstrongcast.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcstrongcast.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assigngcstrongcast.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,42 @@
+/* APPLE LOCAL file radar 5832193 */
+/* assigning a Block into an struct slot should elicit a write-barrier under GC */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#ifdef objc_assign_ivar
+#define __objc_assign_ivar objc_assign_ivar
+#endif
+#include <Foundation/Foundation.h>
+
+#undef objc_assign_ivar
+
+void * _NSConcreteStackBlock;
+int GlobalInt = 0;
+
+id objc_assign_global(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_ivar(id val, id dest, ptrdiff_t offset) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+id objc_assign_strongCast(id val, id *dest) {
+ GlobalInt = 1;
+ return (id)0;
+}
+
+typedef struct {
+ void (^ivarBlock)(void);
+} StructWithBlock_t;
+
+
+int main(char *argc, char *argv[]) {
+ StructWithBlock_t *swbp = (StructWithBlock_t *)malloc(sizeof(StructWithBlock_t*));
+ int i = 10;
+ // assigning a Block into an struct slot should elicit a write-barrier under GC
+ swbp->ivarBlock = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ return GlobalInt - 1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,39 @@
+/* APPLE LOCAL file radar 5882266 */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+int GlobalInt2 = 0;
+
+id objc_assign_weak(id value, id *location) {
+ GlobalInt = 1;
+ *location = value;
+ return value;
+}
+
+id objc_read_weak(id *location) {
+ GlobalInt2 = 1;
+ return *location;
+}
+
+//void (^GlobalVoidVoid)(void);
+
+int* (^__weak Henry)(void);
+
+int main(char *argc, char *argv[]) {
+ // an object should not be retained within a stack Block
+ int i = 0;
+ void (^local)(void);
+ Henry = ^ { | i | ++i; return &i; }; /* { dg-warning "has been deprecated in blocks" } */
+ if (GlobalInt == 1) {
+ printf("%s: success\n", argv[0]);
+ exit(0);
+ }
+ else {
+ printf("%s: problem with weak write-barrier assignment of stack block\n", argv[0]);
+ }
+ exit(1);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgc.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,39 @@
+/* APPLE LOCAL file radar 5882266 */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+int GlobalInt2 = 0;
+
+id objc_assign_weak(id value, id *location) {
+ GlobalInt = 1;
+ *location = value;
+ return value;
+}
+
+id objc_read_weak(id *location) {
+ GlobalInt2 = 1;
+ return *location;
+}
+
+//void (^GlobalVoidVoid)(void);
+
+void (^__weak Henry)(void);
+
+int main(char *argc, char *argv[]) {
+ // an object should not be retained within a stack Block
+ int i = 0;
+ void (^local)(void);
+ Henry = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ if (GlobalInt == 1) {
+ printf("%s: success\n", argv[0]);
+ exit(0);
+ }
+ else {
+ printf("%s: problem with weak write-barrier assignment of stack block\n", argv[0]);
+ }
+ exit(1);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgcivar.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgcivar.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgcivar.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-assignweakgcivar.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,48 @@
+/* APPLE LOCAL file radar 5882266 */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+int GlobalInt2 = 0;
+
+id objc_assign_weak(id value, id *location) {
+ GlobalInt = 1;
+ *location = value;
+ return value;
+}
+
+id objc_read_weak(id *location) {
+ GlobalInt2 = 1;
+ return *location;
+}
+
+ at interface Foo : NSObject {
+ at public
+ void (^__weak ivar)(void);
+}
+ at end
+ at implementation Foo
+ at end
+
+//void (^GlobalVoidVoid)(void);
+
+void (^__weak Henry)(void);
+
+int main(char *argc, char *argv[]) {
+ // an object should not be retained within a stack Block
+ int i = 0;
+ void (^local)(void);
+ Foo *foo = [[Foo alloc] init];
+ foo->ivar = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ if (GlobalInt == 1) {
+ printf("%s: success\n", argv[0]);
+ exit(0);
+ }
+ else {
+ printf("%s: problem with weak write-barrier assignment of ivar\n", argv[0]);
+ }
+ exit(1);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-bad-def.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-bad-def.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-bad-def.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-bad-def.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,12 @@
+/* APPLE LOCAL file radar 5985368 */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+int main(void)
+{
+ void (^b)(void) { }; /* { dg-error "bad definition of a block" } */
+ /* { dg-error "expected" "" { target *-*-* } 7 } */
+
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,22 @@
+/* APPLE LOCAL file radar 5831920 */
+#import <Foundation/Foundation.h>
+/* Test a property with block type. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC" { target *-*-darwin* } } */
+
+#include <stdio.h>
+
+void * _NSConcreteStackBlock;
+
+ at interface TestObject {
+
+}
+ at property(copy, readonly) int (^getIntCopy)(void);
+ at property(retain, readonly) int (^getIntRetain)(void);
+ at end
+
+
+
+int main(char *argc, char *argv[]) {
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-property-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,45 @@
+/* APPLE LOCAL file radar 5831920 */
+#import <Foundation/Foundation.h>
+/* Test a property with block type. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -framework Foundation" { target *-*-darwin* } } */
+
+void * _NSConcreteStackBlock;
+ at interface TestObject : NSObject {
+
+int (^getIntCopy)(void);
+
+int (^getIntRetain)(void);
+
+}
+ at property int (^getIntCopy)(void);
+ at property int (^getIntRetain)(void);
+ at end
+
+ at implementation TestObject
+ at synthesize getIntCopy;
+ at synthesize getIntRetain;
+
+ at end
+
+int DoBlock (int (^getIntCopy)(void))
+{
+ return getIntCopy();
+}
+
+
+
+int main(char *argc, char *argv[]) {
+ int count;
+ int val = 0;
+ TestObject *to = [[TestObject alloc] init];
+ to.getIntRetain = ^ { | val| printf("\n Hello(%d)\n", val); return ++val; }; /* { dg-warning "has been deprecated in blocks" } */
+ to.getIntCopy = to.getIntRetain;
+
+ count = DoBlock (to.getIntCopy);
+ if (count != 1)
+ abort();
+ count = DoBlock (to.getIntRetain);
+ count = DoBlock (to.getIntRetain);
+ return count - 3;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-storageclass.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-storageclass.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-storageclass.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-block-storageclass.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,20 @@
+/* APPLE LOCAL file 5932809 */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+void _Block_byref_release(void*src){}
+
+int main() {
+ __block int X = 1234;
+ __block const char * message = "HELLO";
+
+ X = X - 1234;
+
+ X += 1;
+
+ printf ("%s(%d)\n", message, X);
+ X -= 1;
+
+ return X;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-attribute.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-attribute.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-attribute.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-attribute.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,13 @@
+/* APPLE LOCAL file radar 6096219 */
+/* Test that __byref attribute can be used directly. */
+/* { dg-options "-mmacosx-version-min=10.5 -fblocks" { target *-*-darwin* } } */
+/* { dg-do compile } */
+
+int main()
+{
+ __byref int JJJJ;
+ __attribute__((__blocks__(byref))) int III;
+
+ int (^XXX)(void) = ^{ return III+JJJJ; };
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-block.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-block.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-block.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref-block.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,16 @@
+/* APPLE LOCAL file radar 6180456 */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-options "-mmacosx-version-min=10.6 -fblocks" { target *-*-darwin* } } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "-m64" } { "" } } */
+
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ __block void(*bobTheFunction)(void);
+ __block void(^bobTheBlock)(void);
+
+ bobTheBlock = ^{;};
+
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-byref.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,44 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* Testing byref syntax checking. */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+int main() {
+ int x, y;
+ ^{ };
+ ^{|x|}; /* { dg-warning "has been deprecated in blocks" } */
+
+ ^{ |x,y| int r; return x+y+r; }; /* { dg-warning "has been deprecated in blocks" } */
+ ^{ |x,y|; int r; return x+y+r; }; /* { dg-warning "has been deprecated in blocks" } */
+
+ ^{ |x,y|; int r; return x+y+r; /* { dg-warning "has been deprecated in blocks" } */
+ ^{
+ |x,y|; int r; return x+y; /* { dg-warning "has been deprecated in blocks" } */
+ };
+ };
+
+ ^{ |x,y|; int r; return x+y+r; /* { dg-warning "has been deprecated in blocks" } */
+ ^{
+ { |x,y|; int r; return x+y; }; /* { dg-error "expected expression before" } */
+ };
+ };
+
+ ^ { int r;
+ |x, y| /* { dg-error "expected expression before" } */
+ };
+
+ ^{| /* { dg-warning "has been deprecated in blocks" } */
+ main()|}; /* { dg-error "only a visible variable may be used in a block byref declaration" } */
+
+ /* Assigning to byref variables. */
+ ^{|x| x = 1;}; /* { dg-warning "has been deprecated in blocks" } */
+
+ ^{ |x,y| /* { dg-warning "has been deprecated in blocks" } */
+ if (x != y)
+ x = y = 100;
+ };
+
+
+
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-c99-off-default.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-c99-off-default.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-c99-off-default.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-c99-off-default.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,9 @@
+/* APPLE LOCAL file radar 5811887 */
+/* Test that with -std=c99 blocks is off by default. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99" } */
+
+int main()
+{
+ void (^Vblock)(void) = ^{}; /* { dg-error "expected identifier" } */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-call.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-call.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-call.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-call.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,54 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+
+int (^IFP) ();
+int (^II) (int);
+int main() {
+ int (^PFR) (int) = IFP; /* { dg-error "incompatible block pointer types initializing" } */
+ PFR = II;
+
+
+ int (^IFP) () = PFR; /* { dg-error "incompatible block pointer types initializing" } */
+
+
+ const int (^CIC) () = IFP;
+
+ const int (^CICC) () = CIC;
+
+ int * const (^IPCC) () = 0;
+
+ int * const (^IPCC1) () = IPCC;
+
+ int * (^IPCC2) () = IPCC;
+
+ int (^IPCC3) (const int) = PFR;
+
+ int (^IPCC4) (int, char (^CArg) (double));
+
+
+ int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
+
+ int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; /* { dg-error "incompatible block pointer types initializing" } */
+
+ IPCC2 = 0;
+ IPCC2 = 1; /* { dg-error "invalid conversion assigning integer" } */
+ int (^x)() = 0;
+ int (^y)() = 3; /* { dg-error "invalid conversion initializing integer" } */
+ int a = 1;
+ int (^z)() = a+4; /* { dg-error "invalid conversion initializing integer" } */
+ return 0;
+}
+
+int blah() {
+ int (^IFP) (float);
+ char (^PCP)(double, double, char);
+
+ IFP(1.0);
+ IFP (1.0, 2.0); /* { dg-error "too many arguments to block call" } */
+
+ char ch = PCP(1.0, 2.0, 'a');
+ return PCP(1.0, 2.0); /* { dg-error "too few arguments to block" } */
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-codegen-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-codegen-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-codegen-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-codegen-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,29 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do run } */
+/* { dg-options "-fblocks" } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+extern void exit(int);
+
+typedef double (^myblock)(int);
+
+
+double test(myblock I) {
+ return I(42);
+}
+
+int main() {
+ int x = 1;
+ int y = 2;
+ double res = test(^(int z){|y| y = x+z; return (double)x; }); /* { dg-warning "has been deprecated in blocks" } */
+ printf("result = %f x = %d y = %d\n", res, x, y);
+ if (x != 1 || y != 43)
+ exit(1);
+
+ res = test(^(int z){|x| x = x+z; return (double)y; }); /* { dg-warning "has been deprecated in blocks" } */
+ printf("result = %f x = %d y = %d\n", res, x, y);
+ if (x != 43 || y != 43)
+ exit(1);
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-complicated-type.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-complicated-type.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-complicated-type.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-complicated-type.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,20 @@
+/* APPLE LOCAL file radar 5988995 */
+/* Type compatibility issue for blocks which return blocks. */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+int (^f)(char, int);
+
+int (^farray[10])(float, int);
+
+int (^func(int x))(char, int) {
+ return f;
+}
+
+// intent: block taking int returning block that takes char,int and returns int
+int (^(^block)(double x))(char, short);
+
+void foo() {
+ block = ^(double x){ return ^(char c, short y) { return (int)c + y; };}; /* { dg-error "returning block that lives on the local stack" } */
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-conditional-test.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-conditional-test.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-conditional-test.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-conditional-test.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,20 @@
+/* APPLE LOCAL file radar 5928316 */
+/* Test for use of block pointer in a conditional expression. */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+
+typedef int (^myblock)(int);
+
+int main() {
+ myblock b = ^(int a){ return a * a; };
+ if (1 && (b)) {
+ int i = b(3);
+ printf("i = %d\n", i);
+ }
+ return 0;
+}
+
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-const.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-const.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-const.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-const.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,17 @@
+/* APPLE LOCAL file radar 5814025 */
+/* Test that a one cannot assign to a 'const' block pointer variable. */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+#import <stdio.h>
+
+void foo(void) { printf("I'm in foo\n"); }
+void bar(void) { printf("I'm in bar\n"); }
+
+int main(char *argc, char *argv[]) {
+ void (^const blockA)(void) = ^ { printf("hello\n"); };
+ blockA = ^ { printf("world\n"); }; /* { dg-error "assignment of read-only variable" } */
+ return 0;
+}
+
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-continuation.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-continuation.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-continuation.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-continuation.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,43 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+int main() {
+
+while (1) {
+ takeblock(^{
+ break; /* { dg-error "break statement not within loop or switch" } */
+ while(1) break; /* ok */
+ goto label1; /* { dg-error "goto not allowed in block literal" } */
+ /* { dg-error "label" "" { target *-*-* } 11 } */
+ });
+ label1:
+ break; /* OK */
+ if (1)
+ continue; /* OK */
+ }
+
+ void (^vcl)(void) =
+ ^{
+ break; /* { dg-error "break statement not within loop or switch" } */
+
+ while (1) {
+ void (^vcl1) (void) = ^{};
+
+ break;
+ }
+ };
+
+ void (^VCL)(void) =
+ ^{
+ while (1) {
+ int i;
+ void (^vcl1) (void) = ^{ continue; };/* { dg-error "continue statement not within a loop" } */
+ break;
+ for (i = 0; i < 100; i++)
+ if (i == 10)
+ break;
+ }
+ };
+ goto label1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-copy-destroy.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-copy-destroy.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-copy-destroy.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-copy-destroy.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,30 @@
+/* APPLE LOCAL file 5782740 - blocks */
+/* Test generation of copy/destroy helper function. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fblocks" { target *-*-darwin* } } */
+
+#import <Cocoa/Cocoa.h>
+
+ at interface Root @end
+
+extern bar(double (^cp)(int));
+
+ at implementation Root
+
+- (void)example {
+ int y, x;
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ NSAutoreleasePool *relpool = [NSAutoreleasePool new];
+ bar(^(int z){ |y| y = x+z; [pool drain]; if (y) y++; [relpool release]; return y+2.0; }); /* { dg-warning "has been deprecated in blocks" } */
+}
+ at end
+
+int main()
+{
+ int x = 10;
+ int (^P) (void) = ^ { return x; };
+
+ int (^Q) (void) = ^ { return P(); };
+}
+/* { dg-final { scan-assembler "___copy_helper_block_" } } */
+/* { dg-final { scan-assembler "___destroy_helper_block_" } } */
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,12 @@
+/* APPLE LOCAL file 5939894 */
+/* Verify that the desired debugging type is generated for a structure
+ member that is a pointer to a block. */
+
+/* { dg-do compile } */
+/* { dg-options "-g -O0 -fblocks -dA" } */
+/* { dg-final { scan-assembler "invoke_impl.*DW_AT_name" } } */
+
+struct inStruct {
+ void (^genericBlockPtr)();
+} is;
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-debug-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,10 @@
+/* APPLE LOCAL file 5939894 */
+/* Verify that the desired debugging type is generated for a pointer
+ to a block. */
+
+/* { dg-do compile } */
+/* { dg-options "-g -O0 -fblocks -dA" } */
+/* { dg-final { scan-assembler "invoke_impl.*DW_AT_name" } } */
+
+void (^os)();
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-dup-invoke_impl.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-dup-invoke_impl.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-dup-invoke_impl.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-dup-invoke_impl.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,43 @@
+/* APPLE LOCAL file radar 5939894 */
+/* Check that if a definition of struct invoke_impl already exist, then use it. */
+/* { dg-options "-fblocks" } */
+/* { dg-do compile } */
+
+struct invoke_impl {
+ void *isa;
+ int Flags;
+ int Size;
+ void *FuncPtr;
+};
+
+enum numbers
+{
+ zero, one, two, three, four
+};
+
+typedef enum numbers (^myblock)(enum numbers);
+
+
+double test(myblock I) {
+ return I(three);
+}
+
+int main() {
+ enum numbers x = one;
+ enum numbers y = two;
+
+ myblock CL = ^(enum numbers z)
+ {|y| y = z; /* { dg-warning "has been deprecated in blocks" } */
+ test (
+ ^ (enum numbers z) { |x| /* { dg-warning "has been deprecated in blocks" } */
+ x = z;
+ return (enum numbers) four;
+ }
+ );
+ return x;
+ };
+
+ enum numbers res = test(CL);
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-encoding.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-encoding.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-encoding.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-encoding.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,24 @@
+/* APPLE LOCAL file radar 5849129 */
+/* Test for encoding of a block pointer as '@'. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+
+ at interface Test : NSObject
+- (void)method1:(void *(^)(void *))a;
+- (void)method2:(void *(^[5])(void *))b;
+ at end
+
+ at implementation Test
+- (void)method1:(void *(^)(void *))a {}
+- (void)method2:(void *(^[5])(void *))b {}
+ at end
+
+int main() {
+ return 0;
+}
+/* { dg-final { scan-assembler "v12 at 0:4@?" { target ilp32 } } } */
+/* { dg-final { scan-assembler "v24 at 0:8@?" { target lp64 } } } */
+/* { dg-final { scan-assembler "v12 at 0:4\[5@?\]" { target ilp32 } } } */
+/* { dg-final { scan-assembler "v24 at 0:8\[5@?\]" { target lp64 } } } */
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-enum.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-enum.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-enum.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-enum.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,35 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* Test use of enumerators in blocks. */
+/* { dg-do run } */
+/* { dg-options "-fblocks" } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+extern void exit(int);
+
+enum numbers
+{
+ zero, one, two, three
+};
+
+typedef enum numbers (^myblock)(enum numbers);
+
+
+double test(myblock I) {
+ return I(three);
+}
+
+int main() {
+ enum numbers x = one;
+ enum numbers y = two;
+
+ enum numbers res = test(^(enum numbers z){|y| y = z; return x; }); /* { dg-warning "has been deprecated in blocks" } */
+
+ if (x != one || y != three || res != one)
+ exit(1);
+
+ res = test(^(enum numbers z){|x| x = z; return x; }); /* { dg-warning "has been deprecated in blocks" } */
+ if (x != three || res != three)
+ exit(1);
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-error-global-byref.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-error-global-byref.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-error-global-byref.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-error-global-byref.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,28 @@
+/* APPLE LOCAL file radar 5803600 */
+/* Test for propery handling of 'byref' globals in nested blocks. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -fblocks" { target *-*-darwin* } } */
+
+#include <stdio.h>
+
+void CallBlock (void (^voidvoidBlock)(void)) {
+ voidvoidBlock();
+}
+
+int glob = 10;
+static int stat = 10;
+
+int foo() {
+ static int static_local = 10;
+ int local;
+ CallBlock( ^ {++glob;
+ CallBlock(^ { |glob, static_local| /* { dg-warning "has been deprecated in blocks" } */
+ ++glob;
+ stat++;
+ ++static_local;
+ });
+ ++local; /* { dg-error "increment of read-only variable" } */
+ ++static_local;
+ });
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-do.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-do.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-do.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-do.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,34 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+int main() {
+ __byref int O1;
+ int p = 0;
+ do
+ {
+ __byref int I1;
+ do
+ {
+ __byref int J1;
+ if (p == 2)
+ break;
+ }
+ while ( ++p < 3);
+ if (p == 4)
+ break;
+ }
+ while (++p != 5);
+
+ return count-7;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,25 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+int main()
+{
+ __byref int O1;
+ int i;
+ for (i = 1; i <= 5; i++)
+ {
+ __byref int I1;
+ }
+ if (count != 5)
+ abort();
+ return count - 6;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-for1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+#include <stdio.h>
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+int main() {
+ __byref int O1;
+ int i;
+ int p;
+ for (i = 1; i <= 5; i++) {
+ __byref int I1;
+ p = 0;
+ while (p != 10) {
+ __byref int II1;
+ if (p == 2)
+ break;
+ ++p;
+ }
+ }
+ return count-21;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-goto.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-goto.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-goto.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-goto.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,26 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do compile } */
+
+
+int foo(int p)
+{
+ __byref int O1;
+ int i;
+ LOUT: ;
+ for (i = 1; i < 100; i++)
+ {
+ __byref int I1;
+ while (p < 0)
+ {
+ __byref int II1;
+ if (p == 100)
+ goto LOUT; /* { dg-error "local byref variable II1 is in the scope of this goto" } */
+ ++p;
+ if (p == 2345)
+ break;
+ }
+ }
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-nested-while.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-nested-while.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-nested-while.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-nested-while.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+#include <stdio.h>
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+void objc_get_type_qualifiers (int flag, int type) {
+ while (flag--)
+ while (type++ < 4) {
+ __byref int W1;
+ __byref int W2;
+ if (type == 2)
+ break;
+ }
+}
+
+int main() {
+ objc_get_type_qualifiers (1, 0);
+ if (count != 4)
+ abort();
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,26 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+#include <stdio.h>
+
+extern void abort(void);
+void _Block_byref_assign_copy(void *a, void *b){};
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+
+int main() {
+ __byref int X = 1234;
+ if (X) {
+ __byref int local_BYREF = 100;
+ X += 100 + local_BYREF;
+ return count-2;
+ }
+ return -1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-return1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,40 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+#include <stdio.h>
+
+extern void abort(void);
+void _Block_byref_assign_copy(void *a, void *b){};
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+void *_NSConcreteStackBlock;
+
+void FOO(int arg) {
+ __byref int X = 1234;
+ if (arg) {
+ __byref int local_BYREF = 100;
+ X += 100 + local_BYREF;
+ return;
+ }
+ ^{ |X| X++; }; /* { dg-warning "has been deprecated in blocks" } */
+ X = 1000;
+}
+
+int main() {
+ FOO(1);
+ if (count != 2)
+ abort();
+
+ count = 0;
+ FOO(0);
+ if (count != 1)
+ abort();
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-switch.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-switch.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-switch.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-switch.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,69 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+#include <stdio.h>
+
+extern void abort(void);
+void _Block_byref_assign_copy(void *a, void *b){};
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ printf ("%p\n", arg);
+ ++count;
+}
+
+int foo(int p, int q) {
+ __byref int O1;
+ switch (p) {
+ case 1:
+ {
+ __byref int I1;
+ I1 += 1;
+ break;
+ }
+ case 10:
+ {
+ __byref int J1;
+ break;
+ }
+ default :
+ {
+ __byref int D1;
+ __byref int D2;
+ switch (q) {
+ case 11:
+ {
+ __byref int Q1;
+ break;
+ }
+ default:
+ {
+ __byref int ID1;
+ __byref int ID2;
+ }
+ };
+ break;
+ }
+ }
+ return 0;
+}
+
+int main() {
+ foo (1, 0);
+ if (count != 2)
+ abort();
+
+ count = 0;
+ foo (12, 11);
+ if (count != 4)
+ abort();
+
+ count = 0;
+ foo (12, 13);
+ if (count != 5)
+ abort();
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-while.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-while.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-while.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-escape-while.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,25 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+int main()
+{
+ __byref int O1;
+ int i = 0;
+ while (++i != 5)
+ {
+ __byref int I1;
+ }
+ if (count != 4)
+ abort();
+ return count - 5;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-block.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-block.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-block.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-block.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,34 @@
+/* APPLE LOCAL file radar 5822844 */
+/* Test that blocks can be declared at global scope. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.6 -fblocks" { target *-*-darwin* } } */
+#include <stdio.h>
+
+static void* _NSConcreteGlobalBlock;
+
+
+typedef void (^ HelloBlock_t)(const char * name);
+
+HelloBlock_t helloBlock = ^(const char * name)
+{
+ printf("Hello there, %s!\n", name);
+};
+
+static HelloBlock_t s_helloBlock = ^(const char * name)
+{
+ printf("Hello there, %s!\n", name);
+};
+
+int X = 1234;
+int (^CP)(void) = ^{ X = X+1; return X; };
+
+int
+main(int argc, char * argv[])
+{
+ helloBlock("world");
+ s_helloBlock("world");
+
+ CP();
+ printf ("X = %d\n", X);
+ return X - 1235;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 5803005 */
+/* Test that all global variables referenced in blocks are treated as 'byref' as default. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -fblocks" { target *-*-darwin* } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+
+void CallBlock (void (^voidvoidBlock)(void)) {
+ voidvoidBlock();
+}
+
+int glob = 10;
+static int stat = 10;
+
+int foo() {
+ static int local = 10;
+ CallBlock( ^ {| local| ++glob; ++stat; ++local; /* { dg-warning "has been deprecated in blocks" } */
+ CallBlock(^ { |local| ++glob; ++stat; ++local; }); /* { dg-warning "has been deprecated in blocks" } */
+ ++glob; ++stat; ++local; });
+
+ if (glob != 13 || stat != 13 || local != 13)
+ return 1;
+ return 0;
+}
+
+int main()
+{
+ return foo ();
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,34 @@
+/* APPLE LOCAL file radar 6014138 */
+/* Test use of __byref on locals which will be used as 'byref' variables in blocks. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -fblocks" { target *-*-darwin* } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+void _Block_byref_assign_copy(void * dst, void *src){}
+void _Block_byref_release(void*src){}
+
+void CallBlock (void (^voidvoidBlock)(void)) {
+ voidvoidBlock();
+}
+
+
+int foo() {
+ __byref int local_byref_1 = 10;
+ __byref int local_byref_2 = 10;
+ __byref int local_byref_3 = 10;
+
+ CallBlock( ^ { ++local_byref_1; ++local_byref_2; ++local_byref_3;
+ CallBlock(^ { ++local_byref_1; ++local_byref_2; ++local_byref_3; });
+ ++local_byref_1; ++local_byref_2; ++local_byref_3; });
+
+ if (local_byref_1 != 13 || local_byref_2 != 13 || local_byref_3 != 13)
+ return 1;
+ return 0;
+}
+
+int main()
+{
+ return foo ();
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-byref.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 5803600 */
+/* Test that all global variables referenced in blocks are treated as 'byref' as default. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -fblocks" { target *-*-darwin* } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+
+void CallBlock (void (^voidvoidBlock)(void)) {
+ voidvoidBlock();
+}
+
+int glob = 10;
+static int stat = 10;
+
+int foo() {
+ static int local = 10;
+ CallBlock( ^ {| glob, stat, local| ++glob; ++stat; ++local; /* { dg-warning "has been deprecated in blocks" } */
+ CallBlock(^ { |glob, stat, local| ++glob; ++stat; ++local; }); /* { dg-warning "has been deprecated in blocks" } */
+ ++glob; ++stat; ++local; });
+
+ if (glob != 13 || stat != 13 || local != 13)
+ return 1;
+ return 0;
+}
+
+int main()
+{
+ return foo ();
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-implicit-byref.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-implicit-byref.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-implicit-byref.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-global-implicit-byref.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,20 @@
+/* APPLE LOCAL file radar 5803005 */
+/* Test that all globals are 'byref' as default. */
+/* { dg-options "-mmacosx-version-min=10.5" { target *-*-darwin* } } */
+/* { dg-do compile } */
+
+int a;
+static s;
+extern int i;
+
+void foo() {
+ extern int b;
+ static int c;
+
+ ^ { a = 1; // byref OK
+ b = 2; // byref OK
+ s = 5; // byref OK
+ i = 12; // byref OK
+ c = 3;
+ };
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-block.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-block.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-block.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-block.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,38 @@
+/* APPLE LOCAL file radar 5831855 */
+#import <Foundation/Foundation.h>
+/* Test that a block pointer can be converted back-and-forth to 'id' in
+ both initializsation and assignment without requiring a cast. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC" { target *-*-darwin* } } */
+
+void * _NSConcreteStackBlock;
+
+typedef void (^blockATYPE)(void);
+
+id myBlockFunc (void (^blockA)(void))
+{
+ return blockA;
+}
+
+blockATYPE MyBlockIdFunc (id id_arg)
+{
+ return id_arg;
+}
+
+int main(char *argc, char *argv[]) {
+ void (^blockA)(void) = ^ { printf("hello\n"); };
+ // an 'id' can be initialized wit a block.
+ id aBlock = blockA;
+
+ // a block should be assignable to an id
+ aBlock = blockA;
+
+ // an 'id' should be assignable to a block
+ blockA = aBlock;
+
+ blockA = myBlockFunc (^ { printf("hello\n"); });
+
+ aBlock = MyBlockIdFunc (aBlock);
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-global-block.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-global-block.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-global-block.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-id-global-block.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,39 @@
+/* APPLE LOCAL file radar 5822844 - global blocks */
+#import <Foundation/Foundation.h>
+/* Test that a block pointer can be converted back-and-forth to 'id' in
+ both initializsation and assignment without requiring a cast. */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.6 -ObjC" { target *-*-darwin* } } */
+
+void * _NSConcreteGlobalBlock;
+
+typedef void (^blockATYPE)(void);
+
+id myBlockFunc (void (^blockA)(void))
+{
+ return blockA;
+}
+
+blockATYPE MyBlockIdFunc (id id_arg)
+{
+ return id_arg;
+}
+
+void (^blockA)(void) = ^ { printf("hello\n"); };
+
+int main(char *argc, char *argv[]) {
+ // an 'id' can be initialized wit a block.
+ id aBlock = blockA;
+
+ // a block should be assignable to an id
+ aBlock = blockA;
+
+ // an 'id' should be assignable to a block
+ blockA = aBlock;
+
+ blockA = myBlockFunc (^ { printf("hello\n"); });
+
+ aBlock = MyBlockIdFunc (aBlock);
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-implicit-byref.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-implicit-byref.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-implicit-byref.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-implicit-byref.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,67 @@
+/* APPLE LOCAL file radar 5811191 */
+/* Test that all 'ivars' are treated as implicit byref. Its inclusing inside |...|
+ block is treated with a warning and ignored.
+*/
+/* { dg-do run } */
+/* { dg-options "-ObjC -mmacosx-version-min=10.5 -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+#import <Foundation/Foundation.h>
+
+void * _NSConcreteStackBlock;
+
+enum {
+ BLOCK_NEEDS_FREE = (1 << 24),
+ BLOCK_HAS_COPY_DISPOSE = (1 << 25),
+ BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed
+ BLOCK_IS_GC = (1 << 27),
+};
+
+struct Block_basic {
+ void *isa;
+ //char flags; char size; short refcount;
+ int Block_flags; // int32_t
+ int Block_size; // XXX should be packed into Block_flags
+ void (*Block_invoke)(void *);
+ void (*Block_copy)(void *dst, void *src);
+ void (*Block_dispose)(void *);
+ //long params[0]; // generic space for const & byref hidden params, return value, variable on needs of course
+};
+
+ at interface TestObject : NSObject {
+ at public
+ id aSlot;
+}
+- (int) testVerbosely:(int)verbose;
+
+
+ at end
+
+ at implementation TestObject
+
+
+- (int) testVerbosely:(int)verbose
+ {
+ aSlot = [[NSObject alloc] init];
+
+
+ void (^myBlock)(void) = ^{
+ | /* { dg-warning "has been deprecated in blocks" } */
+ aSlot| /* { dg-warning "ivar" } */
+ printf("[aSlot retainCount] == %d\n", (int)[aSlot retainCount]);
+ };
+ struct Block_basic *basic = (struct Block_basic *)(void *)myBlock;
+ if (basic->Block_flags & BLOCK_NO_COPY)
+ abort ();
+
+ return 0;
+}
+
+
+ at end
+
+int main(int argc, char *argv[]) {
+ TestObject *to = [[TestObject alloc] init];
+
+ [to testVerbosely:1];
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivar.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivar.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivar.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivar.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,69 @@
+/* APPLE LOCAL file 5782740 - blocks */
+/* Test generation of copy/destroy helper function. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fblocks" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+
+void *Block_copy(const void *aBlock);
+
+ at interface TestObject : NSObject {
+ at public
+ int refcount;
+ id aSlot;
+}
+- (int) testVerbosely:(int)verbose;
+
+ at end
+
+ at implementation TestObject
+
+- (id) retain {
+ ++refcount;
+ return self;
+}
+
+- (int)retainCounter {
+ return refcount + 1;
+}
+
+- (void) release {
+ if (refcount == 0) [self dealloc];
+ else --refcount;
+}
+
+- (int) testVerbosely:(int)verbose
+ {
+ int errors = 0;
+ aSlot = [[NSObject alloc] init];
+
+ int initialRetainCounter = [self retainCounter];
+
+ void (^myBlock)(void) = ^{
+ printf("[aSlot retainCount] == %d\n", (int)[aSlot retainCount]);
+ };
+
+ int afterBlockRetainCounter = [self retainCounter];
+
+ void (^myBlockCopy)(void) = Block_copy(myBlock);
+
+ int afterBlockCopyRetainCounter = [self retainCounter];
+
+ if (afterBlockRetainCounter > initialRetainCounter) {
+ printf("testVerbosely: after block, retain count is %d vs before %d\n", afterBlockRetainCounter, initialRetainCounter);
+ ++errors;
+ }
+
+ if (afterBlockCopyRetainCounter <= afterBlockRetainCounter) {
+ printf("testVerbosely: block copy did not retain interior object\n");
+ ++errors;
+ }
+
+ if (errors == 0 && verbose) printf("testVerbosely: objc import object test success\n");
+ return errors;
+
+}
+ at end
+/* { dg-final { scan-assembler "___copy_helper_block_" } } */
+/* { dg-final { scan-assembler "___destroy_helper_block_" } } */
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivarlayout.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivarlayout.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivarlayout.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-ivarlayout.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,42 @@
+/* APPLE LOCAL file radar 6133042 */
+/* Check that ivars of block pointer types are scanned by GC */
+/* { dg-do run } */
+/* { dg-options "-ObjC -mmacosx-version-min=10.6 -fblocks -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-require-effective-target objc_gc } */
+
+#include <Foundation/Foundation.h>
+
+ at interface TestObject : NSObject {
+ int (^getInt)(void);
+ BOOL b1;
+ int (^getFloat)(void);
+}
+ at property(assign, readonly) int (^getInt)(void);
+ at end
+
+ at implementation TestObject
+ at dynamic getInt;
+ at end
+
+int main(char *argc, char *argv[]) {
+ const char *layout = (char *)class_getIvarLayout([TestObject self]);
+ printf("layout is:\n");
+ int cursor = 0;
+ // we're looking for slot 1
+ int seeking = 1;
+ while (*layout) {
+ int skip = (*layout) >> 4;
+ int process = (*layout) & 0xf;
+ printf("(%x) skip %d, process %d\n", (*layout), skip, process);
+ cursor += skip;
+ if ((cursor <= seeking) && ((cursor + process) > seeking)) {
+ printf("Will scan desired %d element!\n", seeking);
+ return 0;
+ }
+ cursor += process;
+ ++layout;
+ }
+ printf("%s: ***failure, didn't scan slot %d\n", argv[0], seeking);
+ return 1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal-exp.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal-exp.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal-exp.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal-exp.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,13 @@
+/* APPLE LOCAL file radar 5732232, 6034839 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void foo(int x, int y);
+
+int main() {
+ ^(int x)foo(x, 4); /* { dg-error "blocks require" } */
+ ^(int x, int y)foo(y, x); /* { dg-error "blocks require" } */
+ ^(int x)(x+4); /* { dg-error "blocks require" } */
+ ^(z+4); /* { dg-error "expected" } */
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-literal.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,70 @@
+/* APPLE LOCAL file radar 5732232, 6034839 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void I( void (^)(void));
+void (^noop)(void);
+
+void nothing();
+int printf(const char*, ...);
+
+typedef void (^T) (void);
+
+void takeblock(T);
+int takeintint(int (^C)(int)) { return C(4); }
+
+T somefunction() {
+ if (^{ })
+ nothing();
+
+ noop = ^{};
+
+ noop = ^{printf("\nBlock\n"); };
+
+ I(^{ });
+
+ noop = ^noop /* { dg-error "blocks require" } */
+ ; /* { dg-error "argument list is required for block expression literals" } */
+
+ return ^{printf("\nBlock\n"); }; /* { dg-error "returning block that lives on the local stack" } */
+}
+
+void test2() {
+ int x = 4;
+
+ takeblock(^{ printf("%d\n", x); });
+ takeblock(^{ x = 4; }); /* { dg-error "assignment of read-only variable" } */
+
+ takeblock(^test2() /* { dg-error "blocks require" } */
+ ); /* { dg-error "argument list is required for block expression literals" } */
+
+ takeblock(^(void)(void)printf("hello world!\n")); /* { dg-error "blocks require" } */
+}
+
+void (^test3())(void) {
+ return ^{}; /* { dg-error "returning block that lives on the local stack" } */
+}
+
+void test4() {
+ void (^noop)(void) = ^{};
+ void (*noop2)() = 0;
+}
+
+void test5() {
+ takeintint(^(int x)(x+1)); /* { dg-error "blocks require" } */
+
+ // Block expr of statement expr.
+ takeintint(^(int x)({ /* { dg-error "blocks require" } */
+ return 42; })); /* { dg-error "return not allowed in block expression literal" } */
+
+ int y;
+ takeintint(^(int x)(x+y)); /* { dg-error "blocks require" } */
+
+ void *X = ^(x+r); /* { dg-error "expected" } */
+
+ int (^c)(char);
+ (1 ? c : 0)('x');
+ (1 ? 0 : c)('x');
+
+ (1 ? c : c)('x');
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-stack.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-stack.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-stack.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-stack.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,8 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void (^test3())(void) {
+ return ^{}; /* { dg-error "returning block that lives on the local stack" } */
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-static-test.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-static-test.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-static-test.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-local-static-test.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,16 @@
+/* APPLE LOCAL file radar 6177162 */
+/* local statics need be treated same as file static (byref). */
+/* { dg-options "-mmacosx-version-min=10.6" { target *-*-darwin* } } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ static int numberOfSquesals = 5;
+
+ ^{ numberOfSquesals = 6; }();
+
+ if (numberOfSquesals == 6) { printf("%s: success\n", argv[0]); }
+
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-misc.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-misc.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-misc.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-misc.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,52 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void donotwarn();
+
+int (^IFP) ();
+int (^II) (int);
+int test1() {
+ int (^PFR) (int) = 0; // OK
+ PFR = II; // OK
+
+ if (PFR == II) // OK
+ donotwarn();
+
+ if (PFR == IFP) /* { dg-error "comparison of distinct block types" } */
+ donotwarn();
+
+ if (PFR == (int (^) (int))IFP) // OK
+ donotwarn();
+
+ if (PFR == 0) // OK
+ donotwarn();
+
+ if (PFR) // OK
+ donotwarn();
+
+ if (!PFR) // OK
+ donotwarn();
+
+ return PFR != IFP; /* { dg-error "comparison of distinct block types" } */
+}
+
+int test2(double (^S)()) {
+ double (^I)(int) = (void*) S;
+ (void*)I = (void *)S; /* { dg-warning "target of assignment not really an lvalue; this will be a hard error in the future" } */
+
+ void *pv = I;
+
+ pv = S;
+
+ I(1);
+
+ return (void*)I == (void *)S;
+}
+
+int^ x; /* { dg-error "block pointer to non-function type is invalid" } */
+int^^ x1; /* { dg-error "block pointer to non-function type is invalid" } */
+
+int test3() {
+ char *^ y; /* { dg-error "block pointer to non-function type is invalid" } */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,30 @@
+/* APPLE LOCAL file radar 5988451 - nested blocks */
+/* This routine tests a nested block when a copied-in variable in the
+ inner block must be 'frozen' at the outer block so, it has the value
+ at the point of inner block declaration and not when block is envoked.
+*/
+/* { dg-do run } */
+/* { dg-options "-fblocks" } */
+
+extern void abort(void);
+
+void * _NSConcreteStackBlock;
+
+
+void callVoidVoid(void (^closure)(void)) {
+ closure();
+}
+
+int main(int argc, char *argv[]) {
+ int local_i_var = 1;
+
+ void (^vv)(void) = ^{
+ if (argc > 0) {
+ callVoidVoid(^{ if (local_i_var != 1) abort(); });
+ }
+ };
+
+ local_i_var = 2;
+ vv();
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 5988451 */
+/* More testing of copied in variables in nested blocks. */
+/* { dg-options "-fblocks -mmacosx-version-min=10.5 -ObjC -framework Foundation" { target *-*-darwin* } } */
+/* { dg-do run } */
+
+#import <Foundation/Foundation.h>
+void *_NSConcreteStackBlock;
+
+id Global = nil;
+
+void callVoidVoid(void (^closure)(void)) {
+ closure();
+}
+
+int main(int argc, char *argv[]) {
+ id x = [[NSObject alloc] init];
+ id initial_x = x;
+
+ void (^vv)(void) = ^{
+ if (argc > 0) {
+ callVoidVoid(^{ Global = x; });
+ }
+ };
+
+ x = nil;
+ vv();
+ if (Global != initial_x) {
+ exit(1);
+ }
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-3.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-3.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-3.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var-3.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,35 @@
+/* APPLE LOCAL file radar 5988451 */
+/* Testing of copied in parameter in nested blocks. */
+/* { dg-options "-fblocks -mmacosx-version-min=10.5 -ObjC -framework Foundation" { target *-*-darwin* } } */
+/* { dg-do run } */
+
+#import <Foundation/Foundation.h>
+void *_NSConcreteStackBlock;
+
+id Global = nil;
+
+void callVoidVoid(void (^closure)(void)) {
+ closure();
+}
+
+int foo(int argc, id x) {
+ id initial_x = x;
+
+ void (^vv)(void) = ^{
+ if (argc > 0) {
+ callVoidVoid(^{ Global = x; });
+ }
+ };
+
+ x = nil;
+ vv();
+ if (Global != initial_x) {
+ exit(1);
+ }
+ return 0;
+}
+
+int main()
+{
+ return foo(1, [[NSObject alloc] init]);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-copied-var.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 5988451 - nested blocks */
+/* This test is to make sure that the inner block uses the value of the
+ copied-in variable at its point of declaration and not when block is envoked.
+*/
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.6 -fblocks" { target *-*-darwin* } } */
+
+extern void abort(void);
+
+void * _NSConcreteStackBlock;
+
+
+void callVoidVoid(void (^closure)(void)) {
+ closure();
+}
+
+int main(int argc, char *argv[]) {
+ int local_i_var = 1;
+
+ void (^vv)(void) = ^{
+ if (local_i_var != 1)
+ abort();
+ if (argc > 0) {
+ callVoidVoid(^{ if (local_i_var != 1) abort(); });
+ }
+ };
+
+ local_i_var = 2;
+ vv();
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global-copied-var-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global-copied-var-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global-copied-var-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global-copied-var-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,35 @@
+/* APPLE LOCAL file radar global blocks */
+/* More testing of copied in variables in nested blocks. */
+/* { dg-options "-fblocks -mmacosx-version-min=10.6 -ObjC -framework Foundation" { target *-*-darwin* } } */
+/* { dg-do run } */
+
+#import <Foundation/Foundation.h>
+void *_NSConcreteGlobalBlock;
+
+id Global = nil;
+
+void callVoidVoid(void (^closure)(void)) {
+ closure();
+}
+
+int argc = 1;
+
+id x;
+
+void (^vv)(void) = ^{
+ if (argc > 0) {
+ callVoidVoid(^{ Global = x; });
+ }
+};
+
+int main() {
+ x = [[NSObject alloc] init];
+ id initial_x = x;
+
+ vv();
+
+ if (Global != initial_x) {
+ exit(1);
+ }
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested-global.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,58 @@
+/* APPLE LOCAL file radar 5822844 - global blocks */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.6 -fblocks" { target *-*-darwin* } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+#ifdef __cplusplus
+extern "C" void exit(int);
+#else
+extern void exit(int);
+#endif
+
+void * _NSConcreteGlobalBlock;
+
+enum numbers {
+ zero, one, two, three, four
+};
+
+typedef enum numbers (^myblock)(enum numbers);
+
+
+double test(myblock I) {
+ return I(three);
+}
+
+enum numbers x = one;
+enum numbers y = two;
+
+static myblock CL = ^(enum numbers z)
+ { enum numbers savex = x;
+ { __block enum numbers x = savex;
+ y = z;
+ if (y != three)
+ exit (6);
+ test (
+ ^ (enum numbers z) {
+ if (y != three) {
+ exit(1);
+ }
+ if (x != one)
+ exit(2);
+ x = z;
+ if (x != three)
+ exit(3);
+ if (y != three)
+ exit(4);
+ return (enum numbers) four;
+ });}
+ return x;
+ };
+
+int main() {
+ enum numbers res = (enum numbers)test(CL);
+
+ if (res != one)
+ exit (5);
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nested.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,57 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-options "-mmacosx-version-min=10.6 -fblocks" { target *-*-darwin* } } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "-m64" } { "" } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+#ifdef __cplusplus
+extern "C" void exit(int);
+#else
+extern void exit(int);
+#endif
+
+enum numbers {
+ zero, one, two, three, four
+};
+
+typedef enum numbers (^myblock)(enum numbers);
+
+
+double test(myblock I) {
+ return I(three);
+}
+
+int main() {
+ __block enum numbers x = one;
+ __block enum numbers y = two;
+
+ myblock CL = ^(enum numbers z)
+ { enum numbers savex = x;
+ { __block enum numbers x = savex;
+ y = z;
+ if (y != three)
+ exit (6);
+ test (
+ ^ (enum numbers z) {
+ if (y != three) {
+ exit(1);
+ }
+ if (x != one)
+ exit(2);
+ x = z;
+ if (x != three)
+ exit(3);
+ if (y != three)
+ exit(4);
+ return (enum numbers) four;
+ });}
+ return x;
+ };
+
+ enum numbers res = (enum numbers)test(CL);
+
+ if (res != one)
+ exit (5);
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,36 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* Test for generation of escape _Block_byref_release call when a local
+ __byref variable is copied in. */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+void *_NSConcreteStackBlock;
+void _Block_byref_assign_copy(void * dst, void *src){}
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+void junk(void (^block)(void)) {
+ block();
+}
+
+int test() {
+ int __byref i = 10;
+ void (^dummy)(void) = ^{ printf("i = %d\n", i); };
+ junk(dummy);
+ return count;
+}
+
+int main()
+{
+ if ( test() != 1)
+ abort();
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-2.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-2.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-2.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,36 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* Test for generation of escape _Block_byref_release call when a local
+ __byref variable is copied in and block has a return statement. */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+void *_NSConcreteStackBlock;
+void _Block_byref_assign_copy(void * dst, void *src){}
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+void junk(int (^block)(void)) {
+ block();
+}
+
+int test() {
+ int __byref i = 10;
+ int (^dummy)(void) = ^{ printf("i = %d\n", i); return i; };
+ junk(dummy);
+ return count;
+}
+
+int main()
+{
+ if ( test() != 1)
+ abort();
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-3.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-3.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-3.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper-3.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,35 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* Test for generation of escape _Block_byref_release call when a __byref
+ variable inside a block is declared and used. */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+void *_NSConcreteStackBlock;
+void _Block_byref_assign_copy(void * dst, void *src){}
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+void junk(void (^block)(void)) {
+ block();
+}
+
+int test() {
+ void (^dummy)(void) = ^{ int __byref i = 10; printf("i = %d\n", i); };
+ junk(dummy);
+ return count;
+}
+
+int main()
+{
+ if ( test() != 1)
+ abort();
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-noescape-helper.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,34 @@
+/* APPLE LOCAL file radar 6083129 byref escapes */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+#include <stdio.h>
+
+void *_NSConcreteStackBlock;
+void _Block_byref_assign_copy(void * dst, void *src){}
+
+extern void abort(void);
+
+static int count;
+static void _Block_byref_release(void * arg) {
+ ++count;
+}
+
+void junk(void (^block)(void)) {
+ block();
+}
+
+int test() {
+ int __byref i = 10;
+ void (^dummy)(void) = ^{ | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ junk(dummy);
+ return count;
+}
+
+int main()
+{
+ if ( test() != 1)
+ abort();
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nonnull-test.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nonnull-test.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nonnull-test.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-nonnull-test.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,31 @@
+/* APPLE LOCAL file radar 5925781 */
+/* Test for the "nonnull" function attribute. */
+/* { dg-do compile } */
+/* { dg-options "-Wnonnull" } */
+
+#include <stddef.h>
+
+extern void func1 (void (^block1)(), void (^block2)(), int) __attribute__((nonnull));
+
+extern void func3 (void (^block1)(), int, void (^block2)(), int)
+ __attribute__((nonnull(1,3)));
+
+extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1)))
+ __attribute__((nonnull(2)));
+
+void
+foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
+{
+ func1(cp1, cp2, i1);
+
+ func1(NULL, cp2, i1); /* { dg-warning "null" "null with argless nonnull 1" } */
+ func1(cp1, NULL, i1); /* { dg-warning "null" "null with argless nonnull 2" } */
+ func1(cp1, cp2, 0);
+
+
+ func3(NULL, i2, cp3, i3); /* { dg-warning "null" "null with explicit nonnull 1" } */
+ func3(cp3, i2, NULL, i3); /* { dg-warning "null" "null with explicit nonnull 3" } */
+
+ func4(NULL, cp1); /* { dg-warning "null" "null with multiple attributes 1" } */
+ func4(cp1, NULL); /* { dg-warning "null" "null with multiple attributes 2" } */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-assignment.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-assignment.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-assignment.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-assignment.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,12 @@
+/* APPLE LOCAL file radar 5878380 */
+/* Issue diagnostics, instead of ICE, on invalid block pointer assignment. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC" { target *-*-darwin* } } */
+
+static int sNSImageSnapshotInWindowsComputedValue = -2;
+
+static void _NSImageSnapshotInWindows(void)
+{
+ static int nInvalid = ^{ return 1; }; /* { dg-error "incompatible types in initialization" } */
+ sNSImageSnapshotInWindowsComputedValue = ^{ return 1; }; /* { dg-error "incompatible types in assignment" } */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type-match.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type-match.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type-match.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type-match.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,18 @@
+/* APPLE LOCAL file 5795493 - blocks */
+/* Check that function decl and definition which have blocks (blocks) as their
+ type do the type-matching correctly and do not issue bogus warning. */
+/* { dg-do compile } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fblocks" { target *-*-darwin* } } */
+
+void useBlock (void (^arg)(void));
+
+void useBlock (void (^arg)(void)) {}
+
+ at interface Fred
+- (void) useBlock:(void (^)(void)) aBlock;
+ at end
+
+ at implementation Fred
+- (void) useBlock:(void (^)(void)) aBlock { }
+ at end
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer-type.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,113 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* Test that mixup of a pointer type and a block pointer type does not cause program to crash. */
+/* { dg-do run } */
+/* { dg-options "-fblocks" } */
+
+void * _NSConcreteStackBlock;
+#ifndef _BLOCK_PRIVATE_H_
+#define _BLOCK_PRIVATE_H_
+
+enum {
+ BLOCK_NEEDS_FREE = (1 << 24),
+ BLOCK_HAS_COPY_DISPOSE = (1 << 25),
+ BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed
+ BLOCK_IS_GC = (1 << 27),
+};
+
+struct Block_basic {
+ long reserved;
+ //char flags; char size; short refcount;
+ int Block_flags; // int32_t
+ int Block_size; // XXX should be packed into Block_flags
+ void (*Block_invoke)(void *);
+ void (*Block_copy)(void *dst, void *src);
+ void (*Block_dispose)(void *);
+};
+
+struct Block_byref {
+ long reserved;
+ struct Block_byref *forwarding;
+ int refcount;
+ int size;
+ void (*byref_keep)(struct Block_byref *dst, struct Block_byref *src);
+ void (*byref_destroy)(struct Block_byref *);
+};
+
+/* runtime entry for destroying shared data blocks */
+void Block_destroy_byref(struct Block_byref *shared_struct);
+/* runtime entry for sharing shared data blocks */
+struct Block_byref *Block_share_byref(struct Block_byref *shared_struct);
+
+/* runtime entry to get total size of a block */
+int Block_size(struct Block_basic *aBlock);
+
+// set the allocator/deallocator pair (used by ObjC to establish GC)
+void _Block_set_allocator_pair(void *(*alloc)(const unsigned long), void (*dealloc)(const void *));
+
+#endif
+
+int GlobalInt;
+void setGlobalInt(int value) { GlobalInt = value; }
+int getGlobalInt() { int tmp = GlobalInt; GlobalInt = 0; return tmp; }
+
+
+//
+// Example block code generated for specific Blocks
+//
+
+//
+// Partially bound block referencing const and byref args
+//
+
+/* Inclusion of this block block causes program to crash, even though it does not envoke it */
+#if __BLOCKS__
+int parameters_example_real(int verbose) {
+ int desiredValue = 100;
+ void (^myBlock)(int);
+ myBlock = ^ (int param) {
+ setGlobalInt(param);
+ };
+ myBlock(desiredValue);
+ int globalValue = getGlobalInt();
+ // if (error_found("parameters_real", globalValue, desiredValue, verbose)) return 1;
+ return 0;
+}
+
+#endif __BLOCKS__
+
+struct parameters_example_struct {
+ struct Block_basic base;
+};
+
+// the "thunks" compiled for the invoke entry point of the parameters_example
+
+void invoke_parameters_example(struct parameters_example_struct *aBlock, int param) {
+ {
+ setGlobalInt(param);
+ }
+}
+
+
+// The rewritten version of the code above
+
+int parameters_example(int verbose) {
+ int desiredValue = 100;
+ struct parameters_example_struct literal = {
+ { 0, 0, sizeof(struct parameters_example_struct),
+ (void (*)(void *))invoke_parameters_example,
+ },
+ };
+ struct parameters_example_struct *myBlock = &literal;
+
+ // get a type correct function pointer for the invocation function
+ void (*correct)(struct parameters_example_struct *, int);
+ correct = (void (*)(struct parameters_example_struct *, int))myBlock->base.Block_invoke;
+ // call the block with itself as first arg and the parameter 100
+ correct(myBlock, desiredValue);
+
+ return 0;
+
+}
+
+int main(int argc, char *argv[]) { parameters_example(1); return 0; }
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-pointer.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,27 @@
+/* APPLE LOCAL file - testcase for Radar 5811943 */
+/* { dg-do compile } */
+/* { dg-options "-g -O0 -fblocks -dA" } */
+/* { dg-final { scan-assembler "DW_AT_APPLE_block" } } */
+
+#include <stdio.h>
+void * _NSConcreteStackBlock;
+
+int
+blockTaker (int (^myBlock)(int), int other_input)
+{
+ return 5 * myBlock (other_input);
+}
+
+int main (int argc, char **argv)
+{
+ int (^blockptr) (int) = ^(int inval) {
+ printf ("Inputs: %d, %d.\n", argc, inval);
+ return argc * inval;
+ };
+
+
+ argc = 10;
+ printf ("I got: %d.\n",
+ blockTaker (blockptr, 6));
+ return 0;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-1.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-1.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-1.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-1.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,24 @@
+/* APPLE LOCAL file blocks 6065211 */
+/* { dg-options "-fblocks" } */
+
+enum e { no, yes };
+
+void foo() {
+ void (^bp)(int);
+ void (*rp)(int);
+ void (^bp1)();
+ double *dp;
+ void *vp = bp;
+
+ vp = bp;
+ f(1 ? dp : vp);
+ f(1 ? bp : vp);
+ bp != vp;
+ f(1 ? bp : (void*)0);
+ f(1 ? bp : bp1); /* { dg-error "type mismatch" } */
+ bp > rp; /* { dg-error "invalid operands" } */
+ bp > 0; /* { dg-error "invalid operands" } */
+ bp > bp; /* { dg-error "invalid operands" } */
+ bp > vp; /* { dg-error "invalid operands" } */
+ f(1 ? bp : rp); /* { dg-error "type mismatch" } */
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-exp.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-exp.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-exp.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-question-exp.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,19 @@
+/* APPLE LOCAL file radar 5957801 */
+/* Test for use of block pointer in a ?-exp expression. */
+/* { dg-options "-fblocks" } */
+/* { dg-do run } */
+
+typedef int (^myblock)(void);
+void *_NSConcreteStackBlock;
+
+myblock foo(int i, myblock b) {
+ if (!i ? (void *)0 : b)
+ return (i ? b : (void *)0);
+}
+
+int main () {
+ myblock b = ^{ return 1; };
+ if (foo (1, b))
+ return 0;
+ return 1;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readonly-diag.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readonly-diag.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readonly-diag.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readonly-diag.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,13 @@
+/* APPLE LOCAL file radar 5805175 - blocks */
+/* Test that pre/post incr/decr of copied-in variable cuases proper diagnostic. */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+void foo() {
+ static int s_i = 10;
+ int local;
+ ^ { ++s_i; };
+ ^ { local--; }; /* { dg-error "decrement of read-only variable" } */
+ ++s_i;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgc.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgc.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgc.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgc.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,39 @@
+/* APPLE LOCAL file radar 5882266 */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+int GlobalInt2 = 0;
+
+id objc_assign_weak(id value, id *location) {
+ GlobalInt = 1;
+ *location = value;
+ return value;
+}
+
+id objc_read_weak(id *location) {
+ GlobalInt2 = 1;
+ return *location;
+}
+
+
+void (^__weak Henry)(void);
+
+int main(char *argc, char *argv[]) {
+ // an object should not be retained within a stack Block
+ void (^local)(void);
+ int i = 10;
+ Henry = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ local = Henry;
+ if (GlobalInt2 == 1) {
+ printf("%s: success\n", argv[0]);
+ exit(0);
+ }
+ else {
+ printf("%s: problem with weak write-barrier assignment of stack block\n", argv[0]);
+ }
+ exit(1);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgcivar.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgcivar.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgcivar.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-readweakgcivar.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,46 @@
+/* APPLE LOCAL file radar 5882266 */
+/* { dg-do run } */
+/* { dg-options "-mmacosx-version-min=10.5 -ObjC -fobjc-gc -framework Foundation" { target *-*-darwin* } } */
+
+#import <Foundation/Foundation.h>
+void * _NSConcreteStackBlock;
+
+int GlobalInt = 0;
+int GlobalInt2 = 0;
+
+id objc_assign_weak(id value, id *location) {
+ GlobalInt = 1;
+ *location = value;
+ return value;
+}
+
+id objc_read_weak(id *location) {
+ GlobalInt2 = 1;
+ return *location;
+}
+
+ at interface Foo : NSObject {
+ at public
+ void (^__weak ivar)(void);
+}
+ at end
+ at implementation Foo
+ at end
+
+
+int main(char *argc, char *argv[]) {
+ // an object should not be retained within a stack Block
+ int i = 0;
+ void (^local)(void);
+ Foo *foo = [[Foo alloc] init];
+ foo->ivar = ^ { | i | ++i; }; /* { dg-warning "has been deprecated in blocks" } */
+ local = foo->ivar;
+ if (GlobalInt2 == 1) {
+ printf("%s: success\n", argv[0]);
+ exit(0);
+ }
+ else {
+ printf("%s: problem with weak read of ivar\n", argv[0]);
+ }
+ exit(1);
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-return.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-return.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-return.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-return.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,47 @@
+/* APPLE LOCAL file radar 5732232 - blocks */
+/* { dg-do compile } */
+/* { dg-options "-fblocks" } */
+
+typedef void (^CL)(void);
+
+CL foo() {
+
+ short y;
+ short (^add1)(void) = ^{ return y+1; }; /* { dg-error "incompatible block pointer types initializing" } */
+
+ CL X = ^{if (2)
+ return;
+ return 1; /* { dg-error "void block should not return a value" } */
+ };
+
+ int (^Y) (void) = ^{ if (3)
+ return 1;
+ else
+ return; /* { dg-error "non-void block should return a value" } */
+ };
+
+ char *(^Z)(void) = ^{ if (3)
+ return "";
+ else
+ return (char*)0;
+ };
+
+ double (^A)(void) = ^ { if (1)
+ return (float)1.0;
+ else
+ if (2)
+ return (double)2.0; /* { dg-error "incompatible type returning" } */
+ return 1; /* { dg-error "incompatible type returning" } */
+ }; /* { dg-error "incompatible block pointer types initializing" } */
+ char *(^B)(void) =
+ ^{ if (3)
+ return "";
+ else
+ return 2; /* { dg-error "incompatible type returning" } */
+ /* { dg-warning "return makes pointer from integer without a cast" "" { target *-*-* } 40 } */
+ };
+
+ return ^{ return 1; }; /* { dg-error "incompatible block pointer types initializing" } */
+
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-stabs.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-stabs.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-stabs.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-stabs.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,8 @@
+/* APPLE LOCAL file blocks stabs 6034272 */
+/* { dg-do compile } */
+/* { dg-options "-gstabs" } */
+
+void foo() {
+ void (^x)(void) = ^{ foo(); };
+ void *y = (void *)x;
+}
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-sync-compare-and-swap.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-sync-compare-and-swap.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-sync-compare-and-swap.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-sync-compare-and-swap.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,12 @@
+/* APPLE LOCAL file radar 6035389 */
+/* { dg-options "-Werror -fblocks" } */
+
+int print(const char *);
+
+int main()
+{
+ void (^b)(void);
+
+ __sync_bool_compare_and_swap(&b, (void*)0, ^{ print("hello\n"); });
+ return 0;
+};
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-parameter.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-parameter.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-parameter.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-parameter.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,12 @@
+/* APPLE LOCAL file radar 5925784 */
+/* Don't issue warning with -Wunused-parameter on '_self' parameter. */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-parameter" } */
+
+int main()
+{
+ int i = 1;
+ ^ { |i| i = 1; return i; }; /* { dg-warning "has been deprecated in blocks" } */
+ return 0;
+}
+
Added: llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-warn.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-warn.c?rev=55726&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-warn.c (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/gcc.apple/block-unused-warn.c Wed Sep 3 15:48:23 2008
@@ -0,0 +1,17 @@
+/* APPLE LOCAL file radar 5834569 */
+/* Do not issue unused variable warning on blocks. */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int main()
+{
+int x = 10;
+int y = 1;
+
+int (^myBlock)(void) = ^{ |x| return x+y; }; /* { dg-warning "has been deprecated in blocks" } */
+
+myBlock();
+
+return 0;
+}
+
More information about the llvm-commits
mailing list