1 // REQUIRES: x86-registered-target
2 // RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - -std=c++11 | FileCheck %s
3 
4 // rdar://13645930
5 
6 struct Foo {
7   static int *ptr;
8   static int a, b;
9   int arr[4];
10   struct Bar {
11     static int *ptr;
12     char arr[2];
13   };
14 };
15 
t1()16 void t1() {
17   Foo::ptr = (int *)0xDEADBEEF;
18   Foo::Bar::ptr = (int *)0xDEADBEEF;
19   __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]
24 // CHECK: @_Z2t1v
25 // 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)
26 }
27 
28 int gvar = 10;
t2()29 void t2() {
30   int lvar = 10;
31   __asm mov eax, offset Foo::ptr
32   __asm mov eax, offset Foo::Bar::ptr
33 // CHECK: t2
34 // CHECK: call void asm sideeffect inteldialect "mov eax, $0\0A\09mov eax, $1", "r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE, i32** @_ZN3Foo3Bar3ptrE)
35 }
36 
37 // CHECK-LABEL: define void @_Z2t3v()
t3()38 void 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
53 // 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}"()
54 
55 }
56 
57 struct T4 {
58   int x;
59   static int y;
60   void test();
61 };
62 
63 // CHECK-LABEL: define void @_ZN2T44testEv(
test()64 void T4::test() {
65 // CHECK: [[T0:%.*]] = alloca [[T4:%.*]]*,
66 // CHECK: [[THIS:%.*]] = load [[T4]]** [[T0]]
67 // CHECK: [[X:%.*]] = getelementptr inbounds [[T4]]* [[THIS]], i32 0, i32 0
68   __asm mov eax, x;
69   __asm mov y, eax;
70 // 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* {{.*}})
71 }
72 
73 template <class T> struct T5 {
74   template <class U> static T create(U);
75   void run();
76 };
77 // CHECK-LABEL: define void @_Z5test5v()
test5()78 void test5() {
79   // CHECK: [[X:%.*]] = alloca i32
80   // CHECK: [[Y:%.*]] = alloca i32
81   int x, y;
82   __asm push y
83   __asm call T5<int>::create<float>
84   __asm mov x, eax
85   // 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_)
86 }
87 
88 // Just verify this doesn't emit an error.
test6()89 void test6() {
90   __asm {
91    a:
92    jmp a
93   }
94 }
95 
t7_struct()96 void 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 
t7_typedef()106 void 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 
t7_using()116 void 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 }
125 
t8()126 void 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 
142