NAKAMURA Takumi | cc59e91 | 2012-09-27 14:55:08 +0000 | [diff] [blame^] | 1 | // REQUIRES: x86-64-registered-target |
Chad Rosier | 48a05b9 | 2012-08-08 21:15:52 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O0 -fms-extensions -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s |
Chad Rosier | b64f310 | 2012-08-08 20:37:31 +0000 | [diff] [blame] | 3 | |
| 4 | void t1() { |
| 5 | // CHECK: @t1 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 6 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | b64f310 | 2012-08-08 20:37:31 +0000 | [diff] [blame] | 7 | // CHECK: ret void |
| 8 | __asm {} |
| 9 | } |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 10 | |
| 11 | void t2() { |
| 12 | // CHECK: @t2 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 13 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 14 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 15 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 16 | // CHECK: ret void |
| 17 | __asm nop |
| 18 | __asm nop |
| 19 | __asm nop |
| 20 | } |
| 21 | |
| 22 | void t3() { |
| 23 | // CHECK: @t3 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 24 | // CHECK: call void asm sideeffect inteldialect "nop\0A\09nop\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 25 | // CHECK: ret void |
| 26 | __asm nop __asm nop __asm nop |
| 27 | } |
| 28 | |
| 29 | void t4(void) { |
| 30 | // CHECK: @t4 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 31 | // CHECK: call void asm sideeffect inteldialect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 32 | // CHECK: call void asm sideeffect inteldialect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 33 | // CHECK: ret void |
| 34 | __asm mov ebx, eax |
| 35 | __asm mov ecx, ebx |
| 36 | } |
| 37 | |
| 38 | void t5(void) { |
| 39 | // CHECK: @t5 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 40 | // CHECK: call void asm sideeffect inteldialect "mov ebx, eax\0A\09mov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 41 | // CHECK: ret void |
| 42 | __asm mov ebx, eax __asm mov ecx, ebx |
| 43 | } |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 44 | |
| 45 | void t6(void) { |
| 46 | __asm int 0x2c |
| 47 | // CHECK: t6 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 48 | // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 51 | void t7() { |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 52 | __asm { |
| 53 | int 0x2c ; } asm comments are fun! }{ |
| 54 | } |
| 55 | __asm {} |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 56 | // CHECK: t7 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 57 | // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 58 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 59 | } |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 60 | int t8() { |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 61 | __asm int 3 ; } comments for single-line asm |
| 62 | __asm {} |
| 63 | __asm int 4 |
| 64 | return 10; |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 65 | // CHECK: t8 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 66 | // CHECK: call void asm sideeffect inteldialect "int $$3", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 67 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 68 | // CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 69 | // CHECK: ret i32 10 |
| 70 | } |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 71 | void t9() { |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 72 | __asm { |
| 73 | push ebx |
| 74 | mov ebx, 0x07 |
| 75 | pop ebx |
| 76 | } |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 77 | // CHECK: t9 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 78 | // CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 79 | } |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 80 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 81 | unsigned t10(void) { |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 82 | unsigned i = 1, j; |
| 83 | __asm { |
| 84 | mov eax, i |
| 85 | mov j, eax |
| 86 | } |
| 87 | return j; |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 88 | // CHECK: t10 |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 89 | // CHECK: [[I:%[a-zA-Z0-9]+]] = alloca i32, align 4 |
| 90 | // CHECK: [[J:%[a-zA-Z0-9]+]] = alloca i32, align 4 |
| 91 | // CHECK: store i32 1, i32* [[I]], align 4 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 92 | // CHECK: call i32 asm sideeffect inteldialect "mov eax, $1\0A\09mov $0, eax", "=r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}) nounwind |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 93 | // CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4 |
| 94 | // CHECK: ret i32 [[RET]] |
| 95 | } |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 96 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 97 | void t11(void) { |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 98 | __asm EVEN |
| 99 | __asm ALIGN |
Chad Rosier | c691649 | 2012-09-06 19:56:25 +0000 | [diff] [blame] | 100 | // CHECK: t11 |
| 101 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 102 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 105 | void t12(void) { |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 106 | __asm { |
| 107 | _emit 0x4A |
| 108 | _emit 0x43 |
| 109 | _emit 0x4B |
| 110 | } |
Chad Rosier | c691649 | 2012-09-06 19:56:25 +0000 | [diff] [blame] | 111 | // CHECK: t12 |
| 112 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 115 | void t13(void) { |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 116 | unsigned arr[10]; |
| 117 | __asm LENGTH arr ; sizeof(arr)/sizeof(arr[0]) |
| 118 | __asm SIZE arr ; sizeof(arr) |
| 119 | __asm TYPE arr ; sizeof(arr[0]) |
Chad Rosier | c691649 | 2012-09-06 19:56:25 +0000 | [diff] [blame] | 120 | // CHECK: t13 |
| 121 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 122 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 123 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 124 | } |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 125 | |
| 126 | void t14(void) { |
| 127 | __asm mov eax, 1 |
| 128 | // CHECK: t14 |
| 129 | // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 130 | } |
Chad Rosier | 7f9678b | 2012-09-12 18:14:25 +0000 | [diff] [blame] | 131 | |
| 132 | void t15(void) { |
| 133 | __asm mov eax, DWORD PTR [eax] |
| 134 | // CHECK: t15 |
| 135 | // CHECK: call void asm sideeffect inteldialect "mov eax, DWORD PTR [eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 136 | } |
| 137 | |
| 138 | void t16(unsigned long long V) { |
| 139 | __asm mov eax, DWORD PTR [V] |
| 140 | // CHECK: t16 |
Chad Rosier | 1fa1e0c | 2012-09-12 23:03:48 +0000 | [diff] [blame] | 141 | // CHECK: call void asm sideeffect inteldialect "mov eax, DWORD PTR [$0]", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i64 %{{.*}}) nounwind |
Chad Rosier | 7f9678b | 2012-09-12 18:14:25 +0000 | [diff] [blame] | 142 | } |
Chad Rosier | 808a1d0 | 2012-09-12 18:25:06 +0000 | [diff] [blame] | 143 | |
| 144 | void t17(void) { |
| 145 | __asm mov eax, dword ptr [eax] |
| 146 | // CHECK: t17 |
| 147 | // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr [eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 148 | } |
Chad Rosier | 47fa999 | 2012-09-12 18:34:34 +0000 | [diff] [blame] | 149 | |
| 150 | void t18(void) { |
| 151 | __asm mov dword ptr [eax], eax |
| 152 | // CHECK: t18 |
| 153 | // CHECK: call void asm sideeffect inteldialect "mov dword ptr [eax], eax", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 154 | } |
Chad Rosier | b55e602 | 2012-09-13 00:06:55 +0000 | [diff] [blame] | 155 | |
| 156 | unsigned t19(void) { |
| 157 | unsigned i = 1, j, l = 1, m; |
| 158 | __asm { |
| 159 | mov eax, i |
| 160 | mov j, eax |
| 161 | mov eax, l |
| 162 | mov m, eax |
| 163 | } |
| 164 | return j + m; |
| 165 | // CHECK: t19 |
| 166 | // CHECK: call { i32, i32 } asm sideeffect inteldialect "mov eax, $2\0A\09mov $0, eax\0A\09mov eax, $3\0A\09mov $1, eax", "=r,=r,r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i32 %{{.*}}) nounwind |
| 167 | } |