2013-12-04 11:41:33 +08:00
|
|
|
// REQUIRES: x86-registered-target
|
2013-01-23 03:38:32 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fasm-blocks -Wno-microsoft -verify -fsyntax-only
|
2012-09-25 03:57:59 +08:00
|
|
|
|
|
|
|
void t1(void) {
|
2012-10-23 10:43:30 +08:00
|
|
|
__asm __asm // expected-error {{__asm used with no assembly instructions}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f() {
|
2012-10-27 02:33:59 +08:00
|
|
|
int foo;
|
2012-10-23 10:43:30 +08:00
|
|
|
__asm {
|
|
|
|
mov eax, eax
|
|
|
|
.unknowndirective // expected-error {{unknown directive}}
|
|
|
|
}
|
|
|
|
f();
|
|
|
|
__asm {
|
2013-12-01 19:48:10 +08:00
|
|
|
mov eax, 1+=2 // expected-error {{unknown token in expression}}
|
2012-10-23 10:43:30 +08:00
|
|
|
}
|
|
|
|
f();
|
|
|
|
__asm {
|
2013-12-01 19:48:10 +08:00
|
|
|
mov eax, 1+++ // expected-error {{unknown token in expression}}
|
2012-10-23 10:43:30 +08:00
|
|
|
}
|
2013-01-18 08:51:29 +08:00
|
|
|
f();
|
|
|
|
__asm {
|
2013-12-01 19:48:10 +08:00
|
|
|
mov eax, LENGTH bar // expected-error {{unable to lookup expression}}
|
2013-01-18 08:51:29 +08:00
|
|
|
}
|
|
|
|
f();
|
|
|
|
__asm {
|
2013-12-01 19:48:10 +08:00
|
|
|
mov eax, SIZE bar // expected-error {{unable to lookup expression}}
|
2013-01-18 08:51:29 +08:00
|
|
|
}
|
|
|
|
f();
|
|
|
|
__asm {
|
2013-12-01 19:48:10 +08:00
|
|
|
mov eax, TYPE bar // expected-error {{unable to lookup expression}}
|
2013-01-18 08:51:29 +08:00
|
|
|
}
|
2012-09-25 03:57:59 +08:00
|
|
|
}
|
2013-12-03 08:48:09 +08:00
|
|
|
|
|
|
|
void rdar15318432(void) {
|
|
|
|
// We used to crash on this. When LLVM called back to Clang to parse a name
|
|
|
|
// and do name lookup, if parsing failed, we did not restore the lexer state
|
|
|
|
// properly.
|
|
|
|
|
|
|
|
__asm {
|
|
|
|
and ecx, ~15
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
__asm {
|
|
|
|
and ecx, x
|
|
|
|
and ecx, ~15
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 01:57:56 +08:00
|
|
|
|
|
|
|
static int global;
|
|
|
|
|
|
|
|
int t2(int *arr, int i) {
|
|
|
|
__asm {
|
|
|
|
mov eax, arr;
|
|
|
|
mov eax, arr[0];
|
|
|
|
mov eax, arr[1 + 2];
|
|
|
|
mov eax, arr[1 + (2 * 5) - 3 + 1<<1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// expected-error@+1 {{cannot use base register with variable reference}}
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, arr[ebp + 1 + (2 * 5) - 3 + 1<<1] }
|
2014-03-05 01:57:56 +08:00
|
|
|
// expected-error@+1 {{cannot use index register with variable reference}}
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, arr[esi * 4] }
|
2014-03-05 01:57:56 +08:00
|
|
|
// expected-error@+1 {{cannot use more than one symbol in memory operand}}
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, arr[i] }
|
2014-03-05 01:57:56 +08:00
|
|
|
// expected-error@+1 {{cannot use more than one symbol in memory operand}}
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, global[i] }
|
2014-03-05 01:57:56 +08:00
|
|
|
|
|
|
|
// FIXME: Why don't we diagnose this?
|
|
|
|
// expected-Xerror@+1 {{cannot reference multiple local variables in assembly operand}}
|
|
|
|
//__asm mov eax, [arr + i];
|
|
|
|
return 0;
|
|
|
|
}
|
2014-03-07 03:19:36 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int a;
|
|
|
|
int b;
|
|
|
|
} A;
|
|
|
|
|
|
|
|
void t3() {
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, [eax] UndeclaredId } // expected-error {{unknown token in expression}}
|
2014-03-07 03:19:36 +08:00
|
|
|
|
|
|
|
// FIXME: Only emit one diagnostic here.
|
|
|
|
// expected-error@+2 {{unexpected type name 'A': expected expression}}
|
|
|
|
// expected-error@+1 {{unknown token in expression}}
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, [eax] A }
|
2014-03-07 03:19:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void t4() {
|
|
|
|
// The dot in the "intel dot operator" is optional in MSVC. MSVC also does
|
|
|
|
// global field lookup, but we don't.
|
2014-07-25 10:27:14 +08:00
|
|
|
__asm { mov eax, [0] A.a }
|
|
|
|
__asm { mov eax, [0].A.a }
|
|
|
|
__asm { mov eax, [0].a } // expected-error {{Unable to lookup field reference!}}
|
|
|
|
__asm { mov eax, fs:[0] A.a }
|
|
|
|
__asm { mov eax, fs:[0].A.a }
|
|
|
|
__asm { mov eax, fs:[0].a } // expected-error {{Unable to lookup field reference!}}
|
|
|
|
__asm { mov eax, fs:[0]. A.a } // expected-error {{Unexpected token type!}}
|
2014-03-07 03:19:36 +08:00
|
|
|
}
|
2014-08-02 04:23:03 +08:00
|
|
|
|
|
|
|
void test_operand_size() {
|
|
|
|
__asm { call word t4 } // expected-error {{Expected 'PTR' or 'ptr' token!}}
|
|
|
|
}
|