1 // RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only
2
3
f()4 void f() {
5 int i;
6
7 asm ("foo\n" : : "a" (i + 2));
8 asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}}
9
10 asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}}
11 asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
12
13 asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i));
14 asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}}
15 asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}}
16 asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
17
18 asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}}
19 asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}}
20 }
21
clobbers()22 void clobbers() {
23 asm ("nop" : : : "ax", "#ax", "%ax");
24 asm ("nop" : : : "eax", "rax", "ah", "al");
25 asm ("nop" : : : "0", "%0", "#0");
26 asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}}
27 asm ("nop" : : : "52");
28 asm ("nop" : : : "204"); // expected-error {{unknown register name '204' in asm}}
29 asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
30 asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
31 register void *clobber_conflict asm ("%rcx");
32 register void *no_clobber_conflict asm ("%rax");
33 int a,b,c;
34 asm ("nop" : "=r" (no_clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
35 asm ("nop" : "=r" (clobber_conflict) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
36 asm ("nop" : "=r" (clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
37 asm ("nop" : "=c" (a) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
38 asm ("nop" : "=r" (no_clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
39 asm ("nop" : "=r" (clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
40 asm ("nop" : "=a" (a) : "b" (b) : "%rcx", "%rbx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
41 }
42
43 // rdar://6094010
test3()44 void test3() {
45 int x;
46 asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
47 asm("foo" : L"=r"(x)); // expected-error {{wide string}}
48 }
49
50 // <rdar://problem/6156893>
test4(const volatile void * addr)51 void test4(const volatile void *addr)
52 {
53 asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}}
54 asm ("nop" : : "m"(*addr));
55
56 asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}}
57 asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
58
59 asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
60 }
61
62 // <rdar://problem/6512595>
test5()63 void test5() {
64 asm("nop" : : "X" (8));
65 }
66
67 // PR3385
test6(long i)68 void test6(long i) {
69 asm("nop" : : "er"(i));
70 }
71
asm_string_tests(int i)72 void asm_string_tests(int i) {
73 asm("%!"); // simple asm string, %! is not an error.
74 asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
75 asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}}
76
77 asm ("%[somename]" :: [somename] "i"(4)); // ok
78 asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}}
79 asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}}
80 asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}}
81
82 // PR3258
83 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
84 asm("%1" : "+r"(i)); // ok, referring to input.
85 }
86
87 // PR4077
test7(unsigned long long b)88 int test7(unsigned long long b) {
89 int a;
90 asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
91 return a;
92 }
93
94 // PR3904
test8(int i)95 void test8(int i) {
96 // A number in an input constraint can't point to a read-write constraint.
97 asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}}
98 }
99
100 // PR3905
test9(int i)101 void test9(int i) {
102 asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}}
103 asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}}
104 }
105
test10(void)106 void test10(void){
107 static int g asm ("g_asm") = 0;
108 extern int gg asm ("gg_asm");
109 __private_extern__ int ggg asm ("ggg_asm");
110
111 int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}}
112 auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}}
113
114 register int r asm ("cx");
115 register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}}
116 register int rrr asm ("%"); // expected-error{{unknown register name '%' in asm}}
117 }
118
119 // This is just an assert because of the boolean conversion.
120 // Feel free to change the assembly to something sensible if it causes a problem.
121 // rdar://problem/9414925
test11(void)122 void test11(void) {
123 _Bool b;
124 asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
125 }
126
test12(void)127 void test12(void) {
128 register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
129 }
130
131 // PR10223
test13(void)132 void test13(void) {
133 void *esp;
134 __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}
135 }
136
137 // <rdar://problem/12700799>
138 struct S; // expected-note 2 {{forward declaration of 'struct S'}}
test14(struct S * s)139 void test14(struct S *s) {
140 __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
141 __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
142 }
143
144 // PR15759.
test15()145 double test15() {
146 double ret = 0;
147 __asm("0.0":"="(ret)); // expected-error {{invalid output constraint '=' in asm}}
148 __asm("0.0":"=&"(ret)); // expected-error {{invalid output constraint '=&' in asm}}
149 __asm("0.0":"+?"(ret)); // expected-error {{invalid output constraint '+?' in asm}}
150 __asm("0.0":"+!"(ret)); // expected-error {{invalid output constraint '+!' in asm}}
151 __asm("0.0":"+#"(ret)); // expected-error {{invalid output constraint '+#' in asm}}
152 __asm("0.0":"+*"(ret)); // expected-error {{invalid output constraint '+*' in asm}}
153 __asm("0.0":"=%"(ret)); // expected-error {{invalid output constraint '=%' in asm}}
154 __asm("0.0":"=,="(ret)); // expected-error {{invalid output constraint '=,=' in asm}}
155 __asm("0.0":"=,g"(ret)); // no-error
156 __asm("0.0":"=g"(ret)); // no-error
157 return ret;
158 }
159
iOutputConstraint(int x)160 void iOutputConstraint(int x){
161 __asm ("nop" : "=ir" (x) : :); // no-error
162 __asm ("nop" : "=ri" (x) : :); // no-error
163 __asm ("nop" : "=ig" (x) : :); // no-error
164 __asm ("nop" : "=im" (x) : :); // no-error
165 __asm ("nop" : "=imr" (x) : :); // no-error
166 __asm ("nop" : "=i" (x) : :); // expected-error{{invalid output constraint '=i' in asm}}
167 __asm ("nop" : "+i" (x) : :); // expected-error{{invalid output constraint '+i' in asm}}
168 __asm ("nop" : "=ii" (x) : :); // expected-error{{invalid output constraint '=ii' in asm}}
169 __asm ("nop" : "=nr" (x) : :); // no-error
170 __asm ("nop" : "=rn" (x) : :); // no-error
171 __asm ("nop" : "=ng" (x) : :); // no-error
172 __asm ("nop" : "=nm" (x) : :); // no-error
173 __asm ("nop" : "=nmr" (x) : :); // no-error
174 __asm ("nop" : "=n" (x) : :); // expected-error{{invalid output constraint '=n' in asm}}
175 __asm ("nop" : "+n" (x) : :); // expected-error{{invalid output constraint '+n' in asm}}
176 __asm ("nop" : "=nn" (x) : :); // expected-error{{invalid output constraint '=nn' in asm}}
177 __asm ("nop" : "=Fr" (x) : :); // no-error
178 __asm ("nop" : "=rF" (x) : :); // no-error
179 __asm ("nop" : "=Fg" (x) : :); // no-error
180 __asm ("nop" : "=Fm" (x) : :); // no-error
181 __asm ("nop" : "=Fmr" (x) : :); // no-error
182 __asm ("nop" : "=F" (x) : :); // expected-error{{invalid output constraint '=F' in asm}}
183 __asm ("nop" : "+F" (x) : :); // expected-error{{invalid output constraint '+F' in asm}}
184 __asm ("nop" : "=FF" (x) : :); // expected-error{{invalid output constraint '=FF' in asm}}
185 __asm ("nop" : "=Er" (x) : :); // no-error
186 __asm ("nop" : "=rE" (x) : :); // no-error
187 __asm ("nop" : "=Eg" (x) : :); // no-error
188 __asm ("nop" : "=Em" (x) : :); // no-error
189 __asm ("nop" : "=Emr" (x) : :); // no-error
190 __asm ("nop" : "=E" (x) : :); // expected-error{{invalid output constraint '=E' in asm}}
191 __asm ("nop" : "+E" (x) : :); // expected-error{{invalid output constraint '+E' in asm}}
192 __asm ("nop" : "=EE" (x) : :); // expected-error{{invalid output constraint '=EE' in asm}}
193 }
194
195 // PR19837
196 struct foo {
197 int a;
198 };
199 register struct foo bar asm("esp"); // expected-error {{bad type for named register variable}}
200 register float baz asm("esp"); // expected-error {{bad type for named register variable}}
201
202 register int r0 asm ("edi"); // expected-error {{register 'edi' unsuitable for global register variables on this target}}
203 register long long r1 asm ("esp"); // expected-error {{size of register 'esp' does not match variable size}}
204 register int r2 asm ("esp");
205
f_output_constraint(void)206 double f_output_constraint(void) {
207 double result;
208 __asm("foo1": "=f" (result)); // expected-error {{invalid output constraint '=f' in asm}}
209 return result;
210 }
211
fn1()212 void fn1() {
213 int l;
214 __asm__(""
215 : [l] "=r"(l)
216 : "[l],m"(l)); // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}}
217 }
218
fn2()219 void fn2() {
220 int l;
221 __asm__(""
222 : "+&m"(l)); // expected-error {{invalid output constraint '+&m' in asm}}
223 }
224
fn3()225 void fn3() {
226 int l;
227 __asm__(""
228 : "+#r"(l)); // expected-error {{invalid output constraint '+#r' in asm}}
229 }
230
fn4()231 void fn4() {
232 int l;
233 __asm__(""
234 : "=r"(l)
235 : "m#"(l));
236 }
237
fn5()238 void fn5() {
239 int l;
240 __asm__(""
241 : [g] "+r"(l)
242 : "[g]"(l)); // expected-error {{invalid input constraint '[g]' in asm}}
243 }
244
fn6()245 void fn6() {
246 int a;
247 __asm__(""
248 : "=rm"(a), "=rm"(a)
249 : "11m"(a)); // expected-error {{invalid input constraint '11m' in asm}}
250 }
251
252 // PR14269
253 typedef struct test16_foo {
254 unsigned int field1 : 1;
255 unsigned int field2 : 2;
256 unsigned int field3 : 3;
257 } test16_foo;
258 typedef __attribute__((vector_size(16))) int test16_bar;
259 register int test16_baz asm("esp");
260
test16()261 void test16()
262 {
263 test16_foo a;
264 test16_bar b;
265
266 __asm__("movl $5, %0"
267 : "=rm" (a.field2)); // expected-error {{reference to a bit-field in asm input with a memory constraint '=rm'}}
268 __asm__("movl $5, %0"
269 :
270 : "m" (a.field3)); // expected-error {{reference to a bit-field in asm output with a memory constraint 'm'}}
271 __asm__("movl $5, %0"
272 : "=rm" (b[2])); // expected-error {{reference to a vector element in asm input with a memory constraint '=rm'}}
273 __asm__("movl $5, %0"
274 :
275 : "m" (b[3])); // expected-error {{reference to a vector element in asm output with a memory constraint 'm'}}
276 __asm__("movl $5, %0"
277 : "=rm" (test16_baz)); // expected-error {{reference to a global register variable in asm input with a memory constraint '=rm'}}
278 __asm__("movl $5, %0"
279 :
280 : "m" (test16_baz)); // expected-error {{reference to a global register variable in asm output with a memory constraint 'm'}}
281 }
282
test17(int t0)283 int test17(int t0)
284 {
285 int r0, r1;
286 __asm ("addl %2, %2\n\t"
287 "movl $123, %0"
288 : "=a" (r0),
289 "=&r" (r1)
290 : "1" (t0), // expected-note {{constraint '1' is already present here}}
291 "1" (t0)); // expected-error {{more than one input constraint matches the same output '1'}}
292 return r0 + r1;
293 }
294
test18()295 void test18()
296 {
297 // expected-error@+2 {{duplicate use of asm operand name "lab"}}
298 // expected-note@+1 {{asm operand name "lab" first referenced here}}
299 asm goto ("" : : : : lab, lab, lab2, lab);
300 // expected-error@+2 {{duplicate use of asm operand name "lab"}}
301 // expected-note@+1 {{asm operand name "lab" first referenced here}}
302 asm goto ("xorw %[lab], %[lab]; je %l[lab]" : : [lab] "i" (0) : : lab);
303 lab:;
304 lab2:;
305 int x,x1;
306 // expected-error@+2 {{duplicate use of asm operand name "lab"}}
307 // expected-note@+1 {{asm operand name "lab" first referenced here}}
308 asm ("" : [lab] "=r" (x),[lab] "+r" (x) : [lab1] "r" (x));
309 // expected-error@+2 {{duplicate use of asm operand name "lab"}}
310 // expected-note@+1 {{asm operand name "lab" first referenced here}}
311 asm ("" : [lab] "=r" (x1) : [lab] "r" (x));
312 // expected-error@+1 {{invalid operand number in inline asm string}}
313 asm ("jne %l0":::);
314 asm goto ("jne %l0"::::lab);
315 }
316