87 lines · cpp
1// RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only2// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -verify -fsyntax-only3 4struct S {5 ~S();6 int f(int);7private:8 int k;9};10void 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 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 S s2;21// expected-note@+1 {{possible target of asm goto statement}}22Later:23 return;24}25 26struct T { ~T(); };27void test2(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 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}}44BAR:45 return;46}47 48int 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}}60loop:61 return 0;62}63 64void test4cleanup(int*);65// No errors expected.66void test4(void) {67 asm goto(""::::l0);68l0:;69 int x __attribute__((cleanup(test4cleanup)));70 asm goto(""::::l1);71l1:;72}73 74void 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