blob: 123a0e3d6d3d43c45e5f093addc651a8dcc33416 [file] [log] [blame]
NAKAMURA Takumi0acd8a72013-12-04 03:41:33 +00001// REQUIRES: x86-registered-target
Nico Weber9ef9ca42014-05-06 03:13:27 +00002// RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - -std=c++11 | FileCheck %s
Chad Rosier3b7b0cd2013-04-02 20:03:29 +00003
John McCallf413f5e2013-05-03 00:10:13 +00004// rdar://13645930
5
Chad Rosier3b7b0cd2013-04-02 20:03:29 +00006struct Foo {
7 static int *ptr;
8 static int a, b;
Chad Rosier766d0de2013-04-11 23:57:29 +00009 int arr[4];
Chad Rosier3b7b0cd2013-04-02 20:03:29 +000010 struct Bar {
11 static int *ptr;
Chad Rosier766d0de2013-04-11 23:57:29 +000012 char arr[2];
Chad Rosier3b7b0cd2013-04-02 20:03:29 +000013 };
14};
15
16void t1() {
17 Foo::ptr = (int *)0xDEADBEEF;
18 Foo::Bar::ptr = (int *)0xDEADBEEF;
John McCallf413f5e2013-05-03 00:10:13 +000019 __asm mov eax, Foo ::ptr
20 __asm mov eax, Foo :: Bar :: ptr
21 __asm mov eax, [Foo:: ptr]
22 __asm mov eax, dword ptr [Foo :: ptr]
23 __asm mov eax, dword ptr [Foo :: ptr]
Chad Rosier3b7b0cd2013-04-02 20:03:29 +000024// CHECK: @_Z2t1v
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000025// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0\0A\09mov eax, dword ptr $1\0A\09mov eax, dword ptr $2\0A\09mov eax, dword ptr $3\0A\09mov eax, dword ptr $4", "*m,*m,*m,*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3Bar3ptrE, i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3ptrE)
Chad Rosier3b7b0cd2013-04-02 20:03:29 +000026}
Chad Rosierda0ab492013-04-11 23:37:53 +000027
28int gvar = 10;
29void t2() {
30 int lvar = 10;
31 __asm mov eax, offset Foo::ptr
32 __asm mov eax, offset Foo::Bar::ptr
33// CHECK: t2
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000034// CHECK: call void asm sideeffect inteldialect "mov eax, $0\0A\09mov eax, $1", "r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3Bar3ptrE)
Chad Rosierda0ab492013-04-11 23:37:53 +000035}
Chad Rosier766d0de2013-04-11 23:57:29 +000036
Stephen Lin43622612013-08-15 06:47:53 +000037// CHECK-LABEL: define void @_Z2t3v()
Chad Rosier766d0de2013-04-11 23:57:29 +000038void t3() {
39 __asm mov eax, LENGTH Foo::ptr
40 __asm mov eax, LENGTH Foo::Bar::ptr
41 __asm mov eax, LENGTH Foo::arr
42 __asm mov eax, LENGTH Foo::Bar::arr
43
44 __asm mov eax, TYPE Foo::ptr
45 __asm mov eax, TYPE Foo::Bar::ptr
46 __asm mov eax, TYPE Foo::arr
47 __asm mov eax, TYPE Foo::Bar::arr
48
49 __asm mov eax, SIZE Foo::ptr
50 __asm mov eax, SIZE Foo::Bar::ptr
51 __asm mov eax, SIZE Foo::arr
52 __asm mov eax, SIZE Foo::Bar::arr
Ehsan Akhgari2f93b442014-07-25 02:27:14 +000053// CHECK: call void asm sideeffect inteldialect "mov eax, $$1\0A\09mov eax, $$1\0A\09mov eax, $$4\0A\09mov eax, $$2\0A\09mov eax, $$4\0A\09mov eax, $$4\0A\09mov eax, $$4\0A\09mov eax, $$1\0A\09mov eax, $$4\0A\09mov eax, $$4\0A\09mov eax, $$16\0A\09mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"()
John McCallf413f5e2013-05-03 00:10:13 +000054
55}
56
57struct T4 {
58 int x;
59 static int y;
60 void test();
61};
62
Stephen Lin43622612013-08-15 06:47:53 +000063// CHECK-LABEL: define void @_ZN2T44testEv(
John McCallf413f5e2013-05-03 00:10:13 +000064void T4::test() {
65// CHECK: [[T0:%.*]] = alloca [[T4:%.*]]*,
David Blaikiea953f282015-02-27 21:19:58 +000066// CHECK: [[THIS:%.*]] = load [[T4]]*, [[T4]]** [[T0]]
David Blaikie218b7832015-02-27 19:18:17 +000067// CHECK: [[X:%.*]] = getelementptr inbounds [[T4]], [[T4]]* [[THIS]], i32 0, i32 0
John McCallf413f5e2013-05-03 00:10:13 +000068 __asm mov eax, x;
John McCallf413f5e2013-05-03 00:10:13 +000069 __asm mov y, eax;
Ehsan Akhgarifa2d9aa2014-07-25 02:35:50 +000070// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $1\0A\09mov dword ptr $0, eax", "=*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* @_ZN2T41yE, i32* {{.*}})
John McCallf413f5e2013-05-03 00:10:13 +000071}
72
73template <class T> struct T5 {
74 template <class U> static T create(U);
75 void run();
76};
Stephen Lin43622612013-08-15 06:47:53 +000077// CHECK-LABEL: define void @_Z5test5v()
John McCallf413f5e2013-05-03 00:10:13 +000078void test5() {
79 // CHECK: [[X:%.*]] = alloca i32
80 // CHECK: [[Y:%.*]] = alloca i32
81 int x, y;
82 __asm push y
John McCallf413f5e2013-05-03 00:10:13 +000083 __asm call T5<int>::create<float>
John McCallf413f5e2013-05-03 00:10:13 +000084 __asm mov x, eax
Reid Klecknere2d64292014-08-01 20:23:29 +000085 // CHECK: call void asm sideeffect inteldialect "push dword ptr $0\0A\09call dword ptr $2\0A\09mov dword ptr $1, eax", "=*m,=*m,*m,~{esp},~{dirflag},~{fpsr},~{flags}"(i32* %y, i32* %x, i32 (float)* @_ZN2T5IiE6createIfEEiT_)
Chad Rosier766d0de2013-04-11 23:57:29 +000086}
Chad Rosierb9aff1e2013-05-24 18:32:55 +000087
88// Just verify this doesn't emit an error.
89void test6() {
90 __asm {
91 a:
92 jmp a
93 }
94}
Nico Weber9ef9ca42014-05-06 03:13:27 +000095
96void t7_struct() {
97 struct A {
98 int a;
99 int b;
100 };
101 __asm mov eax, [eax].A.b
102 // CHECK-LABEL: define void @_Z9t7_structv
103 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
104}
105
106void t7_typedef() {
107 typedef struct {
108 int a;
109 int b;
110 } A;
111 __asm mov eax, [eax].A.b
112 // CHECK-LABEL: define void @_Z10t7_typedefv
113 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
114}
115
116void t7_using() {
117 using A = struct {
118 int a;
119 int b;
120 };
121 __asm mov eax, [eax].A.b
122 // CHECK-LABEL: define void @_Z8t7_usingv
123 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
124}
Ehsan Akhgari31097582014-09-22 02:21:54 +0000125
126void t8() {
127 __asm some_label:
128 // CHECK-LABEL: define void @_Z2t8v()
129 // CHECK: call void asm sideeffect inteldialect "L__MSASMLABEL_.1__some_label:", "~{dirflag},~{fpsr},~{flags}"()
130 struct A {
131 static void g() {
132 __asm jmp some_label ; This should jump forwards
133 __asm some_label:
134 __asm nop
135 // CHECK-LABEL: define internal void @_ZZ2t8vEN1A1gEv()
136 // CHECK: call void asm sideeffect inteldialect "jmp L__MSASMLABEL_.2__some_label\0A\09L__MSASMLABEL_.2__some_label:\0A\09nop", "~{dirflag},~{fpsr},~{flags}"()
137 }
138 };
139 A::g();
140}
141