xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/ms-inline-asm.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // REQUIRES: x86-64-registered-target
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -x c++ %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - | FileCheck %s
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // rdar://13645930
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc struct Foo {
7*f4a2713aSLionel Sambuc   static int *ptr;
8*f4a2713aSLionel Sambuc   static int a, b;
9*f4a2713aSLionel Sambuc   int arr[4];
10*f4a2713aSLionel Sambuc   struct Bar {
11*f4a2713aSLionel Sambuc     static int *ptr;
12*f4a2713aSLionel Sambuc     char arr[2];
13*f4a2713aSLionel Sambuc   };
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc void t1() {
17*f4a2713aSLionel Sambuc   Foo::ptr = (int *)0xDEADBEEF;
18*f4a2713aSLionel Sambuc   Foo::Bar::ptr = (int *)0xDEADBEEF;
19*f4a2713aSLionel Sambuc   __asm mov eax, Foo ::ptr
20*f4a2713aSLionel Sambuc   __asm mov eax, Foo :: Bar :: ptr
21*f4a2713aSLionel Sambuc   __asm mov eax, [Foo:: ptr]
22*f4a2713aSLionel Sambuc   __asm mov eax, dword ptr [Foo :: ptr]
23*f4a2713aSLionel Sambuc   __asm mov eax, dword ptr [Foo :: ptr]
24*f4a2713aSLionel Sambuc // CHECK: @_Z2t1v
25*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE)
26*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3Bar3ptrE)
27*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE)
28*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE)
29*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE)
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc int gvar = 10;
33*f4a2713aSLionel Sambuc void t2() {
34*f4a2713aSLionel Sambuc   int lvar = 10;
35*f4a2713aSLionel Sambuc   __asm mov eax, offset Foo::ptr
36*f4a2713aSLionel Sambuc   __asm mov eax, offset Foo::Bar::ptr
37*f4a2713aSLionel Sambuc // CHECK: t2
38*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE)
39*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3Bar3ptrE)
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2t3v()
43*f4a2713aSLionel Sambuc void t3() {
44*f4a2713aSLionel Sambuc   __asm mov eax, LENGTH Foo::ptr
45*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"()
46*f4a2713aSLionel Sambuc   __asm mov eax, LENGTH Foo::Bar::ptr
47*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"()
48*f4a2713aSLionel Sambuc   __asm mov eax, LENGTH Foo::arr
49*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
50*f4a2713aSLionel Sambuc   __asm mov eax, LENGTH Foo::Bar::arr
51*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"()
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc   __asm mov eax, TYPE Foo::ptr
54*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
55*f4a2713aSLionel Sambuc   __asm mov eax, TYPE Foo::Bar::ptr
56*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
57*f4a2713aSLionel Sambuc   __asm mov eax, TYPE Foo::arr
58*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
59*f4a2713aSLionel Sambuc   __asm mov eax, TYPE Foo::Bar::arr
60*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"()
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc   __asm mov eax, SIZE Foo::ptr
63*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
64*f4a2713aSLionel Sambuc   __asm mov eax, SIZE Foo::Bar::ptr
65*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
66*f4a2713aSLionel Sambuc   __asm mov eax, SIZE Foo::arr
67*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$16", "~{eax},~{dirflag},~{fpsr},~{flags}"()
68*f4a2713aSLionel Sambuc   __asm mov eax, SIZE Foo::Bar::arr
69*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"()
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc }
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc struct T4 {
74*f4a2713aSLionel Sambuc   int x;
75*f4a2713aSLionel Sambuc   static int y;
76*f4a2713aSLionel Sambuc   void test();
77*f4a2713aSLionel Sambuc };
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN2T44testEv(
80*f4a2713aSLionel Sambuc void T4::test() {
81*f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = alloca [[T4:%.*]]*,
82*f4a2713aSLionel Sambuc // CHECK: [[THIS:%.*]] = load [[T4]]** [[T0]]
83*f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = getelementptr inbounds [[T4]]* [[THIS]], i32 0, i32 0
84*f4a2713aSLionel Sambuc   __asm mov eax, x;
85*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* [[X]])
86*f4a2713aSLionel Sambuc   __asm mov y, eax;
87*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect inteldialect "mov dword ptr $0, eax", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* @_ZN2T41yE)
88*f4a2713aSLionel Sambuc }
89*f4a2713aSLionel Sambuc 
90*f4a2713aSLionel Sambuc template <class T> struct T5 {
91*f4a2713aSLionel Sambuc   template <class U> static T create(U);
92*f4a2713aSLionel Sambuc   void run();
93*f4a2713aSLionel Sambuc };
94*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z5test5v()
95*f4a2713aSLionel Sambuc void test5() {
96*f4a2713aSLionel Sambuc   // CHECK: [[X:%.*]] = alloca i32
97*f4a2713aSLionel Sambuc   // CHECK: [[Y:%.*]] = alloca i32
98*f4a2713aSLionel Sambuc   int x, y;
99*f4a2713aSLionel Sambuc   __asm push y
100*f4a2713aSLionel Sambuc   // CHECK: call void asm sideeffect inteldialect "push dword ptr $0", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* [[Y]])
101*f4a2713aSLionel Sambuc   __asm call T5<int>::create<float>
102*f4a2713aSLionel Sambuc   // CHECK: call void asm sideeffect inteldialect "call $0", "r,~{dirflag},~{fpsr},~{flags}"(i32 (float)* @_ZN2T5IiE6createIfEEiT_)
103*f4a2713aSLionel Sambuc   __asm mov x, eax
104*f4a2713aSLionel Sambuc   // CHECK: call void asm sideeffect inteldialect "mov dword ptr $0, eax", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* [[X]])
105*f4a2713aSLionel Sambuc }
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc // Just verify this doesn't emit an error.
108*f4a2713aSLionel Sambuc void test6() {
109*f4a2713aSLionel Sambuc   __asm {
110*f4a2713aSLionel Sambuc    a:
111*f4a2713aSLionel Sambuc    jmp a
112*f4a2713aSLionel Sambuc   }
113*f4a2713aSLionel Sambuc }
114