1// RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -emit-llvm -O0 -o - | FileCheck %s 2 3struct B { 4 int mb; 5}; 6 7class D : public B { 8public: 9 int getmb() { return mb; } 10}; 11 12void foo() { 13 D d; 14 //CHECK-LABEL: foo 15 //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)* 16 //CHECK: call spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)* 17 d.getmb(); 18} 19 20//Derived and Base are in the same address space. 21 22//CHECK: define linkonce_odr spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)* {{[^,]*}} %this) 23//CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)* 24 25 26// Calling base method through multiple inheritance. 27 28class B2 { 29 public: 30 void baseMethod() const { } 31 int &getRef() { return bb; } 32 int bb; 33}; 34 35class Derived : public B, public B2 { 36 public: 37 void work() const { baseMethod(); } 38 // CHECK-LABEL: work 39 // CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)* 40}; 41 42void pr43145(const Derived *argDerived) { 43 argDerived->work(); 44} 45 46// Casting from base to derived. 47 48void pr43145_2(B *argB) { 49 Derived *x = (Derived*)argB; 50 // CHECK-LABEL: @_Z9pr43145_2 51 // CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)* 52} 53 54// Assigning to reference returned by base class method through derived class. 55 56void pr43145_3(int n) { 57 Derived d; 58 d.getRef() = n; 59 60 // CHECK-LABEL: @_Z9pr43145_3 61 // CHECK: addrspacecast %class.Derived* %d to %class.Derived addrspace(4)* 62 // CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)* 63 // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv 64 65 private Derived *pd = &d; 66 pd->getRef() = n; 67 68 // CHECK: addrspacecast %class.Derived* %4 to %class.Derived addrspace(4)* 69 // CHECK: bitcast i8 addrspace(4)* %add.ptr1 to %class.B2 addrspace(4)* 70 // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv 71} 72 73// Implicit conversion of derived to base. 74 75void functionWithBaseArgPtr(class B2 *b) {} 76void functionWithBaseArgRef(class B2 &b) {} 77 78void pr43145_4() { 79 Derived d; 80 functionWithBaseArgPtr(&d); 81 functionWithBaseArgRef(d); 82} 83