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 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", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE) 26 // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3Bar3ptrE) 27 // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE) 28 // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE) 29 // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE) 30 } 31 32 int gvar = 10; 33 void t2() { 34 int lvar = 10; 35 __asm mov eax, offset Foo::ptr 36 __asm mov eax, offset Foo::Bar::ptr 37 // CHECK: t2 38 // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3ptrE) 39 // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @_ZN3Foo3Bar3ptrE) 40 } 41 42 // CHECK-LABEL: define void @_Z2t3v() 43 void t3() { 44 __asm mov eax, LENGTH Foo::ptr 45 // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() 46 __asm mov eax, LENGTH Foo::Bar::ptr 47 // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() 48 __asm mov eax, LENGTH Foo::arr 49 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 50 __asm mov eax, LENGTH Foo::Bar::arr 51 // CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"() 52 53 __asm mov eax, TYPE Foo::ptr 54 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 55 __asm mov eax, TYPE Foo::Bar::ptr 56 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 57 __asm mov eax, TYPE Foo::arr 58 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 59 __asm mov eax, TYPE Foo::Bar::arr 60 // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() 61 62 __asm mov eax, SIZE Foo::ptr 63 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 64 __asm mov eax, SIZE Foo::Bar::ptr 65 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 66 __asm mov eax, SIZE Foo::arr 67 // CHECK: call void asm sideeffect inteldialect "mov eax, $$16", "~{eax},~{dirflag},~{fpsr},~{flags}"() 68 __asm mov eax, SIZE Foo::Bar::arr 69 // CHECK: call void asm sideeffect inteldialect "mov eax, $$2", "~{eax},~{dirflag},~{fpsr},~{flags}"() 70 71 } 72 73 struct T4 { 74 int x; 75 static int y; 76 void test(); 77 }; 78 79 // CHECK-LABEL: define void @_ZN2T44testEv( 80 void T4::test() { 81 // CHECK: [[T0:%.*]] = alloca [[T4:%.*]]*, 82 // CHECK: [[THIS:%.*]] = load [[T4]]** [[T0]] 83 // CHECK: [[X:%.*]] = getelementptr inbounds [[T4]]* [[THIS]], i32 0, i32 0 84 __asm mov eax, x; 85 // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* [[X]]) 86 __asm mov y, eax; 87 // CHECK: call void asm sideeffect inteldialect "mov dword ptr $0, eax", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* @_ZN2T41yE) 88 } 89 90 template <class T> struct T5 { 91 template <class U> static T create(U); 92 void run(); 93 }; 94 // CHECK-LABEL: define void @_Z5test5v() 95 void test5() { 96 // CHECK: [[X:%.*]] = alloca i32 97 // CHECK: [[Y:%.*]] = alloca i32 98 int x, y; 99 __asm push y 100 // CHECK: call void asm sideeffect inteldialect "push dword ptr $0", "=*m,~{esp},~{dirflag},~{fpsr},~{flags}"(i32* [[Y]]) 101 __asm call T5<int>::create<float> 102 // CHECK: call void asm sideeffect inteldialect "call $0", "r,~{dirflag},~{fpsr},~{flags}"(i32 (float)* @_ZN2T5IiE6createIfEEiT_) 103 __asm mov x, eax 104 // CHECK: call void asm sideeffect inteldialect "mov dword ptr $0, eax", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* [[X]]) 105 } 106 107 // Just verify this doesn't emit an error. 108 void test6() { 109 __asm { 110 a: 111 jmp a 112 } 113 } 114 115 void t7_struct() { 116 struct A { 117 int a; 118 int b; 119 }; 120 __asm mov eax, [eax].A.b 121 // CHECK-LABEL: define void @_Z9t7_structv 122 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 123 } 124 125 void t7_typedef() { 126 typedef struct { 127 int a; 128 int b; 129 } A; 130 __asm mov eax, [eax].A.b 131 // CHECK-LABEL: define void @_Z10t7_typedefv 132 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 133 } 134 135 void t7_using() { 136 using A = struct { 137 int a; 138 int b; 139 }; 140 __asm mov eax, [eax].A.b 141 // CHECK-LABEL: define void @_Z8t7_usingv 142 // CHECK: call void asm sideeffect inteldialect "mov eax, [eax].4", "~{eax},~{dirflag},~{fpsr},~{flags}"() 143 } 144