Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaObjC / arc-jump-block.m
blob64bf193c5836b9f2e42a28de8bd2ec5a82f0b20d
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
3 typedef struct dispatch_queue_s *dispatch_queue_t;
5 typedef void (^dispatch_block_t)(void);
7 void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
9 extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_main_q;
11 @interface SwitchBlockCrashAppDelegate
12 - (void)pageLeft;
13 - (void)pageRight;;
14 @end
16 @implementation SwitchBlockCrashAppDelegate
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     }
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     }
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     }
81 - (void)pageLeft {}
82 - (void)pageRight {}
83 @end
85 int 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;
91   default: // expected-error {{cannot jump}}
92     return 1;
93   }