1 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s
3 
4 #if !__has_extension(gnu_asm)
5 #error Extension 'gnu_asm' should be available by default
6 #endif
7 #if !__has_extension(gnu_asm_goto_with_outputs)
8 #error Extension 'gnu_asm_goto_with_outputs' should be available by default
9 #endif
10 
11 int a, b, c, d, e, f, g, h, i, j, k, l;
12 
test(void)13 void test(void) {
14   __asm__ volatile goto (""
15             :: [a] "r" (a), [b] "r" (b), [c] "r" (c), [d] "r" (d),
16                [e] "r" (e), [f] "r" (f), [g] "r" (g), [h] "r" (h),
17                [i] "r" (i), [j] "r" (j), [k] "r" (k), [l] "r" (l)
18             ::lab1,lab2);
19 lab1: return;
20 lab2: return;
21 }
22 
test2(void)23 void test2(void) {
24   __asm__ volatile goto (""
25             :: [a] "r,m" (a), [b] "r,m" (b), [c] "r,m" (c), [d] "r,m" (d),
26                [e] "r,m" (e), [f] "r,m" (f), [g] "r,m" (g), [h] "r,m" (h),
27                [i] "r,m" (i), [j] "r,m" (j), [k] "r,m" (k), [l] "r,m" (l)
28             :: lab);
29   lab: return;
30 }
31 
test3(int x)32 int test3(int x) {
33   __asm__ volatile goto ("decl %0; jnz %l[a]"
34                          : "=r" (x) : "m" (x) : "memory" : a);
35 a:
36   return -x;
37 }
38 
test4(int x)39 int test4(int x) {
40   int y;
41   if (x > 42)
42     __asm__ volatile goto ("decl %0; jnz %l[a]"
43                            : "=r" (x), "=r" (y) : "m" (x) : "memory" : a);
44   else
45     __asm__ volatile goto ("decl %0; jnz %l[b]"
46                            : "=r" (x), "=r" (y) : "m" (x) : "memory" : b);
47   x = y + 42;
48 a:
49   return -x;
50 b:
51   return +x;
52 }
53 
test5(void)54 int test5(void) {
55   int x,cond,*e;
56   // expected-error@+1 {{expected ')'}}
57   asm ("mov %[e], %[e]" : : [e] "rm" (*e)::a)
58   // expected-error@+1 {{expected identifier}}
59   asm goto ("decl %0;" :: "m"(x) : "memory" : );
60   // expected-error@+1 {{expected ':'}}
61   asm goto ("decl %0;" :: "m"(x) : "memory" );
62   // expected-error@+1 {{use of undeclared label 'x'}}
63   asm goto ("decl %0;" :: "m"(x) : "memory" :x);
64   // expected-error@+1 {{use of undeclared label 'b'}}
65   asm goto ("decl %0;" :: "m"(x) : "memory" :b);
66   // expected-error@+1 {{invalid operand number in inline asm string}}
67   asm goto ("testl %0, %0; jne %l3;" :: "r"(cond)::label_true, loop);
68   // expected-error@+1 {{unknown symbolic operand name in inline assembly string}}
69   asm goto ("decl %0; jnz %l[b]" :: "m"(x) : "memory" : a);
70 a:
71 label_true:
72 loop:
73   return 0;
74 }
75 
test6(int y)76 int test6(int y) {
77   int x,cond,*e;
78   // expected-error@+1 {{expected ')'}}
79   asm ("mov %[e], %[e]" : "=r" (y) : [e] "rm" (*e), "r" (y) :: a)
80   // expected-error@+1 {{expected identifier}}
81   asm goto ("decl %0;" : "=r" (y) : "m" (x), "r" (y) : "memory" :);
82   // expected-error@+1  {{expected ':'}}
83   asm goto ("decl %0;" : "=r" (y) : "m" (x), "r" (y) : "memory");
84   // expected-error@+1 {{use of undeclared label 'x'}}
85   asm goto ("decl %0;" : "=r" (y) : "m" (x), "r" (y) : "memory" : x);
86   // expected-error@+1 {{use of undeclared label 'b'}}
87   asm goto ("decl %0;" : "=r" (y) : "m" (x), "r" (y) : "memory" : b);
88   // expected-error@+1 {{invalid operand number in inline asm string}}
89   asm goto ("testl %0, %0; jne %l5;" : "=r" (y) : "r" (cond), "r" (y) :: label_true, loop);
90   // expected-error@+1 {{unknown symbolic operand name in inline assembly string}}
91   asm goto ("decl %0; jnz %l[b]" : "=r" (y) : "m" (x), "r" (y) : "memory" : a);
92 label_true:
93 loop:
94 a:
95   return 0;
96 }
97