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