| 1 |
// RUN: %clang_cc1 -std=c++11 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 |
// RUN: %clang_cc1 -std=c++11 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s |
| 5 |
// RUN: %clang_cc1 -std=c++11 -triple aarch64-none-linux-android21 -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s |
| 7 |
|
| 8 |
class x { |
| 9 |
public: int operator=(int); |
| 10 |
}; |
| 11 |
void a() { |
| 12 |
x a; |
| 13 |
a = 1u; |
| 14 |
} |
| 15 |
|
| 16 |
// CIR: cir.func {{.*}} @_ZN1xaSEi(!cir.ptr<!rec_x>, !s32i) |
| 17 |
// CIR: cir.func{{.*}} @_Z1av() |
| 18 |
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_x, !cir.ptr<!rec_x>, ["a"] |
| 19 |
// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i |
| 20 |
// CIR: %[[RET:.*]] = cir.call @_ZN1xaSEi(%[[A_ADDR]], %[[ONE]]) : (!cir.ptr<!rec_x>, !s32i) -> !s32i |
| 21 |
|
| 22 |
// LLVM: define{{.*}} @_Z1av(){{.*}} |
| 23 |
// OGCG: define{{.*}} @_Z1av() |
| 24 |
|
| 25 |
void f(int i, int j) { |
| 26 |
(i += j) = 17; |
| 27 |
} |
| 28 |
|
| 29 |
// CIR: cir.func{{.*}} @_Z1fii(%arg0: !s32i {{.*}}, %arg1: !s32i {{.*}}) |
| 30 |
// CIR: %[[I_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] |
| 31 |
// CIR: %[[J_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["j", init] |
| 32 |
// CIR: cir.store %arg0, %[[I_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 33 |
// CIR: cir.store %arg1, %[[J_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 34 |
// CIR: %[[SEVENTEEN:.*]] = cir.const #cir.int<17> : !s32i |
| 35 |
// CIR: %[[J_LOAD:.*]] = cir.load align(4) %[[J_ADDR]] : !cir.ptr<!s32i>, !s32i |
| 36 |
// CIR: %[[I_LOAD:.*]] = cir.load align(4) %[[I_ADDR]] : !cir.ptr<!s32i>, !s32i |
| 37 |
// CIR: %[[ADD:.*]] = cir.binop(add, %[[I_LOAD]], %[[J_LOAD]]) nsw : !s32i |
| 38 |
// CIR: cir.store align(4) %[[ADD]], %[[I_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 39 |
// CIR: cir.store align(4) %[[SEVENTEEN]], %[[I_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 40 |
// CIR: cir.return |
| 41 |
|
| 42 |
// Ensure that we use memcpy when we would have selected a trivial assignment |
| 43 |
// operator, even for a non-trivially-copyable type. |
| 44 |
struct A { |
| 45 |
A &operator=(const A&); |
| 46 |
}; |
| 47 |
struct B { |
| 48 |
B(const B&); |
| 49 |
B &operator=(const B&) = default; |
| 50 |
int n; |
| 51 |
}; |
| 52 |
struct C { |
| 53 |
A a; |
| 54 |
B b[16]; |
| 55 |
}; |
| 56 |
void copy_c(C &c1, C &c2) { |
| 57 |
c1 = c2; |
| 58 |
} |
| 59 |
|
| 60 |
// CIR: cir.func private @_ZN1AaSERKS_(!cir.ptr<!rec_A>, !cir.ptr<!rec_A>) -> !cir.ptr<!rec_A> |
| 61 |
// CIR: cir.func private @memcpy(!cir.ptr<!void>, !cir.ptr<!void>, !u64i) -> !cir.ptr<!void> |
| 62 |
|
| 63 |
// Implicit assignment operator for C. |
| 64 |
|
| 65 |
// CIR: cir.func {{.*}} @_ZN1CaSERKS_(%arg0: !cir.ptr<!rec_C> {{.*}}, %arg1: !cir.ptr<!rec_C> {{.*}}) -> !cir.ptr<!rec_C> |
| 66 |
// CIR: %[[THIS_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["this", init] |
| 67 |
// CIR: %[[ARG1_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["", init, const] |
| 68 |
// CIR: %[[RET_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["__retval"] |
| 69 |
// CIR: cir.store %arg0, %[[THIS_ADDR]] |
| 70 |
// CIR: cir.store %arg1, %[[ARG1_ADDR]] |
| 71 |
// CIR: %[[THIS:.*]] = cir.load{{.*}} %[[THIS_ADDR]] |
| 72 |
// CIR: %[[A_MEMBER:.*]] = cir.get_member %[[THIS]][0] {name = "a"} |
| 73 |
// CIR: %[[ARG1_LOAD:.*]] = cir.load{{.*}} %[[ARG1_ADDR]] |
| 74 |
// CIR: %[[A_MEMBER_2:.*]] = cir.get_member %[[ARG1_LOAD]][0] {name = "a"} |
| 75 |
// CIR: %[[C_A:.*]] = cir.call @_ZN1AaSERKS_(%[[A_MEMBER]], %[[A_MEMBER_2]]) |
| 76 |
// CIR: %[[B_MEMBER:.*]] = cir.get_member %[[THIS]][1] {name = "b"} |
| 77 |
// CIR: %[[B_VOID_PTR:.*]] = cir.cast bitcast %[[B_MEMBER]] : !cir.ptr<!cir.array<!rec_B x 16>> -> !cir.ptr<!void> |
| 78 |
// CIR: %[[RET_LOAD:.*]] = cir.load %[[ARG1_ADDR]] |
| 79 |
// CIR: %[[B_MEMBER_2:.*]] = cir.get_member %[[RET_LOAD]][1] {name = "b"} |
| 80 |
// CIR: %[[B_VOID_PTR_2:.*]] = cir.cast bitcast %[[B_MEMBER_2]] : !cir.ptr<!cir.array<!rec_B x 16>> -> !cir.ptr<!void> |
| 81 |
// CIR: %[[SIZE:.*]] = cir.const #cir.int<64> : !u64i |
| 82 |
// CIR: %[[COUNT:.*]] = cir.call @memcpy(%[[B_VOID_PTR]], %[[B_VOID_PTR_2]], %[[SIZE]]) |
| 83 |
// CIR: cir.store %[[THIS]], %[[RET_ADDR]] |
| 84 |
// CIR: %[[RET_VAL:.*]] = cir.load{{.*}} %[[RET_ADDR]] |
| 85 |
// CIR: cir.return %[[RET_VAL]] |
| 86 |
|
| 87 |
// CIR: cir.func{{.*}} @_Z6copy_cR1CS0_(%arg0: !cir.ptr<!rec_C> {{.*}}, %arg1: !cir.ptr<!rec_C> {{.*}}) |
| 88 |
// CIR: %[[C1_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["c1", init, const] |
| 89 |
// CIR: %[[C2_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["c2", init, const] |
| 90 |
// CIR: cir.store %arg0, %[[C1_ADDR]] |
| 91 |
// CIR: cir.store %arg1, %[[C2_ADDR]] |
| 92 |
// CIR: %[[C2_LOAD:.*]] = cir.load{{.*}} %[[C2_ADDR]] |
| 93 |
// CIR: %[[C1_LOAD:.*]] = cir.load{{.*}} %[[C1_ADDR]] |
| 94 |
// CIR: %[[RET:.*]] = cir.call @_ZN1CaSERKS_(%[[C1_LOAD]], %[[C2_LOAD]]) |
| 95 |
|
| 96 |
struct D { |
| 97 |
D &operator=(const D&); |
| 98 |
}; |
| 99 |
struct E { |
| 100 |
D &get_d_ref() { return d; } |
| 101 |
private: |
| 102 |
D d; |
| 103 |
}; |
| 104 |
|
| 105 |
void copy_ref_to_ref(E &e1, E &e2) { |
| 106 |
e1.get_d_ref() = e2.get_d_ref(); |
| 107 |
} |
| 108 |
|
| 109 |
// The call to e2.get_d_ref() must occur before the call to e1.get_d_ref(). |
| 110 |
|
| 111 |
// CIR: cir.func{{.*}} @_Z15copy_ref_to_refR1ES0_(%arg0: !cir.ptr<!rec_E> {{.*}}, %arg1: !cir.ptr<!rec_E> {{.*}}) |
| 112 |
// CIR: %[[E1_ADDR:.*]] = cir.alloca !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>>, ["e1", init, const] |
| 113 |
// CIR: %[[E2_ADDR:.*]] = cir.alloca !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>>, ["e2", init, const] |
| 114 |
// CIR: cir.store %arg0, %[[E1_ADDR]] : !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>> |
| 115 |
// CIR: cir.store %arg1, %[[E2_ADDR]] : !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>> |
| 116 |
// CIR: %[[E2:.*]] = cir.load %[[E2_ADDR]] |
| 117 |
// CIR: %[[D2_REF:.*]] = cir.call @_ZN1E9get_d_refEv(%[[E2]]) |
| 118 |
// CIR: %[[E1:.*]] = cir.load %[[E1_ADDR]] |
| 119 |
// CIR: %[[D1_REF:.*]] = cir.call @_ZN1E9get_d_refEv(%[[E1]]) |
| 120 |
// CIR: %[[D1_REF_2:.*]] = cir.call @_ZN1DaSERKS_(%[[D1_REF]], %[[D2_REF]]) |
| 121 |
// CIR: cir.return |
| 122 |
|
| 123 |
// LLVM: define{{.*}} void @_Z15copy_ref_to_refR1ES0_(ptr %[[ARG0:.*]], ptr %[[ARG1:.*]]){{.*}} { |
| 124 |
// LLVM: %[[E1_ADDR:.*]] = alloca ptr |
| 125 |
// LLVM: %[[E2_ADDR:.*]] = alloca ptr |
| 126 |
// LLVM: store ptr %[[ARG0]], ptr %[[E1_ADDR]] |
| 127 |
// LLVM: store ptr %[[ARG1]], ptr %[[E2_ADDR]] |
| 128 |
// LLVM: %[[E2:.*]] = load ptr, ptr %[[E2_ADDR]] |
| 129 |
// LLVM: %[[D2_REF:.*]] = call ptr @_ZN1E9get_d_refEv(ptr %[[E2]]) |
| 130 |
// LLVM: %[[E1:.*]] = load ptr, ptr %[[E1_ADDR]] |
| 131 |
// LLVM: %[[D1_REF:.*]] = call ptr @_ZN1E9get_d_refEv(ptr %[[E1]]) |
| 132 |
// LLVM: %[[D1_REF_2:.*]] = call ptr @_ZN1DaSERKS_(ptr %[[D1_REF]], ptr %[[D2_REF]]) |
| 133 |
|
| 134 |
// OGCG: define{{.*}} void @_Z15copy_ref_to_refR1ES0_(ptr{{.*}} %[[ARG0:.*]], ptr{{.*}} %[[ARG1:.*]]) |
| 135 |
// OGCG: %[[E1_ADDR:.*]] = alloca ptr |
| 136 |
// OGCG: %[[E2_ADDR:.*]] = alloca ptr |
| 137 |
// OGCG: store ptr %[[ARG0]], ptr %[[E1_ADDR]] |
| 138 |
// OGCG: store ptr %[[ARG1]], ptr %[[E2_ADDR]] |
| 139 |
// OGCG: %[[E2:.*]] = load ptr, ptr %[[E2_ADDR]] |
| 140 |
// OGCG: %[[D2_REF:.*]] = call{{.*}} ptr @_ZN1E9get_d_refEv(ptr{{.*}} %[[E2]]) |
| 141 |
// OGCG: %[[E1:.*]] = load ptr, ptr %[[E1_ADDR]] |
| 142 |
// OGCG: %[[D1_REF:.*]] = call{{.*}} ptr @_ZN1E9get_d_refEv(ptr{{.*}} %[[E1]]) |
| 143 |
// OGCG: %[[D1_REF_2:.*]] = call{{.*}} ptr @_ZN1DaSERKS_(ptr{{.*}} %[[D1_REF]], ptr{{.*}} %[[D2_REF]]) |