1 // RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only
7 asm ("foo\n" : : "a" (i + 2));
8 asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}}
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}}
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}}
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}}
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");
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}}
46 asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
47 asm("foo" : L"=r"(x)); // expected-error {{wide string}}
50 // <rdar://problem/6156893>
51 void test4(const volatile void *addr)
53 asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}}
54 asm ("nop" : : "m"(*addr));
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'}}
59 asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
62 // <rdar://problem/6512595>
64 asm("nop" : : "X" (8));
69 asm("nop" : : "er"(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}}
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}}
83 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
84 asm("%1" : "+r"(i)); // ok, referring to input.
88 int test7(unsigned long long b) {
90 asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
94 // <rdar://problem/7574870>
95 asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}}
99 // A number in an input constraint can't point to a read-write constraint.
100 asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}}
105 asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}}
106 asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}}
110 static int g asm ("g_asm") = 0;
111 extern int gg asm ("gg_asm");
112 __private_extern__ int ggg asm ("ggg_asm");
114 int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}}
115 auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}}
117 register int r asm ("cx");
118 register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}}
119 register int rrr asm ("%"); // expected-error{{unknown register name '%' in asm}}
122 // This is just an assert because of the boolean conversion.
123 // Feel free to change the assembly to something sensible if it causes a problem.
124 // rdar://problem/9414925
127 asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
131 register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
137 __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}
140 // <rdar://problem/12700799>
141 struct S; // expected-note 2 {{forward declaration of 'struct S'}}
142 void test14(struct S *s) {
143 __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
144 __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
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":"+*"(ret)); // expected-error {{invalid output constraint '+*' in asm}}
156 __asm("0.0":"=%"(ret)); // expected-error {{invalid output constraint '=%' in asm}}
157 __asm("0.0":"=,="(ret)); // expected-error {{invalid output constraint '=,=' in asm}}
158 __asm("0.0":"=,g"(ret)); // no-error
159 __asm("0.0":"=g"(ret)); // no-error
167 register struct foo bar asm("esp"); // expected-error {{bad type for named register variable}}
168 register float baz asm("esp"); // expected-error {{bad type for named register variable}}
170 register int r0 asm ("edi"); // expected-error {{register 'edi' unsuitable for global register variables on this target}}
171 register long long r1 asm ("esp"); // expected-error {{size of register 'esp' does not match variable size}}
172 register int r2 asm ("esp");
174 double f_output_constraint(void) {
176 __asm("foo1": "=f" (result)); // expected-error {{invalid output constraint '=f' in asm}}
184 : "[l],m"(l)); // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}}
190 : "+&m"(l)); // expected-error {{invalid output constraint '+&m' in asm}}
196 : "+#r"(l)); // expected-error {{invalid output constraint '+#r' in asm}}
210 : "[g]"(l)); // expected-error {{invalid input constraint '[g]' in asm}}
217 : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}}
221 typedef struct test16_foo {
222 unsigned int field1 : 1;
223 unsigned int field2 : 2;
224 unsigned int field3 : 3;
226 typedef __attribute__((vector_size(16))) int test16_bar;
227 register int test16_baz asm("esp");
234 __asm__("movl $5, %0"
235 : "=rm" (a.field2)); // expected-error {{reference to a bit-field in asm input with a memory constraint '=rm'}}
236 __asm__("movl $5, %0"
238 : "m" (a.field3)); // expected-error {{reference to a bit-field in asm output with a memory constraint 'm'}}
239 __asm__("movl $5, %0"
240 : "=rm" (b[2])); // expected-error {{reference to a vector element in asm input with a memory constraint '=rm'}}
241 __asm__("movl $5, %0"
243 : "m" (b[3])); // expected-error {{reference to a vector element in asm output with a memory constraint 'm'}}
244 __asm__("movl $5, %0"
245 : "=rm" (test16_baz)); // expected-error {{reference to a global register variable in asm input with a memory constraint '=rm'}}
246 __asm__("movl $5, %0"
248 : "m" (test16_baz)); // expected-error {{reference to a global register variable in asm output with a memory constraint 'm'}}
254 __asm ("addl %2, %2\n\t"
258 : "1" (t0), // expected-note {{constraint '1' is already present here}}
259 "1" (t0)); // expected-error {{more than one input constraint matches the same output '1'}}