Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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 | |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 4 | struct S { |
| 5 | ~S(); |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 6 | int f(int); |
| 7 | private: |
| 8 | int k; |
| 9 | }; |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 10 | void test1(int n) { |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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}} |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 14 | S s1; |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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}} |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 20 | S s2; |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 21 | // expected-note@+1 {{possible target of asm goto statement}} |
| 22 | Later: |
| 23 | return; |
| 24 | } |
| 25 | |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 26 | struct T { ~T(); }; |
| 27 | void test2(int a) { |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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}} |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 32 | T t; |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 33 | void *p = &&BAR; |
| 34 | // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 35 | asm goto("jmp %l0;" ::::BAR); |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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 | |
Bill Wendling | 50cac24 | 2020-02-24 18:32:50 -0800 | [diff] [blame] | 48 | int test3(int n) |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 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@+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}} |
| 59 | loop: |
| 60 | return 0; |
| 61 | } |