blob: d85730974359c719092c9c00d2c11684c93ed7d3 [file] [log] [blame]
Jennifer Yub8fee672019-06-03 15:57:25 +00001// 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
4struct NonTrivial {
5 ~NonTrivial();
6 int f(int);
7private:
8 int k;
9};
10void JumpDiagnostics(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 NonTrivial tnp1;
15
16DirectJump:
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 NonTrivial tnp2;
21// expected-note@+1 {{possible target of asm goto statement}}
22Later:
23 return;
24}
25
26struct S { ~S(); };
27void foo(int a) {
28 if (a) {
29FOO:
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 S s;
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}}
44BAR:
45 return;
46}
47
48
49//Asm goto:
50int test16(int n)
51{
52 // expected-error@+2 {{cannot jump from this asm goto statement to one of its possible targets}}
53 // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}}
54 asm volatile goto("testl %0, %0; jne %l1;" :: "r"(n)::label_true, loop);
55 // expected-note@+2 {{jump bypasses initialization of variable length array}}
56 // expected-note@+1 {{possible target of asm goto statement}}
57 return ({int a[n];label_true: 2;});
58 // expected-note@+1 {{jump bypasses initialization of variable length array}}
59 int b[n];
60// expected-note@+1 {{possible target of asm goto statement}}
61loop:
62 return 0;
63}