blob: 64addd9d75b6ef427831811f49fc4a854a60d8b5 [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
Bill Wendling50cac242020-02-24 18:32:50 -08004struct S {
5 ~S();
Jennifer Yub8fee672019-06-03 15:57:25 +00006 int f(int);
7private:
8 int k;
9};
Bill Wendling50cac242020-02-24 18:32:50 -080010void test1(int n) {
Jennifer Yub8fee672019-06-03 15:57:25 +000011// 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}}
Bill Wendling50cac242020-02-24 18:32:50 -080014 S s1;
Jennifer Yub8fee672019-06-03 15:57:25 +000015
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}}
Bill Wendling50cac242020-02-24 18:32:50 -080020 S s2;
Jennifer Yub8fee672019-06-03 15:57:25 +000021// expected-note@+1 {{possible target of asm goto statement}}
22Later:
23 return;
24}
25
Bill Wendling50cac242020-02-24 18:32:50 -080026struct T { ~T(); };
27void test2(int a) {
Jennifer Yub8fee672019-06-03 15:57:25 +000028 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}}
Bill Wendling50cac242020-02-24 18:32:50 -080032 T t;
Jennifer Yub8fee672019-06-03 15:57:25 +000033 void *p = &&BAR;
34// expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}}
Bill Wendling50cac242020-02-24 18:32:50 -080035 asm goto("jmp %l0;" ::::BAR);
Jennifer Yub8fee672019-06-03 15:57:25 +000036// 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
Bill Wendling50cac242020-02-24 18:32:50 -080048int test3(int n)
Jennifer Yub8fee672019-06-03 15:57:25 +000049{
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@+2 {{jump bypasses initialization of variable length array}}
54 // expected-note@+1 {{possible target of asm goto statement}}
55 return ({int a[n];label_true: 2;});
56 // expected-note@+1 {{jump bypasses initialization of variable length array}}
57 int b[n];
58// expected-note@+1 {{possible target of asm goto statement}}
59loop:
60 return 0;
61}