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