Debian Codegraph @

clang/test/CIR/CodeGen/cxx-special-member-attr.cpp

raw
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
4 struct Flub {
5 int a = 123;
6 };
7
8 struct Foo {
9 int a;
10
11 Foo() : a(123) {}
12 Foo(const Foo &other) : a(other.a) {}
13 Foo(Foo &&other) noexcept : a(other.a) { other.a = 0; }
14
15 Foo &operator=(const Foo &other) {
16 if (this != &other) {
17 a = other.a;
18 }
19 return *this;
20 }
21
22 Foo &operator=(Foo &&other) noexcept {
23 if (this != &other) {
24 a = other.a;
25 other.a = 0;
26 }
27 return *this;
28 }
29
30 ~Foo();
31 };
32
33 void trivial_func() {
34 Flub f1{};
35
36 Flub f2 = f1;
37 // Trivial copy constructors/assignments are replaced with cir.copy
38 // CIR: cir.copy {{.*}} : !cir.ptr<!rec_Flub>
39
40 Flub f3 = static_cast<Flub&&>(f1);
41 // CIR: @_ZN4FlubC1EOS_(%arg0: !cir.ptr<!rec_Flub> loc({{.*}}), %arg1: !cir.ptr<!rec_Flub> loc({{.*}})) special_member<#cir.cxx_ctor<!rec_Flub, move, trivial true>
42
43 f2 = f1;
44 // CIR: @_ZN4FlubaSERKS_(%arg0: !cir.ptr<!rec_Flub> loc({{.*}}), %arg1: !cir.ptr<!rec_Flub> loc({{.*}})) -> !cir.ptr<!rec_Flub> special_member<#cir.cxx_assign<!rec_Flub, copy, trivial true>>
45
46 f1 = static_cast<Flub&&>(f3);
47 // CIR: @_ZN4FlubaSEOS_(%arg0: !cir.ptr<!rec_Flub> loc({{.*}}), %arg1: !cir.ptr<!rec_Flub> loc({{.*}})) -> !cir.ptr<!rec_Flub> special_member<#cir.cxx_assign<!rec_Flub, move, trivial true>>
48 }
49
50 void non_trivial_func() {
51 Foo f1{};
52 // CIR: @_ZN3FooC2Ev(%arg0: !cir.ptr<!rec_Foo> loc({{.*}})) special_member<#cir.cxx_ctor<!rec_Foo, default>>
53
54 Foo f2 = f1;
55 // CIR: @_ZN3FooC2ERKS_(%arg0: !cir.ptr<!rec_Foo> loc({{.*}}), %arg1: !cir.ptr<!rec_Foo> loc({{.*}})) special_member<#cir.cxx_ctor<!rec_Foo, copy>>
56
57 Foo f3 = static_cast<Foo&&>(f1);
58 // CIR: @_ZN3FooC2EOS_(%arg0: !cir.ptr<!rec_Foo> loc({{.*}}), %arg1: !cir.ptr<!rec_Foo> loc({{.*}})) special_member<#cir.cxx_ctor<!rec_Foo, move>>
59
60 f2 = f1;
61 // CIR: @_ZN3FooaSERKS_(%arg0: !cir.ptr<!rec_Foo> loc({{.*}}), %arg1: !cir.ptr<!rec_Foo> loc({{.*}})) -> !cir.ptr<!rec_Foo> special_member<#cir.cxx_assign<!rec_Foo, copy>>
62
63 f1 = static_cast<Foo&&>(f3);
64 // CIR: @_ZN3FooaSEOS_(%arg0: !cir.ptr<!rec_Foo> loc({{.*}}), %arg1: !cir.ptr<!rec_Foo> loc({{.*}})) -> !cir.ptr<!rec_Foo> special_member<#cir.cxx_assign<!rec_Foo, move>>
65 // CIR: @_ZN3FooD1Ev(!cir.ptr<!rec_Foo>) special_member<#cir.cxx_dtor<!rec_Foo>>
66 }