xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/captured-statements.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
2*f4a2713aSLionel Sambuc 
test_gotos()3*f4a2713aSLionel Sambuc void test_gotos() {
4*f4a2713aSLionel Sambuc   goto L1; // expected-error {{use of undeclared label 'L1'}}
5*f4a2713aSLionel Sambuc   goto L3; // OK
6*f4a2713aSLionel Sambuc   #pragma clang __debug captured
7*f4a2713aSLionel Sambuc   {
8*f4a2713aSLionel Sambuc L1:
9*f4a2713aSLionel Sambuc     goto L2; // OK
10*f4a2713aSLionel Sambuc L2:
11*f4a2713aSLionel Sambuc     goto L3; // expected-error {{use of undeclared label 'L3'}}
12*f4a2713aSLionel Sambuc   }
13*f4a2713aSLionel Sambuc L3: ;
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc 
test_break_continue()16*f4a2713aSLionel Sambuc void test_break_continue() {
17*f4a2713aSLionel Sambuc   while (1) {
18*f4a2713aSLionel Sambuc     #pragma clang __debug captured
19*f4a2713aSLionel Sambuc     {
20*f4a2713aSLionel Sambuc       break; // expected-error {{'break' statement not in loop or switch statement}}
21*f4a2713aSLionel Sambuc       continue; // expected-error {{'continue' statement not in loop statement}}
22*f4a2713aSLionel Sambuc     }
23*f4a2713aSLionel Sambuc   }
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc 
test_return()26*f4a2713aSLionel Sambuc void test_return() {
27*f4a2713aSLionel Sambuc   while (1) {
28*f4a2713aSLionel Sambuc     #pragma clang __debug captured
29*f4a2713aSLionel Sambuc     {
30*f4a2713aSLionel Sambuc       return; // expected-error {{cannot return from default captured statement}}
31*f4a2713aSLionel Sambuc     }
32*f4a2713aSLionel Sambuc   }
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc 
test_nest()35*f4a2713aSLionel Sambuc void test_nest() {
36*f4a2713aSLionel Sambuc   int x;
37*f4a2713aSLionel Sambuc   #pragma clang __debug captured
38*f4a2713aSLionel Sambuc   {
39*f4a2713aSLionel Sambuc     int y;
40*f4a2713aSLionel Sambuc     #pragma clang __debug captured
41*f4a2713aSLionel Sambuc     {
42*f4a2713aSLionel Sambuc       int z;
43*f4a2713aSLionel Sambuc       #pragma clang __debug captured
44*f4a2713aSLionel Sambuc       {
45*f4a2713aSLionel Sambuc         x = z = y; // OK
46*f4a2713aSLionel Sambuc       }
47*f4a2713aSLionel Sambuc     }
48*f4a2713aSLionel Sambuc   }
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc 
test_nest_block()51*f4a2713aSLionel Sambuc void test_nest_block() {
52*f4a2713aSLionel Sambuc   __block int x; // expected-note {{'x' declared here}}
53*f4a2713aSLionel Sambuc   int y;
54*f4a2713aSLionel Sambuc   ^{
55*f4a2713aSLionel Sambuc     int z;
56*f4a2713aSLionel Sambuc     #pragma clang __debug captured
57*f4a2713aSLionel Sambuc     {
58*f4a2713aSLionel Sambuc       x = y; // expected-error{{__block variable 'x' cannot be captured in a captured statement}}
59*f4a2713aSLionel Sambuc       y = z; // expected-error{{variable is not assignable (missing __block type specifier)}}
60*f4a2713aSLionel Sambuc       z = y; // OK
61*f4a2713aSLionel Sambuc     }
62*f4a2713aSLionel Sambuc   }();
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc   __block int a; // expected-note 2 {{'a' declared here}}
65*f4a2713aSLionel Sambuc   int b;
66*f4a2713aSLionel Sambuc   #pragma clang __debug captured
67*f4a2713aSLionel Sambuc   {
68*f4a2713aSLionel Sambuc     __block int c;
69*f4a2713aSLionel Sambuc     int d;
70*f4a2713aSLionel Sambuc     ^{
71*f4a2713aSLionel Sambuc       a = b; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
72*f4a2713aSLionel Sambuc       b = d; // OK - Consistent with block inside a lambda
73*f4a2713aSLionel Sambuc       c = a; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
74*f4a2713aSLionel Sambuc       c = d; // OK
75*f4a2713aSLionel Sambuc       d = b; // expected-error{{variable is not assignable (missing __block type specifier)}}
76*f4a2713aSLionel Sambuc     }();
77*f4a2713aSLionel Sambuc   }
78*f4a2713aSLionel Sambuc }
79