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