diff options
Diffstat (limited to 'clang/test/Sema')
-rw-r--r-- | clang/test/Sema/asm-goto.cpp | 45 | ||||
-rw-r--r-- | clang/test/Sema/asm.c | 21 | ||||
-rw-r--r-- | clang/test/Sema/inline-asm-validate-tmpl.cpp | 10 | ||||
-rw-r--r-- | clang/test/Sema/scope-check.c | 16 |
4 files changed, 92 insertions, 0 deletions
diff --git a/clang/test/Sema/asm-goto.cpp b/clang/test/Sema/asm-goto.cpp new file mode 100644 index 00000000000..f61a8096b83 --- /dev/null +++ b/clang/test/Sema/asm-goto.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only + +struct NonTrivial { + ~NonTrivial(); + int f(int); +private: + int k; +}; +void JumpDiagnostics(int n) { +// expected-error@+1 {{cannot jump from this goto statement to its label}} + goto DirectJump; +// expected-note@+1 {{jump bypasses variable with a non-trivial destructor}} + NonTrivial tnp1; + +DirectJump: +// expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} + asm goto("jmp %l0;" ::::Later); +// expected-note@+1 {{jump bypasses variable with a non-trivial destructor}} + NonTrivial tnp2; +// expected-note@+1 {{possible target of asm goto statement}} +Later: + return; +} + +struct S { ~S(); }; +void foo(int a) { + if (a) { +FOO: +// expected-note@+2 {{jump exits scope of variable with non-trivial destructor}} +// expected-note@+1 {{jump exits scope of variable with non-trivial destructor}} + S s; + void *p = &&BAR; +// expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} + asm goto("jmp %l0;" ::::BAR); +// expected-error@+1 {{cannot jump from this indirect goto statement to one of its possible targets}} + goto *p; + p = &&FOO; + goto *p; + return; + } +// expected-note@+2 {{possible target of asm goto statement}} +// expected-note@+1 {{possible target of indirect goto statement}} +BAR: + return; +} diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c index 67da197426c..29a55c610de 100644 --- a/clang/test/Sema/asm.c +++ b/clang/test/Sema/asm.c @@ -295,3 +295,24 @@ int test17(int t0) return r0 + r1; } +void test18() +{ + // expected-error@+2 {{duplicate use of asm operand name "lab"}} + // expected-note@+1 {{asm operand name "lab" first referenced here}} + asm goto ("" : : : : lab, lab, lab2, lab); + // expected-error@+2 {{duplicate use of asm operand name "lab"}} + // expected-note@+1 {{asm operand name "lab" first referenced here}} + asm goto ("xorw %[lab], %[lab]; je %l[lab]" : : [lab] "i" (0) : : lab); +lab:; +lab2:; + int x,x1; + // expected-error@+2 {{duplicate use of asm operand name "lab"}} + // expected-note@+1 {{asm operand name "lab" first referenced here}} + asm ("" : [lab] "=r" (x),[lab] "+r" (x) : [lab1] "r" (x)); + // expected-error@+2 {{duplicate use of asm operand name "lab"}} + // expected-note@+1 {{asm operand name "lab" first referenced here}} + asm ("" : [lab] "=r" (x1) : [lab] "r" (x)); + // expected-error@+1 {{invalid operand number in inline asm string}} + asm ("jne %l0":::); + asm goto ("jne %l0"::::lab); +} diff --git a/clang/test/Sema/inline-asm-validate-tmpl.cpp b/clang/test/Sema/inline-asm-validate-tmpl.cpp index cf7eac3d83d..9e234caa9c8 100644 --- a/clang/test/Sema/inline-asm-validate-tmpl.cpp +++ b/clang/test/Sema/inline-asm-validate-tmpl.cpp @@ -23,3 +23,13 @@ template <int N> void testc(int value) asm("rol %1, %0" :"=r"(value): "I"(N + 1)); } int foo() { testc<2>(10); } + +// these should compile without error +template <int N> bool testd() +{ + __asm goto ("" : : : : lab); + return true; +lab: + return false; +} +bool foox() { return testd<0> (); } diff --git a/clang/test/Sema/scope-check.c b/clang/test/Sema/scope-check.c index fa37d10d070..0622450e2e7 100644 --- a/clang/test/Sema/scope-check.c +++ b/clang/test/Sema/scope-check.c @@ -232,3 +232,19 @@ void test15(int n, void *pc) { // rdar://9024687 int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}} + +//Asm goto: +int test16(int n) +{ + // expected-error@+2 {{cannot jump from this asm goto statement to one of its possible targets}} + // expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} + asm volatile goto("testl %0, %0; jne %l1;" :: "r"(n)::label_true, loop); + // expected-note@+2 {{jump bypasses initialization of variable length array}} + // expected-note@+1 {{possible target of asm goto statement}} + return ({int a[n];label_true: 2;}); + // expected-note@+1 {{jump bypasses initialization of variable length array}} + int b[n]; +// expected-note@+1 {{possible target of asm goto statement}} +loop: + return 0; +} |