Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / constructor-destructor-return-this.cpp
blobd71949f25af0faa6f6145eb1db0afc1686319158
1 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-unknown-linux | FileCheck --check-prefix=CHECKGEN %s
2 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios6.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKARM %s
3 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios5.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKIOS5 %s
4 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=wasm32-unknown-unknown \
5 //RUN: | FileCheck --check-prefix=CHECKARM %s
6 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
7 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
8 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
9 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s
10 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s
11 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
13 // Make sure we attach the 'returned' attribute to the 'this' parameter of
14 // constructors and destructors which return this (and only these cases)
16 class A {
17 public:
18 A();
19 virtual ~A();
21 private:
22 int x_;
25 class B : public A {
26 public:
27 B(int *i);
28 virtual ~B();
30 private:
31 int *i_;
34 B::B(int *i) : i_(i) { }
35 B::~B() { }
37 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BC2EPi(ptr {{[^,]*}} %this, ptr noundef %i)
38 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BC1EPi(ptr {{[^,]*}} %this, ptr noundef %i)
39 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(ptr {{[^,]*}} %this)
40 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(ptr {{[^,]*}} %this)
42 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1BC2EPi(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i)
43 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1BC1EPi(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i)
44 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1BD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
45 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1BD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
47 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1BC2EPi(ptr {{[^,]*}} %this, ptr noundef %i)
48 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1BC1EPi(ptr {{[^,]*}} %this, ptr noundef %i)
49 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1BD2Ev(ptr {{[^,]*}} %this)
50 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1BD1Ev(ptr {{[^,]*}} %this)
52 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1BC2EPi(ptr {{[^,]*}} %this, ptr noundef %i)
53 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1BC1EPi(ptr {{[^,]*}} %this, ptr noundef %i)
54 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1BD2Ev(ptr {{[^,]*}} %this)
55 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1BD1Ev(ptr {{[^,]*}} %this)
57 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1BC2EPi(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i)
58 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1BC1EPi(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i)
59 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1BD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
60 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1BD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
62 // CHECKMS-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0B@@QAE@PAH@Z"(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i)
63 // CHECKMS-LABEL: define dso_local x86_thiscallcc void @"??1B@@UAE@XZ"(ptr {{[^,]*}} %this)
65 class C : public A, public B {
66 public:
67 C(int *i, char *c);
68 virtual ~C();
69 private:
70 char *c_;
73 C::C(int *i, char *c) : B(i), c_(c) { }
74 C::~C() { }
76 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CC2EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
77 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CC1EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
78 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD2Ev(ptr {{[^,]*}} %this)
79 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD1Ev(ptr {{[^,]*}} %this)
80 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD1Ev(ptr noundef %this)
81 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(ptr {{[^,]*}} %this)
82 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(ptr noundef %this)
84 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1CC2EPiPc(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
85 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1CC1EPiPc(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
86 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1CD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
87 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1CD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
88 // CHECKARM-LABEL: define{{.*}} ptr @_ZThn8_N1CD1Ev(ptr noundef %this)
89 // CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZThn16_N1CD1Ev(ptr noundef %this)
90 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(ptr {{[^,]*}} %this)
91 // CHECKARM-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(ptr noundef %this)
92 // CHECKAARCH64RET-LABEL: define{{.*}} void @_ZThn16_N1CD0Ev(ptr noundef %this)
94 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1CC2EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
95 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1CC1EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
96 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1CD2Ev(ptr {{[^,]*}} %this)
97 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1CD1Ev(ptr {{[^,]*}} %this)
98 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZThn8_N1CD1Ev(ptr noundef %this)
99 // CHECKI686RET-LABEL: define{{.*}} void @_ZN1CD0Ev(ptr {{[^,]*}} %this)
100 // CHECKI686RET-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(ptr noundef %this)
102 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1CC2EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
103 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1CC1EPiPc(ptr {{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
104 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1CD2Ev(ptr {{[^,]*}} %this)
105 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1CD1Ev(ptr {{[^,]*}} %this)
106 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZThn8_N1CD1Ev(ptr noundef %this)
107 // CHECKIOS5-LABEL: define{{.*}} void @_ZN1CD0Ev(ptr {{[^,]*}} %this)
108 // CHECKIOS5-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(ptr noundef %this)
110 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1CC2EPiPc(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
111 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1CC1EPiPc(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
112 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1CD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
113 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1CD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
114 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZThn16_N1CD1Ev(ptr noundef %this)
115 // CHECKFUCHSIA-LABEL: define{{.*}} void @_ZN1CD0Ev(ptr {{[^,]*}} %this)
116 // CHECKFUCHSIA-LABEL: define{{.*}} void @_ZThn16_N1CD0Ev(ptr noundef %this)
118 // CHECKMS-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0C@@QAE@PAHPAD@Z"(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %i, ptr noundef %c)
119 // CHECKMS-LABEL: define dso_local x86_thiscallcc void @"??1C@@UAE@XZ"(ptr {{[^,]*}} %this)
121 class D : public virtual A {
122 public:
123 D();
124 ~D();
127 D::D() { }
128 D::~D() { }
130 // CHECKGEN-LABEL: define{{.*}} void @_ZN1DC2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
131 // CHECKGEN-LABEL: define{{.*}} void @_ZN1DC1Ev(ptr {{[^,]*}} %this)
132 // CHECKGEN-LABEL: define{{.*}} void @_ZN1DD2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
133 // CHECKGEN-LABEL: define{{.*}} void @_ZN1DD1Ev(ptr {{[^,]*}} %this)
135 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1DC2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %vtt)
136 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1DC1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
137 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1DD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %vtt)
138 // CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} ptr @_ZN1DD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
140 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1DC2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
141 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1DC1Ev(ptr {{[^,]*}} %this)
142 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1DD2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
143 // CHECKI686RET-LABEL: define{{.*}} ptr @_ZN1DD1Ev(ptr {{[^,]*}} %this)
145 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1DC2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
146 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1DC1Ev(ptr {{[^,]*}} %this)
147 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1DD2Ev(ptr {{[^,]*}} %this, ptr noundef %vtt)
148 // CHECKIOS5-LABEL: define{{.*}} ptr @_ZN1DD1Ev(ptr {{[^,]*}} %this)
150 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1DC2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %vtt)
151 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1DC1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
152 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1DD2Ev(ptr {{[^,]*}} returned{{[^,]*}} %this, ptr noundef %vtt)
153 // CHECKFUCHSIA-LABEL: define{{.*}} ptr @_ZN1DD1Ev(ptr {{[^,]*}} returned{{[^,]*}} %this)
155 // CHECKMS-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0D@@QAE@XZ"(ptr {{[^,]*}} returned{{[^,]*}} %this, i32 noundef %is_most_derived)
156 // CHECKMS-LABEL: define dso_local x86_thiscallcc void @"??1D@@UAE@XZ"(ptr{{[^,]*}} %this)
158 class E {
159 public:
160 E();
161 virtual ~E();
164 E* gete();
166 void test_destructor() {
167 const E& e1 = E();
168 E* e2 = gete();
169 e2->~E();
172 // CHECKARM-LABEL,CHECKFUCHSIA-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_Z15test_destructorv()
174 // Verify that virtual calls to destructors are not marked with a 'returned'
175 // this parameter at the call site...
176 // CHECKARM,CHECKAARCH64RET: [[VFN:%.*]] = getelementptr inbounds ptr, ptr
177 // CHECKARM,CHECKAARCH64RET: [[THUNK:%.*]] = load ptr, ptr [[VFN]]
178 // CHECKFUCHSIA: [[THUNK:%.*]] = call ptr @llvm.load.relative.i32(ptr {{.*}}, i32 0)
179 // CHECKARM,CHECKFUCHSIA,CHECKAARCH64RET: call noundef ptr [[THUNK]](ptr {{[^,]*}} %
181 // ...but static calls create declarations with 'returned' this
182 // CHECKARM,CHECKFUCHSIA,CHECKAARCH64RET: {{%.*}} = call noundef ptr @_ZN1ED1Ev(ptr {{[^,]*}} %
184 // CHECKARM,CHECKFUCHSIA,CHECKAARCH64RET: declare noundef ptr @_ZN1ED1Ev(ptr {{[^,]*}} returned{{[^,]*}})