blob: abf10b67cce1846f5747dac3d86483ee2342cdc4 [file] [log] [blame]
NAKAMURA Takumi0acd8a72013-12-04 03:41:33 +00001// REQUIRES: x86-registered-target
Aaron Ballman674cf262015-05-26 19:44:52 +00002// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
Bob Wilson317be452012-09-24 19:57:59 +00003
4void t1(void) {
Eli Friedmand5d136b2012-10-23 02:43:30 +00005 __asm __asm // expected-error {{__asm used with no assembly instructions}}
6}
7
8void f() {
Chad Rosier0130f822012-10-26 18:33:59 +00009 int foo;
Eli Friedmand5d136b2012-10-23 02:43:30 +000010 __asm {
11 mov eax, eax
12 .unknowndirective // expected-error {{unknown directive}}
13 }
14 f();
15 __asm {
Benjamin Kramer6b724722013-12-01 11:48:10 +000016 mov eax, 1+=2 // expected-error {{unknown token in expression}}
Eli Friedmand5d136b2012-10-23 02:43:30 +000017 }
18 f();
19 __asm {
Benjamin Kramer6b724722013-12-01 11:48:10 +000020 mov eax, 1+++ // expected-error {{unknown token in expression}}
Eli Friedmand5d136b2012-10-23 02:43:30 +000021 }
Chad Rosier92c487d2013-01-18 00:51:29 +000022 f();
23 __asm {
Benjamin Kramer6b724722013-12-01 11:48:10 +000024 mov eax, LENGTH bar // expected-error {{unable to lookup expression}}
Chad Rosier92c487d2013-01-18 00:51:29 +000025 }
26 f();
27 __asm {
Benjamin Kramer6b724722013-12-01 11:48:10 +000028 mov eax, SIZE bar // expected-error {{unable to lookup expression}}
Chad Rosier92c487d2013-01-18 00:51:29 +000029 }
30 f();
31 __asm {
Ehsan Akhgari31097582014-09-22 02:21:54 +000032 mov eax, TYPE bar // expected-error {{unable to lookup expression}} expected-error {{use of undeclared label 'bar'}}
Chad Rosier92c487d2013-01-18 00:51:29 +000033 }
Bob Wilson317be452012-09-24 19:57:59 +000034}
Dmitri Gribenkofc13b8b2013-12-03 00:48:09 +000035
36void rdar15318432(void) {
37 // We used to crash on this. When LLVM called back to Clang to parse a name
38 // and do name lookup, if parsing failed, we did not restore the lexer state
39 // properly.
40
Dmitri Gribenkofc13b8b2013-12-03 00:48:09 +000041 __asm {
42 and ecx, ~15
43 }
44
45 int x = 0;
Dmitri Gribenkofc13b8b2013-12-03 00:48:09 +000046 __asm {
47 and ecx, x
48 and ecx, ~15
49 }
50}
Reid Kleckner51082b12014-03-04 17:57:56 +000051
52static int global;
53
54int t2(int *arr, int i) {
55 __asm {
56 mov eax, arr;
57 mov eax, arr[0];
58 mov eax, arr[1 + 2];
59 mov eax, arr[1 + (2 * 5) - 3 + 1<<1];
60 }
61
62 // expected-error@+1 {{cannot use base register with variable reference}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000063 __asm { mov eax, arr[ebp + 1 + (2 * 5) - 3 + 1<<1] }
Reid Kleckner51082b12014-03-04 17:57:56 +000064 // expected-error@+1 {{cannot use index register with variable reference}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000065 __asm { mov eax, arr[esi * 4] }
Reid Kleckner51082b12014-03-04 17:57:56 +000066 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000067 __asm { mov eax, arr[i] }
Reid Kleckner51082b12014-03-04 17:57:56 +000068 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000069 __asm { mov eax, global[i] }
Reid Kleckner51082b12014-03-04 17:57:56 +000070
71 // FIXME: Why don't we diagnose this?
72 // expected-Xerror@+1 {{cannot reference multiple local variables in assembly operand}}
73 //__asm mov eax, [arr + i];
74 return 0;
75}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000076
77typedef struct {
78 int a;
79 int b;
80} A;
81
82void t3() {
Ehsan Akhgari31097582014-09-22 02:21:54 +000083 __asm { mov eax, [eax] UndeclaredId } // expected-error {{unknown token in expression}} expected-error {{use of undeclared label 'UndeclaredId'}}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000084
85 // FIXME: Only emit one diagnostic here.
Ehsan Akhgari31097582014-09-22 02:21:54 +000086 // expected-error@+3 {{use of undeclared label 'A'}}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000087 // expected-error@+2 {{unexpected type name 'A': expected expression}}
88 // expected-error@+1 {{unknown token in expression}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000089 __asm { mov eax, [eax] A }
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000090}
91
92void t4() {
93 // The dot in the "intel dot operator" is optional in MSVC. MSVC also does
94 // global field lookup, but we don't.
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000095 __asm { mov eax, [0] A.a }
96 __asm { mov eax, [0].A.a }
97 __asm { mov eax, [0].a } // expected-error {{Unable to lookup field reference!}}
98 __asm { mov eax, fs:[0] A.a }
99 __asm { mov eax, fs:[0].A.a }
100 __asm { mov eax, fs:[0].a } // expected-error {{Unable to lookup field reference!}}
101 __asm { mov eax, fs:[0]. A.a } // expected-error {{Unexpected token type!}}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +0000102}
Reid Kleckner05d2daf2014-08-01 20:23:03 +0000103
104void test_operand_size() {
105 __asm { call word t4 } // expected-error {{Expected 'PTR' or 'ptr' token!}}
106}
Hans Wennborg93dbeae2014-09-04 22:16:48 +0000107
108__declspec(naked) int t5(int x) { // expected-note {{attribute is here}}
Ehsan Akhgari31097582014-09-22 02:21:54 +0000109 asm { movl eax, x } // expected-error {{parameter references not allowed in naked functions}} expected-error {{use of undeclared label 'x'}}
Hans Wennborg93dbeae2014-09-04 22:16:48 +0000110 asm { retl }
111}
112
113int y;
114__declspec(naked) int t6(int x) {
115 asm { mov eax, y } // No error.
116 asm { ret }
117}
Ehsan Akhgari31097582014-09-22 02:21:54 +0000118
119void t7() {
120 __asm {
121 foo: // expected-note {{inline assembly label 'foo' declared here}}
122 mov eax, 0
123 }
124 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
125}
126
127void t8() {
128 __asm foo: // expected-note {{inline assembly label 'foo' declared here}}
129 __asm mov eax, 0
130 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
131}
132
133void t9() {
134 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
135 __asm {
136 foo: // expected-note {{inline assembly label 'foo' declared here}}
137 mov eax, 0
138 }
139}
140
141void t10() {
142 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
143 __asm foo: // expected-note {{inline assembly label 'foo' declared here}}
144 __asm mov eax, 0
145}
146
147void t11() {
148foo:
Ehsan Akhgari42924432014-10-08 17:28:34 +0000149 __asm mov eax, foo // expected-error {{use of undeclared label 'foo'}} expected-warning {{unused label 'foo'}}
150}
151
152void t12() {
153 __asm foo:
154 __asm bar: // expected-warning {{unused label 'bar'}}
155 __asm jmp foo
Ehsan Akhgari31097582014-09-22 02:21:54 +0000156}