1 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - -std=c++17 %s | FileCheck %s --implicit-check-not=@_ZSt4move
4 template<typename T
> constexpr T
&&move(T
&val
) { return static_cast<T
&&>(val
); }
5 template<typename T
> constexpr T
&&move_if_noexcept(T
&val
);
6 template<typename T
> constexpr T
&&forward(T
&val
);
7 template<typename U
, typename T
> constexpr T
&&forward_like(T
&&val
);
8 template<typename T
> constexpr const T
&as_const(T
&val
);
11 template<typename T
, typename U
> T
move(U source
, U source_end
, T dest
);
15 extern "C" void take(T
&&);
16 extern "C" void take_lval(const T
&);
20 // Check emission of a constant-evaluated call.
21 // CHECK-DAG: @move_a = constant ptr @a
22 T
&&move_a
= std::move(a
);
23 // CHECK-DAG: @move_if_noexcept_a = constant ptr @a
24 T
&&move_if_noexcept_a
= std::move_if_noexcept(a
);
25 // CHECK-DAG: @forward_a = constant ptr @a
26 T
&forward_a
= std::forward
<T
&>(a
);
27 // CHECK-DAG: @forward_like_a = constant ptr @a
28 T
&forward_like_a
= std::forward_like
<int&>(a
);
30 // Check emission of a non-constant call.
31 // CHECK-LABEL: define {{.*}} void @test
32 extern "C" void test(T
&t
) {
33 // CHECK: store ptr %{{.*}}, ptr %[[T_REF:[^,]*]]
34 // CHECK: %0 = load ptr, ptr %[[T_REF]]
35 // CHECK: call void @take(ptr {{.*}} %0)
37 // CHECK: %1 = load ptr, ptr %[[T_REF]]
38 // CHECK: call void @take(ptr {{.*}} %1)
39 take(std::move_if_noexcept(t
));
40 // CHECK: %2 = load ptr, ptr %[[T_REF]]
41 // CHECK: call void @take(ptr {{.*}} %2)
42 take(std::forward
<T
&&>(t
));
43 // CHECK: %3 = load ptr, ptr %[[T_REF]]
44 // CHECK: call void @take_lval(ptr {{.*}} %3)
45 take_lval(std::forward_like
<int&>(t
));
46 // CHECK: %4 = load ptr, ptr %[[T_REF]]
47 // CHECK: call void @take_lval(ptr {{.*}} %4)
48 take_lval(std::as_const
<T
&&>(t
));
50 // CHECK: call {{.*}} @_ZSt4moveI1TS0_ET_T0_S2_S1_
54 // CHECK: declare {{.*}} @_ZSt4moveI1TS0_ET_T0_S2_S1_
56 // Check that we instantiate and emit if the address is taken.
57 // CHECK-LABEL: define {{.*}} @use_address
58 extern "C" void *use_address() {
59 // CHECK: ret {{.*}} @_ZSt4moveIiEOT_RS0_
60 return (void*)&std::move
<int>;
63 // CHECK: define {{.*}} ptr @_ZSt4moveIiEOT_RS0_(ptr
65 extern "C" void take_const_int_rref(const int &&);
66 // CHECK-LABEL: define {{.*}} @move_const_int(
67 extern "C" void move_const_int() {
68 // CHECK: store i32 5, ptr %[[N_ADDR:[^,]*]]
70 // CHECK: call {{.*}} @take_const_int_rref(ptr {{.*}} %[[N_ADDR]])
71 take_const_int_rref(std::move(n
));