2012-09-27 22:55:08 +08:00
|
|
|
// REQUIRES: x86-64-registered-target
|
2012-12-06 05:08:21 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -O0 -fasm-blocks -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
|
2012-10-20 04:38:09 +08:00
|
|
|
|
2012-08-09 04:37:31 +08:00
|
|
|
void t1() {
|
|
|
|
// CHECK: @t1
|
2012-09-06 03:01:07 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-09 04:37:31 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
__asm {}
|
|
|
|
}
|
2012-08-14 04:32:07 +08:00
|
|
|
|
|
|
|
void t2() {
|
|
|
|
// CHECK: @t2
|
2012-09-06 03:01:07 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-14 04:32:07 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
__asm nop
|
|
|
|
__asm nop
|
|
|
|
__asm nop
|
|
|
|
}
|
|
|
|
|
|
|
|
void t3() {
|
|
|
|
// CHECK: @t3
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "nop\0A\09nop\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-14 04:32:07 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
__asm nop __asm nop __asm nop
|
|
|
|
}
|
|
|
|
|
|
|
|
void t4(void) {
|
|
|
|
// CHECK: @t4
|
2012-09-06 03:01:07 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-14 04:32:07 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
__asm mov ebx, eax
|
|
|
|
__asm mov ecx, ebx
|
|
|
|
}
|
|
|
|
|
|
|
|
void t5(void) {
|
|
|
|
// CHECK: @t5
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov ebx, eax\0A\09mov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-14 04:32:07 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
__asm mov ebx, eax __asm mov ecx, ebx
|
|
|
|
}
|
2012-08-15 07:48:41 +08:00
|
|
|
|
|
|
|
void t6(void) {
|
|
|
|
__asm int 0x2c
|
|
|
|
// CHECK: t6
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-15 07:48:41 +08:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:01:26 +08:00
|
|
|
void t7() {
|
2012-08-15 07:48:41 +08:00
|
|
|
__asm {
|
|
|
|
int 0x2c ; } asm comments are fun! }{
|
|
|
|
}
|
|
|
|
__asm {}
|
2012-08-22 01:01:26 +08:00
|
|
|
// CHECK: t7
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-09-06 03:01:07 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-15 07:48:41 +08:00
|
|
|
}
|
2012-10-03 04:55:30 +08:00
|
|
|
|
2012-08-22 01:01:26 +08:00
|
|
|
int t8() {
|
2012-10-16 03:56:10 +08:00
|
|
|
__asm int 4 ; } comments for single-line asm
|
2012-08-15 07:48:41 +08:00
|
|
|
__asm {}
|
|
|
|
__asm int 4
|
|
|
|
return 10;
|
2012-08-22 01:01:26 +08:00
|
|
|
// CHECK: t8
|
2012-10-16 03:56:10 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-09-06 03:01:07 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-15 07:48:41 +08:00
|
|
|
// CHECK: ret i32 10
|
|
|
|
}
|
2012-10-03 04:55:30 +08:00
|
|
|
|
2012-08-22 01:01:26 +08:00
|
|
|
void t9() {
|
2012-08-15 07:48:41 +08:00
|
|
|
__asm {
|
|
|
|
push ebx
|
|
|
|
mov ebx, 0x07
|
|
|
|
pop ebx
|
|
|
|
}
|
2012-08-22 01:01:26 +08:00
|
|
|
// CHECK: t9
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-08-15 07:48:41 +08:00
|
|
|
}
|
2012-08-17 01:10:59 +08:00
|
|
|
|
2012-08-22 01:01:26 +08:00
|
|
|
unsigned t10(void) {
|
2012-08-17 01:10:59 +08:00
|
|
|
unsigned i = 1, j;
|
|
|
|
__asm {
|
|
|
|
mov eax, i
|
|
|
|
mov j, eax
|
|
|
|
}
|
|
|
|
return j;
|
2012-08-22 01:01:26 +08:00
|
|
|
// CHECK: t10
|
2012-08-17 01:10:59 +08:00
|
|
|
// CHECK: [[I:%[a-zA-Z0-9]+]] = alloca i32, align 4
|
|
|
|
// CHECK: [[J:%[a-zA-Z0-9]+]] = alloca i32, align 4
|
|
|
|
// CHECK: store i32 1, i32* [[I]], align 4
|
2012-10-20 04:57:37 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $1\0A\09mov dword ptr $0, eax", "=*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32* %{{.*}}) nounwind
|
2012-08-17 01:10:59 +08:00
|
|
|
// CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4
|
|
|
|
// CHECK: ret i32 [[RET]]
|
|
|
|
}
|
2012-08-17 06:25:38 +08:00
|
|
|
|
2012-08-22 01:01:26 +08:00
|
|
|
void t11(void) {
|
2012-09-11 08:51:28 +08:00
|
|
|
__asm mov eax, 1
|
2012-10-13 05:37:00 +08:00
|
|
|
// CHECK: t11
|
2012-09-11 08:51:28 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2012-09-13 02:14:25 +08:00
|
|
|
|
2012-10-13 05:37:00 +08:00
|
|
|
unsigned t12(void) {
|
2012-09-13 08:06:55 +08:00
|
|
|
unsigned i = 1, j, l = 1, m;
|
|
|
|
__asm {
|
|
|
|
mov eax, i
|
|
|
|
mov j, eax
|
|
|
|
mov eax, l
|
|
|
|
mov m, eax
|
|
|
|
}
|
|
|
|
return j + m;
|
2012-10-13 05:37:00 +08:00
|
|
|
// CHECK: t12
|
2012-10-20 04:57:37 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $2\0A\09mov dword ptr $0, eax\0A\09mov eax, dword ptr $3\0A\09mov dword ptr $1, eax", "=*m,=*m,*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}) nounwind
|
|
|
|
}
|
|
|
|
|
|
|
|
void t13() {
|
|
|
|
char i = 1;
|
|
|
|
short j = 2;
|
|
|
|
__asm movzx eax, i
|
|
|
|
__asm movzx eax, j
|
|
|
|
// CHECK: t13
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "movzx eax, byte ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i8* %{{.*}}) nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "movzx eax, word ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i16* %{{.*}}) nounwind
|
2012-09-13 08:06:55 +08:00
|
|
|
}
|
2012-10-20 07:16:17 +08:00
|
|
|
|
|
|
|
void t14() {
|
|
|
|
unsigned i = 1, j = 2;
|
|
|
|
__asm {
|
|
|
|
.if 1
|
|
|
|
mov eax, i
|
|
|
|
.else
|
|
|
|
mov ebx, j
|
|
|
|
.endif
|
|
|
|
}
|
|
|
|
// CHECK: t14
|
2012-10-23 04:50:45 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect ".if 1\0A\09mov eax, dword ptr $0\0A\09.else\0A\09mov ebx, j\0A\09.endif", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind
|
2012-10-20 07:16:17 +08:00
|
|
|
}
|
2012-10-23 03:43:17 +08:00
|
|
|
|
2013-01-09 07:51:48 +08:00
|
|
|
int gvar = 10;
|
2012-10-23 03:43:17 +08:00
|
|
|
void t15() {
|
2013-01-09 07:51:48 +08:00
|
|
|
int lvar = 10;
|
|
|
|
__asm mov eax, lvar ; eax = 10
|
|
|
|
__asm mov eax, offset lvar ; eax = address of lvar
|
|
|
|
__asm mov eax, offset gvar ; eax = address of gvar
|
2012-10-23 03:43:17 +08:00
|
|
|
// CHECK: t15
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind
|
2012-10-24 01:44:40 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind
|
2013-01-09 07:51:48 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* @{{.*}}) nounwind
|
2012-10-23 03:43:17 +08:00
|
|
|
}
|
2012-10-25 01:23:06 +08:00
|
|
|
|
|
|
|
void t16() {
|
|
|
|
int var = 10;
|
|
|
|
__asm mov [eax], offset var
|
|
|
|
// CHECK: t16
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov [eax], $0", "r,~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind
|
|
|
|
}
|
2012-10-25 01:48:01 +08:00
|
|
|
|
|
|
|
void t17() {
|
|
|
|
__asm _emit 0x4A
|
|
|
|
__asm _emit 0x43
|
|
|
|
__asm _emit 0x4B
|
|
|
|
// CHECK: t17
|
|
|
|
// CHECK: call void asm sideeffect inteldialect ".byte 0x4A", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect ".byte 0x43", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect ".byte 0x4B", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2012-10-25 06:22:12 +08:00
|
|
|
|
|
|
|
struct t18_type { int a, b; };
|
|
|
|
|
|
|
|
int t18() {
|
|
|
|
struct t18_type foo;
|
|
|
|
foo.a = 1;
|
|
|
|
foo.b = 2;
|
|
|
|
__asm {
|
|
|
|
lea ebx, foo
|
|
|
|
mov eax, [ebx].0
|
|
|
|
mov [ebx].4, ecx
|
|
|
|
}
|
|
|
|
return foo.b;
|
|
|
|
// CHECK: t18
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "lea ebx, foo\0A\09mov eax, [ebx].0\0A\09mov [ebx].4, ecx", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2012-10-26 05:52:03 +08:00
|
|
|
|
|
|
|
int t19() {
|
|
|
|
struct t18_type foo;
|
|
|
|
foo.a = 1;
|
|
|
|
foo.b = 2;
|
|
|
|
__asm {
|
|
|
|
lea ebx, foo
|
|
|
|
mov eax, [ebx].foo.a
|
|
|
|
mov [ebx].foo.b, ecx
|
|
|
|
}
|
|
|
|
return foo.b;
|
|
|
|
// CHECK: t19
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "lea ebx, foo\0A\09mov eax, [ebx].0\0A\09mov [ebx].4, ecx", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2012-10-27 02:04:45 +08:00
|
|
|
|
|
|
|
void t20() {
|
2013-01-18 03:22:48 +08:00
|
|
|
char bar;
|
2012-10-27 02:04:45 +08:00
|
|
|
int foo;
|
2013-01-18 03:22:48 +08:00
|
|
|
char _bar[2];
|
|
|
|
int _foo[4];
|
|
|
|
|
|
|
|
__asm mov eax, LENGTH foo
|
|
|
|
__asm mov eax, LENGTH bar
|
|
|
|
__asm mov eax, LENGTH _foo
|
|
|
|
__asm mov eax, LENGTH _bar
|
2012-10-27 02:04:45 +08:00
|
|
|
// CHECK: t20
|
2013-01-18 03:22:48 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
|
|
|
|
__asm mov eax, TYPE foo
|
|
|
|
__asm mov eax, TYPE bar
|
|
|
|
__asm mov eax, TYPE _foo
|
|
|
|
__asm mov eax, TYPE _bar
|
2012-10-27 02:04:45 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
2013-01-18 03:22:48 +08:00
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
|
|
|
|
__asm mov eax, SIZE foo
|
|
|
|
__asm mov eax, SIZE bar
|
|
|
|
__asm mov eax, SIZE _foo
|
|
|
|
__asm mov eax, SIZE _bar
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$16", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
|
2012-10-27 02:04:45 +08:00
|
|
|
}
|
2012-12-06 03:52:05 +08:00
|
|
|
|
|
|
|
void t21() {
|
|
|
|
__asm {
|
|
|
|
__asm push ebx
|
|
|
|
__asm mov ebx, 0x07
|
|
|
|
__asm pop ebx
|
|
|
|
}
|
|
|
|
// CHECK: t21
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void t22_helper(int x);
|
|
|
|
void t22() {
|
|
|
|
int x = 0;
|
|
|
|
__asm {
|
|
|
|
__asm push ebx
|
|
|
|
__asm mov ebx, esp
|
|
|
|
}
|
|
|
|
t22_helper(x);
|
|
|
|
__asm {
|
|
|
|
__asm mov esp, ebx
|
|
|
|
__asm pop ebx
|
|
|
|
}
|
|
|
|
// CHECK: t22
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, esp", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
// CHECK: call void @t22_helper
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "mov esp, ebx\0A\09pop ebx", "~{ebx},~{esp},~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2013-01-08 04:34:40 +08:00
|
|
|
|
|
|
|
void t23() {
|
|
|
|
__asm {
|
|
|
|
the_label:
|
|
|
|
}
|
|
|
|
// CHECK: t23
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "the_label:", "~{dirflag},~{fpsr},~{flags}"() nounwind
|
|
|
|
}
|
2013-01-11 06:11:28 +08:00
|
|
|
|
|
|
|
void t24_helper(void) {}
|
|
|
|
void t24() {
|
|
|
|
__asm call t24_helper
|
|
|
|
// CHECK: t24
|
|
|
|
// CHECK: call void asm sideeffect inteldialect "call $0", "r,~{dirflag},~{fpsr},~{flags}"(void ()* @t24_helper) nounwind
|
|
|
|
}
|