1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only
2f4a2713aSLionel Sambuc
3*0a6a1f1dSLionel Sambuc
4*0a6a1f1dSLionel Sambuc
f()5f4a2713aSLionel Sambuc void f() {
6f4a2713aSLionel Sambuc int i;
7f4a2713aSLionel Sambuc
8f4a2713aSLionel Sambuc asm ("foo\n" : : "a" (i + 2));
9f4a2713aSLionel Sambuc asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}}
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}}
12f4a2713aSLionel Sambuc asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i));
15f4a2713aSLionel Sambuc asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}}
16f4a2713aSLionel Sambuc asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}}
17f4a2713aSLionel Sambuc asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
18*0a6a1f1dSLionel Sambuc
19*0a6a1f1dSLionel Sambuc asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}}
20*0a6a1f1dSLionel Sambuc asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}}
21f4a2713aSLionel Sambuc }
22f4a2713aSLionel Sambuc
clobbers()23f4a2713aSLionel Sambuc void clobbers() {
24f4a2713aSLionel Sambuc asm ("nop" : : : "ax", "#ax", "%ax");
25f4a2713aSLionel Sambuc asm ("nop" : : : "eax", "rax", "ah", "al");
26f4a2713aSLionel Sambuc asm ("nop" : : : "0", "%0", "#0");
27f4a2713aSLionel Sambuc asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}}
28f4a2713aSLionel Sambuc asm ("nop" : : : "52");
29f4a2713aSLionel Sambuc asm ("nop" : : : "104"); // expected-error {{unknown register name '104' in asm}}
30f4a2713aSLionel Sambuc asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
31f4a2713aSLionel Sambuc asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
32f4a2713aSLionel Sambuc }
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc // rdar://6094010
test3()35f4a2713aSLionel Sambuc void test3() {
36f4a2713aSLionel Sambuc int x;
37f4a2713aSLionel Sambuc asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
38f4a2713aSLionel Sambuc asm("foo" : L"=r"(x)); // expected-error {{wide string}}
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc
41f4a2713aSLionel Sambuc // <rdar://problem/6156893>
test4(const volatile void * addr)42f4a2713aSLionel Sambuc void test4(const volatile void *addr)
43f4a2713aSLionel Sambuc {
44f4a2713aSLionel Sambuc asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}}
45f4a2713aSLionel Sambuc asm ("nop" : : "m"(*addr));
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambuc asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}}
48f4a2713aSLionel Sambuc asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc
53f4a2713aSLionel Sambuc // <rdar://problem/6512595>
test5()54f4a2713aSLionel Sambuc void test5() {
55f4a2713aSLionel Sambuc asm("nop" : : "X" (8));
56f4a2713aSLionel Sambuc }
57f4a2713aSLionel Sambuc
58f4a2713aSLionel Sambuc // PR3385
test6(long i)59f4a2713aSLionel Sambuc void test6(long i) {
60f4a2713aSLionel Sambuc asm("nop" : : "er"(i));
61f4a2713aSLionel Sambuc }
62f4a2713aSLionel Sambuc
asm_string_tests(int i)63f4a2713aSLionel Sambuc void asm_string_tests(int i) {
64f4a2713aSLionel Sambuc asm("%!"); // simple asm string, %! is not an error.
65f4a2713aSLionel Sambuc asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
66f4a2713aSLionel Sambuc asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}}
67f4a2713aSLionel Sambuc
68f4a2713aSLionel Sambuc asm ("%[somename]" :: [somename] "i"(4)); // ok
69f4a2713aSLionel Sambuc asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}}
70f4a2713aSLionel Sambuc asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}}
71f4a2713aSLionel Sambuc asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}}
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc // PR3258
74f4a2713aSLionel Sambuc asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
75f4a2713aSLionel Sambuc asm("%1" : "+r"(i)); // ok, referring to input.
76f4a2713aSLionel Sambuc }
77f4a2713aSLionel Sambuc
78f4a2713aSLionel Sambuc // PR4077
test7(unsigned long long b)79f4a2713aSLionel Sambuc int test7(unsigned long long b) {
80f4a2713aSLionel Sambuc int a;
81f4a2713aSLionel Sambuc asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
82f4a2713aSLionel Sambuc return a;
83f4a2713aSLionel Sambuc }
84f4a2713aSLionel Sambuc
85f4a2713aSLionel Sambuc // <rdar://problem/7574870>
86f4a2713aSLionel Sambuc asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}}
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambuc // PR3904
test8(int i)89f4a2713aSLionel Sambuc void test8(int i) {
90f4a2713aSLionel Sambuc // A number in an input constraint can't point to a read-write constraint.
91f4a2713aSLionel Sambuc asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}}
92f4a2713aSLionel Sambuc }
93f4a2713aSLionel Sambuc
94f4a2713aSLionel Sambuc // PR3905
test9(int i)95f4a2713aSLionel Sambuc void test9(int i) {
96f4a2713aSLionel Sambuc asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}}
97f4a2713aSLionel Sambuc asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}}
98f4a2713aSLionel Sambuc }
99f4a2713aSLionel Sambuc
test10(void)100f4a2713aSLionel Sambuc void test10(void){
101f4a2713aSLionel Sambuc static int g asm ("g_asm") = 0;
102f4a2713aSLionel Sambuc extern int gg asm ("gg_asm");
103f4a2713aSLionel Sambuc __private_extern__ int ggg asm ("ggg_asm");
104f4a2713aSLionel Sambuc
105f4a2713aSLionel Sambuc int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}}
106f4a2713aSLionel Sambuc auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}}
107f4a2713aSLionel Sambuc
108f4a2713aSLionel Sambuc register int r asm ("cx");
109f4a2713aSLionel Sambuc register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}}
110*0a6a1f1dSLionel Sambuc register int rrr asm ("%"); // expected-error{{unknown register name '%' in asm}}
111f4a2713aSLionel Sambuc }
112f4a2713aSLionel Sambuc
113f4a2713aSLionel Sambuc // This is just an assert because of the boolean conversion.
114f4a2713aSLionel Sambuc // Feel free to change the assembly to something sensible if it causes a problem.
115f4a2713aSLionel Sambuc // rdar://problem/9414925
test11(void)116f4a2713aSLionel Sambuc void test11(void) {
117f4a2713aSLionel Sambuc _Bool b;
118f4a2713aSLionel Sambuc asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
119f4a2713aSLionel Sambuc }
120f4a2713aSLionel Sambuc
test12(void)121f4a2713aSLionel Sambuc void test12(void) {
122f4a2713aSLionel Sambuc register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
123f4a2713aSLionel Sambuc }
124f4a2713aSLionel Sambuc
125f4a2713aSLionel Sambuc // PR10223
test13(void)126f4a2713aSLionel Sambuc void test13(void) {
127f4a2713aSLionel Sambuc void *esp;
128f4a2713aSLionel Sambuc __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}
129f4a2713aSLionel Sambuc }
130f4a2713aSLionel Sambuc
131f4a2713aSLionel Sambuc // <rdar://problem/12700799>
132f4a2713aSLionel Sambuc struct S; // expected-note 2 {{forward declaration of 'struct S'}}
test14(struct S * s)133f4a2713aSLionel Sambuc void test14(struct S *s) {
134f4a2713aSLionel Sambuc __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
135f4a2713aSLionel Sambuc __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
136f4a2713aSLionel Sambuc }
137f4a2713aSLionel Sambuc
138f4a2713aSLionel Sambuc // PR15759.
test15()139f4a2713aSLionel Sambuc double test15() {
140f4a2713aSLionel Sambuc double ret = 0;
141f4a2713aSLionel Sambuc __asm("0.0":"="(ret)); // expected-error {{invalid output constraint '=' in asm}}
142f4a2713aSLionel Sambuc __asm("0.0":"=&"(ret)); // expected-error {{invalid output constraint '=&' in asm}}
143f4a2713aSLionel Sambuc __asm("0.0":"+?"(ret)); // expected-error {{invalid output constraint '+?' in asm}}
144f4a2713aSLionel Sambuc __asm("0.0":"+!"(ret)); // expected-error {{invalid output constraint '+!' in asm}}
145f4a2713aSLionel Sambuc __asm("0.0":"+#"(ret)); // expected-error {{invalid output constraint '+#' in asm}}
146f4a2713aSLionel Sambuc __asm("0.0":"+*"(ret)); // expected-error {{invalid output constraint '+*' in asm}}
147f4a2713aSLionel Sambuc __asm("0.0":"=%"(ret)); // expected-error {{invalid output constraint '=%' in asm}}
148f4a2713aSLionel Sambuc __asm("0.0":"=,="(ret)); // expected-error {{invalid output constraint '=,=' in asm}}
149f4a2713aSLionel Sambuc __asm("0.0":"=,g"(ret)); // no-error
150f4a2713aSLionel Sambuc __asm("0.0":"=g"(ret)); // no-error
151f4a2713aSLionel Sambuc return ret;
152f4a2713aSLionel Sambuc }
153*0a6a1f1dSLionel Sambuc
154*0a6a1f1dSLionel Sambuc // PR19837
155*0a6a1f1dSLionel Sambuc struct foo {
156*0a6a1f1dSLionel Sambuc int a;
157*0a6a1f1dSLionel Sambuc char b;
158*0a6a1f1dSLionel Sambuc };
159*0a6a1f1dSLionel Sambuc register struct foo bar asm("sp"); // expected-error {{bad type for named register variable}}
160*0a6a1f1dSLionel Sambuc register float baz asm("sp"); // expected-error {{bad type for named register variable}}
161*0a6a1f1dSLionel Sambuc
f_output_constraint(void)162*0a6a1f1dSLionel Sambuc double f_output_constraint(void) {
163*0a6a1f1dSLionel Sambuc double result;
164*0a6a1f1dSLionel Sambuc __asm("foo1": "=f" (result)); // expected-error {{invalid output constraint '=f' in asm}}
165*0a6a1f1dSLionel Sambuc return result;
166*0a6a1f1dSLionel Sambuc }
167*0a6a1f1dSLionel Sambuc
fn1()168*0a6a1f1dSLionel Sambuc void fn1() {
169*0a6a1f1dSLionel Sambuc int l;
170*0a6a1f1dSLionel Sambuc __asm__(""
171*0a6a1f1dSLionel Sambuc : [l] "=r"(l)
172*0a6a1f1dSLionel Sambuc : "[l],m"(l)); // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}}
173*0a6a1f1dSLionel Sambuc }
174*0a6a1f1dSLionel Sambuc
fn2()175*0a6a1f1dSLionel Sambuc void fn2() {
176*0a6a1f1dSLionel Sambuc int l;
177*0a6a1f1dSLionel Sambuc __asm__(""
178*0a6a1f1dSLionel Sambuc : "+&m"(l)); // expected-error {{invalid output constraint '+&m' in asm}}
179*0a6a1f1dSLionel Sambuc }
180*0a6a1f1dSLionel Sambuc
fn3()181*0a6a1f1dSLionel Sambuc void fn3() {
182*0a6a1f1dSLionel Sambuc int l;
183*0a6a1f1dSLionel Sambuc __asm__(""
184*0a6a1f1dSLionel Sambuc : "+#r"(l)); // expected-error {{invalid output constraint '+#r' in asm}}
185*0a6a1f1dSLionel Sambuc }
186*0a6a1f1dSLionel Sambuc
fn4()187*0a6a1f1dSLionel Sambuc void fn4() {
188*0a6a1f1dSLionel Sambuc int l;
189*0a6a1f1dSLionel Sambuc __asm__(""
190*0a6a1f1dSLionel Sambuc : "=r"(l)
191*0a6a1f1dSLionel Sambuc : "m#"(l));
192*0a6a1f1dSLionel Sambuc }
193*0a6a1f1dSLionel Sambuc
fn5()194*0a6a1f1dSLionel Sambuc void fn5() {
195*0a6a1f1dSLionel Sambuc int l;
196*0a6a1f1dSLionel Sambuc __asm__(""
197*0a6a1f1dSLionel Sambuc : [g] "+r"(l)
198*0a6a1f1dSLionel Sambuc : "[g]"(l)); // expected-error {{invalid input constraint '[g]' in asm}}
199*0a6a1f1dSLionel Sambuc }
200*0a6a1f1dSLionel Sambuc
fn6()201*0a6a1f1dSLionel Sambuc void fn6() {
202*0a6a1f1dSLionel Sambuc int a;
203*0a6a1f1dSLionel Sambuc __asm__(""
204*0a6a1f1dSLionel Sambuc : "=rm"(a), "=rm"(a)
205*0a6a1f1dSLionel Sambuc : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}}
206*0a6a1f1dSLionel Sambuc }
207