1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s 2f4a2713aSLionel Sambuc// rdar://9535237 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuctypedef struct dispatch_queue_s *dispatch_queue_t; 5f4a2713aSLionel Sambuc 6f4a2713aSLionel Sambuctypedef void (^dispatch_block_t)(void); 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambucvoid dispatch_async(dispatch_queue_t queue, dispatch_block_t block); 9f4a2713aSLionel Sambuc 10f4a2713aSLionel Sambucextern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_main_q; 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambuc@interface SwitchBlockCrashAppDelegate 13f4a2713aSLionel Sambuc- (void)pageLeft; 14f4a2713aSLionel Sambuc- (void)pageRight;; 15f4a2713aSLionel Sambuc@end 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc@implementation SwitchBlockCrashAppDelegate 18f4a2713aSLionel Sambuc 19f4a2713aSLionel Sambuc- (void)choose:(int)button { 20f4a2713aSLionel Sambuc switch (button) { 21f4a2713aSLionel Sambuc case 0: 22f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); // expected-note 3 {{jump enters lifetime of block which strongly captures a variable}} 23f4a2713aSLionel Sambuc break; 24*0a6a1f1dSLionel Sambuc case 2: // expected-error {{cannot jump}} 25f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); // expected-note 2 {{jump enters lifetime of block which strongly captures a variable}} 26f4a2713aSLionel Sambuc break; 27*0a6a1f1dSLionel Sambuc case 3: // expected-error {{cannot jump}} 28f4a2713aSLionel Sambuc { 29f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); 30f4a2713aSLionel Sambuc break; 31f4a2713aSLionel Sambuc } 32*0a6a1f1dSLionel Sambuc case 4: // expected-error {{cannot jump}} 33f4a2713aSLionel Sambuc break; 34f4a2713aSLionel Sambuc } 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc __block SwitchBlockCrashAppDelegate *captured_block_obj; 37f4a2713aSLionel Sambuc switch (button) { 38f4a2713aSLionel Sambuc case 10: 39f4a2713aSLionel Sambuc { 40f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); 41f4a2713aSLionel Sambuc break; 42f4a2713aSLionel Sambuc } 43f4a2713aSLionel Sambuc case 12: 44f4a2713aSLionel Sambuc if (button) 45f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [captured_block_obj pageRight]; }); 46f4a2713aSLionel Sambuc break; 47f4a2713aSLionel Sambuc case 13: 48f4a2713aSLionel Sambuc while (button) 49f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); 50f4a2713aSLionel Sambuc break; 51f4a2713aSLionel Sambuc case 14: 52f4a2713aSLionel Sambuc break; 53f4a2713aSLionel Sambuc } 54f4a2713aSLionel Sambuc 55f4a2713aSLionel Sambuc switch (button) { 56f4a2713aSLionel Sambuc case 10: 57f4a2713aSLionel Sambuc { 58f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); 59f4a2713aSLionel Sambuc break; 60f4a2713aSLionel Sambuc } 61f4a2713aSLionel Sambuc case 12: 62f4a2713aSLionel Sambuc if (button) 63f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); 64f4a2713aSLionel Sambuc switch (button) { 65f4a2713aSLionel Sambuc case 0: 66f4a2713aSLionel Sambuc { 67f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); 68f4a2713aSLionel Sambuc break; 69f4a2713aSLionel Sambuc } 70f4a2713aSLionel Sambuc case 4: 71f4a2713aSLionel Sambuc break; 72f4a2713aSLionel Sambuc } 73f4a2713aSLionel Sambuc break; 74f4a2713aSLionel Sambuc case 13: 75f4a2713aSLionel Sambuc while (button) 76f4a2713aSLionel Sambuc dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); 77f4a2713aSLionel Sambuc break; 78f4a2713aSLionel Sambuc case 14: 79f4a2713aSLionel Sambuc break; 80f4a2713aSLionel Sambuc } 81f4a2713aSLionel Sambuc} 82f4a2713aSLionel Sambuc- (void)pageLeft {} 83f4a2713aSLionel Sambuc- (void)pageRight {} 84f4a2713aSLionel Sambuc@end 85f4a2713aSLionel Sambuc 86f4a2713aSLionel Sambuc// Test 2. rdar://problem/11150919 87*0a6a1f1dSLionel Sambucint test2(id obj, int state) { // expected-note {{jump enters lifetime of block}} FIXME: weird location 88f4a2713aSLionel Sambuc switch (state) { 89f4a2713aSLionel Sambuc case 0: 90f4a2713aSLionel Sambuc (void) ^{ (void) obj; }; 91f4a2713aSLionel Sambuc return 0; 92f4a2713aSLionel Sambuc 93*0a6a1f1dSLionel Sambuc default: // expected-error {{cannot jump}} 94f4a2713aSLionel Sambuc return 1; 95f4a2713aSLionel Sambuc } 96f4a2713aSLionel Sambuc} 97f4a2713aSLionel Sambuc 98