1 // REQUIRES: x86-registered-target
2 // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fasm-blocks -Wno-microsoft -verify -fsyntax-only
3
t1(void)4 void t1(void) {
5 __asm __asm // expected-error {{__asm used with no assembly instructions}}
6 }
7
f()8 void f() {
9 int foo;
10 __asm {
11 mov eax, eax
12 .unknowndirective // expected-error {{unknown directive}}
13 }
14 f();
15 __asm {
16 mov eax, 1+=2 // expected-error {{unknown token in expression}}
17 }
18 f();
19 __asm {
20 mov eax, 1+++ // expected-error {{unknown token in expression}}
21 }
22 f();
23 __asm {
24 mov eax, LENGTH bar // expected-error {{unable to lookup expression}}
25 }
26 f();
27 __asm {
28 mov eax, SIZE bar // expected-error {{unable to lookup expression}}
29 }
30 f();
31 __asm {
32 mov eax, TYPE bar // expected-error {{unable to lookup expression}}
33 }
34 }
35
rdar15318432(void)36 void 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
41 __asm {
42 and ecx, ~15
43 }
44
45 int x = 0;
46 __asm {
47 and ecx, x
48 and ecx, ~15
49 }
50 }
51
52 static int global;
53
t2(int * arr,int i)54 int 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}}
63 __asm mov eax, arr[ebp + 1 + (2 * 5) - 3 + 1<<1]
64 // expected-error@+1 {{cannot use index register with variable reference}}
65 __asm mov eax, arr[esi * 4]
66 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
67 __asm mov eax, arr[i]
68 // expected-error@+1 {{cannot use more than one symbol in memory operand}}
69 __asm mov eax, global[i]
70
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 }
76
77 typedef struct {
78 int a;
79 int b;
80 } A;
81
t3()82 void t3() {
83 __asm mov eax, [eax] UndeclaredId // expected-error {{unknown token in expression}}
84
85 // FIXME: Only emit one diagnostic here.
86 // expected-error@+2 {{unexpected type name 'A': expected expression}}
87 // expected-error@+1 {{unknown token in expression}}
88 __asm mov eax, [eax] A
89 }
90
t4()91 void t4() {
92 // The dot in the "intel dot operator" is optional in MSVC. MSVC also does
93 // global field lookup, but we don't.
94 __asm mov eax, [0] A.a
95 __asm mov eax, [0].A.a
96 __asm mov eax, [0].a // expected-error {{Unable to lookup field reference!}}
97 __asm mov eax, fs:[0] A.a
98 __asm mov eax, fs:[0].A.a
99 __asm mov eax, fs:[0].a // expected-error {{Unable to lookup field reference!}}
100 __asm mov eax, fs:[0]. A.a // expected-error {{Unexpected token type!}}
101 }
102