Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / cxx1z-copy-omission.cpp
blobdb6671bcd301b84484dd92265d186d13d96f2c16
1 // RUN: %clang_cc1 -std=c++1z -emit-llvm -triple x86_64-linux-gnu -o - %s | FileCheck %s
3 struct A {
4 A(int);
5 A(A&&);
6 A(const A&);
7 ~A();
9 operator bool();
11 int arr[10];
14 A f();
15 void h();
17 // CHECK-LABEL: define {{.*}} @_Z1gv(
18 void g() {
19 // CHECK: %[[A:.*]] = alloca
20 // CHECK-NOT: alloca
21 // CHECK-NOT: call
22 // CHECK: call {{.*}} @_Z1fv(ptr sret({{.*}}) align 4 %[[A]])
23 A a = A( A{ f() } );
24 // CHECK-NOT: call
26 // CHECK: call void @_Z1hv(
27 h();
28 // CHECK-NOT: call
30 // CHECK: call void @_ZN1AD1Ev(ptr {{[^,]*}} %[[A]])
31 // CHECK-NOT: call
32 // CHECK-LABEL: }
35 void f(A);
37 // CHECK-LABEL: define {{.*}} @_Z1hv(
38 void h() {
39 // CHECK: %[[A:.*]] = alloca
40 // CHECK-NOT: alloca
41 // CHECK-NOT: call
43 // CHECK: call {{.*}} @_Z1fv(ptr sret({{.*}}) align 4 %[[A]])
44 // CHECK-NOT: call
45 // CHECK: call {{.*}} @_Z1f1A(ptr noundef %[[A]])
46 f(f());
47 // CHECK-NOT: call
48 // CHECK: call void @_ZN1AD1Ev(ptr {{[^,]*}} %[[A]])
50 // CHECK: call void @_Z1hv(
51 h();
53 // CHECK-NOT: call
54 // CHECK-LABEL: }
57 // We still pass classes with trivial copy/move constructors and destructors in
58 // registers, even if the copy is formally omitted.
59 struct B {
60 B(int);
61 int n;
64 B fB();
65 void fB(B);
67 // CHECK-LABEL: define {{.*}} @_Z1iv(
68 void i() {
69 // CHECK: %[[B:.*]] = alloca
70 // CHECK-NOT: alloca
71 // CHECK-NOT: call
73 // CHECK: %[[B_N:.*]] = call i32 @_Z2fBv()
74 // CHECK-NOT: call
75 // CHECK: store i32 %[[B_N]],
76 // CHECK-NOT: call
77 // CHECK: %[[B_N:.*]] = load i32
78 // CHECK-NOT: call
79 // CHECK: call void @_Z2fB1B(i32 %[[B_N]])
80 fB(fB());
82 // CHECK-LABEL: }
85 // CHECK-LABEL: define {{.*}} @_Z1jv(
86 void j() {
87 // CHECK: alloca ptr
88 // CHECK: %[[OUTERTEMP:.*]] = alloca %{{.*}}
89 // CHECK: %[[INNERTEMP:.*]] = alloca %{{.*}}
90 // CHECK: call void @_ZN1AC1Ei(ptr {{.*}} %[[INNERTEMP]], i32 noundef 1)
91 // CHECK: call noundef zeroext i1 @_ZN1AcvbEv(ptr {{.*}} %[[INNERTEMP]])
92 // CHECK: br i1
94 // CHECK: call void @_ZN1AC1EOS_(ptr {{.*}} %[[OUTERTEMP]], ptr {{.*}} %[[INNERTEMP]])
95 // CHECK: br label
97 // CHECK: call void @_ZN1AC1Ei(ptr {{.*}} %[[OUTERTEMP]], i32 noundef 2)
98 // CHECK: br label
100 // CHECK: call void @_ZN1AD1Ev(ptr {{.*}} %[[INNERTEMP]])
101 A &&a = A(1) ?: A(2);
103 // CHECK: call void @_Z1iv()
104 i();
106 // CHECK: call void @_ZN1AD1Ev(ptr {{.*}} %[[OUTERTEMP]])