1*0a6a1f1dSLionel Sambuc // REQUIRES: x86-registered-target
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - -std=c++11 | FileCheck %s
3f4a2713aSLionel Sambuc
4f4a2713aSLionel Sambuc // rdar://13645930
5f4a2713aSLionel Sambuc
6f4a2713aSLionel Sambuc struct Foo {
7f4a2713aSLionel Sambuc static int *ptr;
8f4a2713aSLionel Sambuc static int a, b;
9f4a2713aSLionel Sambuc int arr[4];
10f4a2713aSLionel Sambuc struct Bar {
11f4a2713aSLionel Sambuc static int *ptr;
12f4a2713aSLionel Sambuc char arr[2];
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc };
15f4a2713aSLionel Sambuc
t1()16f4a2713aSLionel Sambuc void t1() {
17f4a2713aSLionel Sambuc Foo::ptr = (int *)0xDEADBEEF;
18f4a2713aSLionel Sambuc Foo::Bar::ptr = (int *)0xDEADBEEF;
19f4a2713aSLionel Sambuc __asm mov eax, Foo ::ptr
20f4a2713aSLionel Sambuc __asm mov eax, Foo :: Bar :: ptr
21f4a2713aSLionel Sambuc __asm mov eax, [Foo:: ptr]
22f4a2713aSLionel Sambuc __asm mov eax, dword ptr [Foo :: ptr]
23f4a2713aSLionel Sambuc __asm mov eax, dword ptr [Foo :: ptr]
24f4a2713aSLionel Sambuc // CHECK: @_Z2t1v
25*0a6a1f1dSLionel Sambuc // 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)
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc
28f4a2713aSLionel Sambuc int gvar = 10;
t2()29f4a2713aSLionel Sambuc void t2() {
30f4a2713aSLionel Sambuc int lvar = 10;
31f4a2713aSLionel Sambuc __asm mov eax, offset Foo::ptr
32f4a2713aSLionel Sambuc __asm mov eax, offset Foo::Bar::ptr
33f4a2713aSLionel Sambuc // CHECK: t2
34*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $0\0A\09mov eax, $1", "r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3Bar3ptrE)
35f4a2713aSLionel Sambuc }
36f4a2713aSLionel Sambuc
37f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2t3v()
t3()38f4a2713aSLionel Sambuc void t3() {
39f4a2713aSLionel Sambuc __asm mov eax, LENGTH Foo::ptr
40f4a2713aSLionel Sambuc __asm mov eax, LENGTH Foo::Bar::ptr
41f4a2713aSLionel Sambuc __asm mov eax, LENGTH Foo::arr
42f4a2713aSLionel Sambuc __asm mov eax, LENGTH Foo::Bar::arr
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc __asm mov eax, TYPE Foo::ptr
45f4a2713aSLionel Sambuc __asm mov eax, TYPE Foo::Bar::ptr
46f4a2713aSLionel Sambuc __asm mov eax, TYPE Foo::arr
47f4a2713aSLionel Sambuc __asm mov eax, TYPE Foo::Bar::arr
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc __asm mov eax, SIZE Foo::ptr
50f4a2713aSLionel Sambuc __asm mov eax, SIZE Foo::Bar::ptr
51f4a2713aSLionel Sambuc __asm mov eax, SIZE Foo::arr
52f4a2713aSLionel Sambuc __asm mov eax, SIZE Foo::Bar::arr
53*0a6a1f1dSLionel Sambuc // 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}"()
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc
57f4a2713aSLionel Sambuc struct T4 {
58f4a2713aSLionel Sambuc int x;
59f4a2713aSLionel Sambuc static int y;
60f4a2713aSLionel Sambuc void test();
61f4a2713aSLionel Sambuc };
62f4a2713aSLionel Sambuc
63f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN2T44testEv(
test()64f4a2713aSLionel Sambuc void T4::test() {
65f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = alloca [[T4:%.*]]*,
66f4a2713aSLionel Sambuc // CHECK: [[THIS:%.*]] = load [[T4]]** [[T0]]
67f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = getelementptr inbounds [[T4]]* [[THIS]], i32 0, i32 0
68f4a2713aSLionel Sambuc __asm mov eax, x;
69f4a2713aSLionel Sambuc __asm mov y, eax;
70*0a6a1f1dSLionel Sambuc // 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* {{.*}})
71f4a2713aSLionel Sambuc }
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc template <class T> struct T5 {
74f4a2713aSLionel Sambuc template <class U> static T create(U);
75f4a2713aSLionel Sambuc void run();
76f4a2713aSLionel Sambuc };
77f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z5test5v()
test5()78f4a2713aSLionel Sambuc void test5() {
79f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i32
80f4a2713aSLionel Sambuc // CHECK: [[Y:%.*]] = alloca i32
81f4a2713aSLionel Sambuc int x, y;
82f4a2713aSLionel Sambuc __asm push y
83f4a2713aSLionel Sambuc __asm call T5<int>::create<float>
84f4a2713aSLionel Sambuc __asm mov x, eax
85*0a6a1f1dSLionel Sambuc // 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_)
86f4a2713aSLionel Sambuc }
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambuc // Just verify this doesn't emit an error.
test6()89f4a2713aSLionel Sambuc void test6() {
90f4a2713aSLionel Sambuc __asm {
91f4a2713aSLionel Sambuc a:
92f4a2713aSLionel Sambuc jmp a
93f4a2713aSLionel Sambuc }
94f4a2713aSLionel Sambuc }
95*0a6a1f1dSLionel Sambuc
t7_struct()96*0a6a1f1dSLionel Sambuc void t7_struct() {
97*0a6a1f1dSLionel Sambuc struct A {
98*0a6a1f1dSLionel Sambuc int a;
99*0a6a1f1dSLionel Sambuc int b;
100*0a6a1f1dSLionel Sambuc };
101*0a6a1f1dSLionel Sambuc __asm mov eax, [eax].A.b
102*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @_Z9t7_structv
103*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
104*0a6a1f1dSLionel Sambuc }
105*0a6a1f1dSLionel Sambuc
t7_typedef()106*0a6a1f1dSLionel Sambuc void t7_typedef() {
107*0a6a1f1dSLionel Sambuc typedef struct {
108*0a6a1f1dSLionel Sambuc int a;
109*0a6a1f1dSLionel Sambuc int b;
110*0a6a1f1dSLionel Sambuc } A;
111*0a6a1f1dSLionel Sambuc __asm mov eax, [eax].A.b
112*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @_Z10t7_typedefv
113*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
114*0a6a1f1dSLionel Sambuc }
115*0a6a1f1dSLionel Sambuc
t7_using()116*0a6a1f1dSLionel Sambuc void t7_using() {
117*0a6a1f1dSLionel Sambuc using A = struct {
118*0a6a1f1dSLionel Sambuc int a;
119*0a6a1f1dSLionel Sambuc int b;
120*0a6a1f1dSLionel Sambuc };
121*0a6a1f1dSLionel Sambuc __asm mov eax, [eax].A.b
122*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @_Z8t7_usingv
123*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
124*0a6a1f1dSLionel Sambuc }
125*0a6a1f1dSLionel Sambuc
t8()126*0a6a1f1dSLionel Sambuc void t8() {
127*0a6a1f1dSLionel Sambuc __asm some_label:
128*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @_Z2t8v()
129*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "L__MSASMLABEL_.1__some_label:", "~{dirflag},~{fpsr},~{flags}"()
130*0a6a1f1dSLionel Sambuc struct A {
131*0a6a1f1dSLionel Sambuc static void g() {
132*0a6a1f1dSLionel Sambuc __asm jmp some_label ; This should jump forwards
133*0a6a1f1dSLionel Sambuc __asm some_label:
134*0a6a1f1dSLionel Sambuc __asm nop
135*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define internal void @_ZZ2t8vEN1A1gEv()
136*0a6a1f1dSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "jmp L__MSASMLABEL_.2__some_label\0A\09L__MSASMLABEL_.2__some_label:\0A\09nop", "~{dirflag},~{fpsr},~{flags}"()
137*0a6a1f1dSLionel Sambuc }
138*0a6a1f1dSLionel Sambuc };
139*0a6a1f1dSLionel Sambuc A::g();
140*0a6a1f1dSLionel Sambuc }
141*0a6a1f1dSLionel Sambuc
142