blob: 3fc74fa99c35eba82a4469d16ae6564e9fac38c3 [file] [log] [blame]
NAKAMURA Takumi0acd8a72013-12-04 03:41:33 +00001// REQUIRES: x86-registered-target
Saleem Abdulrasoolb51bcaf2017-04-07 15:13:47 +00002// RUN: %clang_cc1 %s -triple i386-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
Reid Kleckner51082b12014-03-04 17:57:56 +000062 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000063 __asm { mov eax, arr[i] }
Reid Kleckner51082b12014-03-04 17:57:56 +000064 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000065 __asm { mov eax, global[i] }
Reid Kleckner51082b12014-03-04 17:57:56 +000066
Coby Tayreecfa38102017-08-24 08:47:26 +000067 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
68 __asm mov eax, [arr + i];
Reid Kleckner51082b12014-03-04 17:57:56 +000069 return 0;
70}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000071
72typedef struct {
73 int a;
74 int b;
75} A;
76
77void t3() {
Ehsan Akhgari31097582014-09-22 02:21:54 +000078 __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 +000079
80 // FIXME: Only emit one diagnostic here.
Ehsan Akhgari31097582014-09-22 02:21:54 +000081 // expected-error@+3 {{use of undeclared label 'A'}}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000082 // expected-error@+2 {{unexpected type name 'A': expected expression}}
83 // expected-error@+1 {{unknown token in expression}}
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000084 __asm { mov eax, [eax] A }
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000085}
86
87void t4() {
88 // The dot in the "intel dot operator" is optional in MSVC. MSVC also does
89 // global field lookup, but we don't.
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000090 __asm { mov eax, [0] A.a }
91 __asm { mov eax, [0].A.a }
92 __asm { mov eax, [0].a } // expected-error {{Unable to lookup field reference!}}
93 __asm { mov eax, fs:[0] A.a }
94 __asm { mov eax, fs:[0].A.a }
95 __asm { mov eax, fs:[0].a } // expected-error {{Unable to lookup field reference!}}
Coby Tayreecfa38102017-08-24 08:47:26 +000096 __asm { mov eax, fs:[0]. A.a } // expected-error {{unexpected token in argument list}}
Reid Kleckner8d4a16e2014-03-06 19:19:36 +000097}
Reid Kleckner05d2daf2014-08-01 20:23:03 +000098
99void test_operand_size() {
100 __asm { call word t4 } // expected-error {{Expected 'PTR' or 'ptr' token!}}
101}
Hans Wennborg93dbeae2014-09-04 22:16:48 +0000102
103__declspec(naked) int t5(int x) { // expected-note {{attribute is here}}
Ehsan Akhgari31097582014-09-22 02:21:54 +0000104 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 +0000105 asm { retl }
106}
107
108int y;
109__declspec(naked) int t6(int x) {
110 asm { mov eax, y } // No error.
111 asm { ret }
112}
Ehsan Akhgari31097582014-09-22 02:21:54 +0000113
114void t7() {
115 __asm {
116 foo: // expected-note {{inline assembly label 'foo' declared here}}
117 mov eax, 0
118 }
119 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
120}
121
122void t8() {
123 __asm foo: // expected-note {{inline assembly label 'foo' declared here}}
124 __asm mov eax, 0
125 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
126}
127
128void t9() {
129 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
130 __asm {
131 foo: // expected-note {{inline assembly label 'foo' declared here}}
132 mov eax, 0
133 }
134}
135
136void t10() {
137 goto foo; // expected-error {{cannot jump from this goto statement to label 'foo' inside an inline assembly block}}
138 __asm foo: // expected-note {{inline assembly label 'foo' declared here}}
139 __asm mov eax, 0
140}
141
142void t11() {
143foo:
Ehsan Akhgari42924432014-10-08 17:28:34 +0000144 __asm mov eax, foo // expected-error {{use of undeclared label 'foo'}} expected-warning {{unused label 'foo'}}
145}
146
147void t12() {
148 __asm foo:
149 __asm bar: // expected-warning {{unused label 'bar'}}
150 __asm jmp foo
Ehsan Akhgari31097582014-09-22 02:21:54 +0000151}