1 // RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only
2 // RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -verify -fsyntax-only
3
4 struct S {
5 ~S();
6 int f(int);
7 private:
8 int k;
9 };
test1(int n)10 void test1(int n) {
11 // expected-error@+1 {{cannot jump from this goto statement to its label}}
12 goto DirectJump;
13 // expected-note@+1 {{jump bypasses variable with a non-trivial destructor}}
14 S s1;
15
16 DirectJump:
17 // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}}
18 asm goto("jmp %l0;" ::::Later);
19 // expected-note@+1 {{jump bypasses variable with a non-trivial destructor}}
20 S s2;
21 // expected-note@+1 {{possible target of asm goto statement}}
22 Later:
23 return;
24 }
25
26 struct T { ~T(); };
test2(int a)27 void test2(int a) {
28 if (a) {
29 FOO:
30 // expected-note@+2 {{jump exits scope of variable with non-trivial destructor}}
31 // expected-note@+1 {{jump exits scope of variable with non-trivial destructor}}
32 T t;
33 void *p = &&BAR;
34 // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}}
35 asm goto("jmp %l0;" ::::BAR);
36 // expected-error@+1 {{cannot jump from this indirect goto statement to one of its possible targets}}
37 goto *p;
38 p = &&FOO;
39 goto *p;
40 return;
41 }
42 // expected-note@+2 {{possible target of asm goto statement}}
43 // expected-note@+1 {{possible target of indirect goto statement}}
44 BAR:
45 return;
46 }
47
test3(int n)48 int test3(int n)
49 {
50 // expected-error@+2 {{cannot jump from this asm goto statement to one of its possible targets}}
51 // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}}
52 asm volatile goto("testl %0, %0; jne %l1;" :: "r"(n)::label_true, loop);
53 // expected-note@+3 {{jump bypasses initialization of variable length array}}
54 // expected-note@+2 {{possible target of asm goto statement}}
55 // expected-note@+1 {{jump enters a statement expression}}
56 return ({int a[n];label_true: 2;});
57 // expected-note@+1 {{jump bypasses initialization of variable length array}}
58 int b[n];
59 // expected-note@+1 {{possible target of asm goto statement}}
60 loop:
61 return 0;
62 }
63
64 void test4cleanup(int*);
65 // No errors expected.
test4(void)66 void test4(void) {
67 asm goto(""::::l0);
68 l0:;
69 int x __attribute__((cleanup(test4cleanup)));
70 asm goto(""::::l1);
71 l1:;
72 }
73
statement_expressions()74 void statement_expressions() {
75 ({
76 __label__ label;
77 asm goto("" : : : : label);
78 label:;
79 });
80
81 ({
82 __label__ label;
83 asm goto("" : : : : label);
84 label:;
85 });
86 }
87