Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / inline-functions.cpp
blob6c4badc4f6f69a07c7b2a7858d93805b4fe160bc
1 // RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=NORMAL
2 // RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -triple=x86_64-pc-win32 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=MSVCCOMPAT
3 // CHECK: ; ModuleID
5 struct A {
6 inline void f();
7 };
9 // NORMAL-NOT: define{{.*}} void @_ZN1A1fEv
10 // MSVCCOMPAT-NOT: define{{.*}} void @"?f@A@@QEAAXXZ"
11 void A::f() { }
13 template<typename> struct B { };
15 template<> struct B<char> {
16 inline void f();
19 // NORMAL-NOT: _ZN1BIcE1fEv
20 // MSVCCOMPAT-NOT: @"?f@?$B@D@@QEAAXXZ"
21 void B<char>::f() { }
23 // We need a final CHECK line here.
25 // NORMAL-LABEL: define{{.*}} void @_Z1fv
26 // MSVCCOMPAT-LABEL: define dso_local void @"?f@@YAXXZ"
27 void f() { }
29 inline void f1(int);
31 // NORMAL-LABEL: define linkonce_odr void @_Z2f1i
32 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?f1@@YAXH@Z"
33 void f1(int) { }
35 void test_f1() { f1(17); }
37 // PR8789
38 namespace test1 {
39 template <typename T> class ClassTemplate {
40 private:
41 friend void T::func();
42 void g() {}
45 // NORMAL-LABEL: define linkonce_odr void @_ZN5test11C4funcEv(
46 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?func@C@test1@@QEAAXXZ"(
48 class C {
49 public:
50 void func() {
51 ClassTemplate<C> ct;
52 ct.g();
56 void f() {
57 C c;
58 c.func();
62 // PR13252
63 namespace test2 {
64 struct A;
65 void f(const A& a);
66 struct A {
67 friend void f(const A& a) { }
69 void g() {
70 A a;
71 f(a);
73 // NORMAL-LABEL: define linkonce_odr void @_ZN5test21fERKNS_1AE
74 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?f@test2@@YAXAEBUA@1@@Z"
77 // NORMAL-NOT: _Z17ExternAndInlineFnv
78 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?ExternAndInlineFn@@YAXXZ"
79 extern inline void ExternAndInlineFn() {}
81 // NORMAL-NOT: _Z18InlineThenExternFnv
82 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?InlineThenExternFn@@YAXXZ"
83 inline void InlineThenExternFn() {}
84 extern void InlineThenExternFn();
86 // NORMAL-LABEL: define{{.*}} void @_Z18ExternThenInlineFnv
87 // MSVCCOMPAT-LABEL: define dso_local void @"?ExternThenInlineFn@@YAXXZ"
88 extern void ExternThenInlineFn() {}
90 // NORMAL-NOT: _Z25ExternThenInlineThenDefFnv
91 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?ExternThenInlineThenDefFn@@YAXXZ"
92 extern void ExternThenInlineThenDefFn();
93 inline void ExternThenInlineThenDefFn();
94 void ExternThenInlineThenDefFn() {}
96 // NORMAL-NOT: _Z25InlineThenExternThenDefFnv
97 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?InlineThenExternThenDefFn@@YAXXZ"
98 inline void InlineThenExternThenDefFn();
99 extern void InlineThenExternThenDefFn();
100 void InlineThenExternThenDefFn() {}
102 // NORMAL-NOT: _Z17ExternAndConstexprFnv
103 // MSVCCOMPAT-LABEL: define weak_odr dso_local noundef i32 @"?ExternAndConstexprFn@@YAHXZ"
104 extern constexpr int ExternAndConstexprFn() { return 0; }
106 // NORMAL-NOT: _Z11ConstexprFnv
107 // MSVCCOMPAT-NOT: @"?ConstexprFn@@YAHXZ"
108 constexpr int ConstexprFn() { return 0; }
110 template <typename T>
111 extern inline void ExternInlineOnPrimaryTemplate(T);
113 // NORMAL-LABEL: define{{.*}} void @_Z29ExternInlineOnPrimaryTemplateIiEvT_
114 // MSVCCOMPAT-LABEL: define dso_local void @"??$ExternInlineOnPrimaryTemplate@H@@YAXH@Z"
115 template <>
116 void ExternInlineOnPrimaryTemplate(int) {}
118 template <typename T>
119 extern inline void ExternInlineOnPrimaryTemplateAndSpecialization(T);
121 // NORMAL-NOT: _Z46ExternInlineOnPrimaryTemplateAndSpecializationIiEvT_
122 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"??$ExternInlineOnPrimaryTemplateAndSpecialization@H@@YAXH@Z"
123 template <>
124 extern inline void ExternInlineOnPrimaryTemplateAndSpecialization(int) {}
126 struct TypeWithInlineMethods {
127 // NORMAL-NOT: _ZN21TypeWithInlineMethods9StaticFunEv
128 // MSVCCOMPAT-NOT: @"?StaticFun@TypeWithInlineMethods@@SAXXZ"
129 static void StaticFun() {}
130 // NORMAL-NOT: _ZN21TypeWithInlineMethods12NonStaticFunEv
131 // MSVCCOMPAT-NOT: @"?NonStaticFun@TypeWithInlineMethods@@QEAAXXZ"
132 void NonStaticFun() { StaticFun(); }
135 namespace PR22959 {
136 template <typename>
137 struct S;
139 S<int> Foo();
141 template <typename>
142 struct S {
143 friend S<int> Foo();
146 __attribute__((used)) inline S<int> Foo() { return S<int>(); }
147 // NORMAL-LABEL: define linkonce_odr void @_ZN7PR229593FooEv(
148 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local i8 @"?Foo@PR22959@@YA?AU?$S@H@1@XZ"(