1 // RUN: %clang_cc1 -fno-elide-constructors -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
2 // RUN: %clang_cc1 -fno-elide-constructors -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | opt -verify
3 // FIXME: remove the call to "opt" once the tests are running the Clang verifier automatically again.
10 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %1)
11 // CHECK-NEXT: ret i32 %call
12 [[clang::musttail
]] return Bar(x
);
14 [[clang::musttail
]] return Baz(x
); // CHECK: %call1 = musttail call noundef i32 @_Z3Bazi(i32 noundef %3)
20 [[clang::musttail
]] return Bar(Bar(x
));
24 // CHECK: %call1 = musttail call noundef i32 @_Z3Bari(i32 noundef %call)
28 static int StaticMethod(int x
);
29 int MemberFunction(int x
);
35 int Foo::TailFrom(int x
) {
36 [[clang::musttail
]] return MemberFunction(x
);
39 // CHECK: %call = musttail call noundef i32 @_ZN3Foo14MemberFunctionEi(%class.Foo* noundef nonnull align 1 dereferenceable(1) %this1, i32 noundef %0)
42 [[clang::musttail
]] return Foo::StaticMethod(x
);
45 // CHECK: %call = musttail call noundef i32 @_ZN3Foo12StaticMethodEi(i32 noundef %0)
48 Foo foo
; // Object with trivial destructor.
49 [[clang::musttail
]] return foo
.StaticMethod(x
);
52 // CHECK: %call = musttail call noundef i32 @_ZN3Foo12StaticMethodEi(i32 noundef %0)
56 int Foo::TailFrom2(int x
) {
57 [[clang::musttail
]] return ((*this).*pmf
)(x
);
60 // CHECK: %call = musttail call noundef i32 %8(%class.Foo* noundef nonnull align 1 dereferenceable(1) %this.adjusted, i32 noundef %9)
62 int Foo::TailFrom3(int x
) {
63 [[clang::musttail
]] return (this->*pmf
)(x
);
66 // CHECK: %call = musttail call noundef i32 %8(%class.Foo* noundef nonnull align 1 dereferenceable(1) %this.adjusted, i32 noundef %9)
71 [[clang::musttail
]] return ReturnsVoid();
74 // CHECK: musttail call void @_Z11ReturnsVoidv()
76 class HasTrivialDestructor
{};
78 int ReturnsInt(int x
);
81 HasTrivialDestructor foo
;
82 [[clang::musttail
]] return ReturnsInt(x
);
85 // CHECK: %call = musttail call noundef i32 @_Z10ReturnsInti(i32 noundef %0)
91 int Func7(Data
*data
) {
92 [[clang::musttail
]] return data
->fptr(data
);
95 // CHECK: %call = musttail call noundef i32 %1(%struct.Data* noundef %2)
103 [[clang::musttail
]] return TemplateFunc
<int>(x
);
106 // CHECK: %call = musttail call noundef i32 @_Z12TemplateFuncIiET_S0_(i32 noundef %0)
111 [[clang::musttail
]] return Bar(x
);
115 return Func10
<int>(x
);
118 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %0)
122 [[clang::musttail
]] return ::Bar(x
);
126 return Func12
<int>(x
);
129 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %0)
133 [[clang::musttail
]] return Bar(x
);
136 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %3)
138 void TrivialDestructorParam(HasTrivialDestructor obj
);
140 void Func14(HasTrivialDestructor obj
) {
141 [[clang::musttail
]] return TrivialDestructorParam(obj
);
144 // CHECK: musttail call void @_Z22TrivialDestructorParam20HasTrivialDestructor()
147 void ConstMemberFunction(const int *) const;
148 void NonConstMemberFunction(int *i
);
150 void Struct3::NonConstMemberFunction(int *i
) {
151 // The parameters are not identical, but they are compatible.
152 [[clang::musttail
]] return ConstMemberFunction(i
);
155 // CHECK: musttail call void @_ZNK7Struct319ConstMemberFunctionEPKi(%struct.Struct3* noundef nonnull align 1 dereferenceable(1) %this1, i32* noundef %0)
157 struct HasNonTrivialCopyConstructor
{
158 HasNonTrivialCopyConstructor(const HasNonTrivialCopyConstructor
&);
160 HasNonTrivialCopyConstructor
ReturnsClassByValue();
161 HasNonTrivialCopyConstructor
TestNonElidableCopyConstructor() {
162 [[clang::musttail
]] return (((ReturnsClassByValue())));
165 // CHECK: musttail call void @_Z19ReturnsClassByValuev(%struct.HasNonTrivialCopyConstructor* sret(%struct.HasNonTrivialCopyConstructor) align 1 %agg.result)
167 struct HasNonTrivialCopyConstructor2
{
168 // Copy constructor works even if it has extra default params.
169 HasNonTrivialCopyConstructor2(const HasNonTrivialCopyConstructor
&, int DefaultParam
= 5);
171 HasNonTrivialCopyConstructor2
ReturnsClassByValue2();
172 HasNonTrivialCopyConstructor2
TestNonElidableCopyConstructor2() {
173 [[clang::musttail
]] return (((ReturnsClassByValue2())));
176 // CHECK: musttail call void @_Z20ReturnsClassByValue2v()
178 void TestFunctionPointer(int x
) {
179 void (*p
)(int) = nullptr;
180 [[clang::musttail
]] return p(x
);
183 // CHECK: musttail call void %0(i32 noundef %1)
185 struct LargeWithCopyConstructor
{
186 LargeWithCopyConstructor(const LargeWithCopyConstructor
&);
189 LargeWithCopyConstructor
ReturnsLarge();
190 LargeWithCopyConstructor
TestLargeWithCopyConstructor() {
191 [[clang::musttail
]] return ReturnsLarge();
194 // CHECK: define dso_local void @_Z28TestLargeWithCopyConstructorv(%struct.LargeWithCopyConstructor* noalias sret(%struct.LargeWithCopyConstructor) align 1 %agg.result)
195 // CHECK: musttail call void @_Z12ReturnsLargev(%struct.LargeWithCopyConstructor* sret(%struct.LargeWithCopyConstructor) align 1 %agg.result)
197 using IntFunctionType
= int();
198 IntFunctionType
*ReturnsIntFunction();
199 int TestRValueFunctionPointer() {
200 [[clang::musttail
]] return ReturnsIntFunction()();
203 // CHECK: musttail call noundef i32 %call()
205 void(FuncWithParens
)() {
206 [[clang::musttail
]] return FuncWithParens();
209 // CHECK: musttail call void @_Z14FuncWithParensv()
211 int TestNonCapturingLambda() {
212 auto lambda
= []() { return 12; };
213 [[clang::musttail
]] return (+lambda
)();
216 // CHECK: %call = call noundef i32 ()* @"_ZZ22TestNonCapturingLambdavENK3$_0cvPFivEEv"(%class.anon* noundef nonnull align 1 dereferenceable(1) %lambda)
217 // CHECK: musttail call noundef i32 %call()
220 virtual void TailTo();
221 virtual void TailFrom();
224 void TestVirtual::TailFrom() {
225 [[clang::musttail
]] return TailTo();
228 // CHECK: musttail call void %1(%class.TestVirtual* noundef nonnull align 8 dereferenceable(8) %this1)