[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CodeGenCXX / attr-musttail.cpp
blobc76a0d16efc8fd59f09b229fa7edaa87d460f867
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.
5 int Bar(int);
6 int Baz(int);
8 int Func1(int x) {
9 if (x) {
10 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %1)
11 // CHECK-NEXT: ret i32 %call
12 [[clang::musttail]] return Bar(x);
13 } else {
14 [[clang::musttail]] return Baz(x); // CHECK: %call1 = musttail call noundef i32 @_Z3Bazi(i32 noundef %3)
18 int Func2(int x) {
20 [[clang::musttail]] return Bar(Bar(x));
24 // CHECK: %call1 = musttail call noundef i32 @_Z3Bari(i32 noundef %call)
26 class Foo {
27 public:
28 static int StaticMethod(int x);
29 int MemberFunction(int x);
30 int TailFrom(int x);
31 int TailFrom2(int x);
32 int TailFrom3(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)
41 int Func3(int x) {
42 [[clang::musttail]] return Foo::StaticMethod(x);
45 // CHECK: %call = musttail call noundef i32 @_ZN3Foo12StaticMethodEi(i32 noundef %0)
47 int Func4(int x) {
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)
54 int (Foo::*pmf)(int);
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)
68 void ReturnsVoid();
70 void Func5() {
71 [[clang::musttail]] return ReturnsVoid();
74 // CHECK: musttail call void @_Z11ReturnsVoidv()
76 class HasTrivialDestructor {};
78 int ReturnsInt(int x);
80 int Func6(int x) {
81 HasTrivialDestructor foo;
82 [[clang::musttail]] return ReturnsInt(x);
85 // CHECK: %call = musttail call noundef i32 @_Z10ReturnsInti(i32 noundef %0)
87 struct Data {
88 int (*fptr)(Data *);
91 int Func7(Data *data) {
92 [[clang::musttail]] return data->fptr(data);
95 // CHECK: %call = musttail call noundef i32 %1(%struct.Data* noundef %2)
97 template <class T>
98 T TemplateFunc(T) {
99 return 5;
102 int Func9(int x) {
103 [[clang::musttail]] return TemplateFunc<int>(x);
106 // CHECK: %call = musttail call noundef i32 @_Z12TemplateFuncIiET_S0_(i32 noundef %0)
108 template <class T>
109 int Func10(int x) {
110 T t;
111 [[clang::musttail]] return Bar(x);
114 int Func11(int x) {
115 return Func10<int>(x);
118 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %0)
120 template <class T>
121 T Func12(T x) {
122 [[clang::musttail]] return ::Bar(x);
125 int Func13(int x) {
126 return Func12<int>(x);
129 // CHECK: %call = musttail call noundef i32 @_Z3Bari(i32 noundef %0)
131 int Func14(int x) {
132 int vla[x];
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()
146 struct Struct3 {
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 &);
187 char data[32];
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()
219 class TestVirtual {
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)