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
4 
5 struct A {
6     inline void f();
7 };
8 
9 // NORMAL-NOT: define{{.*}} void @_ZN1A1fEv
10 // MSVCCOMPAT-NOT: define{{.*}} void @"?f@A@@QEAAXXZ"
f()11 void A::f() { }
12 
13 template<typename> struct B { };
14 
15 template<> struct B<char> {
16   inline void f();
17 };
18 
19 // NORMAL-NOT: _ZN1BIcE1fEv
20 // MSVCCOMPAT-NOT: @"?f@?$B@D@@QEAAXXZ"
f()21 void B<char>::f() { }
22 
23 // We need a final CHECK line here.
24 
25 // NORMAL-LABEL: define{{.*}} void @_Z1fv
26 // MSVCCOMPAT-LABEL: define dso_local void @"?f@@YAXXZ"
f()27 void f() { }
28 
29 // <rdar://problem/8740363>
30 inline void f1(int);
31 
32 // NORMAL-LABEL: define linkonce_odr void @_Z2f1i
33 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?f1@@YAXH@Z"
f1(int)34 void f1(int) { }
35 
test_f1()36 void test_f1() { f1(17); }
37 
38 // PR8789
39 namespace test1 {
40   template <typename T> class ClassTemplate {
41   private:
42     friend void T::func();
g()43     void g() {}
44   };
45 
46   // NORMAL-LABEL: define linkonce_odr void @_ZN5test11C4funcEv(
47   // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?func@C@test1@@QEAAXXZ"(
48 
49   class C {
50   public:
func()51     void func() {
52       ClassTemplate<C> ct;
53       ct.g();
54     }
55   };
56 
f()57   void f() {
58     C c;
59     c.func();
60   }
61 }
62 
63 // PR13252
64 namespace test2 {
65   struct A;
66   void f(const A& a);
67   struct A {
f(const A & a)68     friend void f(const A& a) { }
69   };
g()70   void g() {
71     A a;
72     f(a);
73   }
74   // NORMAL-LABEL: define linkonce_odr void @_ZN5test21fERKNS_1AE
75   // MSVCCOMPAT-LABEL: define linkonce_odr dso_local void @"?f@test2@@YAXAEBUA@1@@Z"
76 }
77 
78 // NORMAL-NOT: _Z17ExternAndInlineFnv
79 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?ExternAndInlineFn@@YAXXZ"
ExternAndInlineFn()80 extern inline void ExternAndInlineFn() {}
81 
82 // NORMAL-NOT: _Z18InlineThenExternFnv
83 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?InlineThenExternFn@@YAXXZ"
InlineThenExternFn()84 inline void InlineThenExternFn() {}
85 extern void InlineThenExternFn();
86 
87 // NORMAL-LABEL: define{{.*}} void @_Z18ExternThenInlineFnv
88 // MSVCCOMPAT-LABEL: define dso_local void @"?ExternThenInlineFn@@YAXXZ"
ExternThenInlineFn()89 extern void ExternThenInlineFn() {}
90 
91 // NORMAL-NOT: _Z25ExternThenInlineThenDefFnv
92 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?ExternThenInlineThenDefFn@@YAXXZ"
93 extern void ExternThenInlineThenDefFn();
94 inline void ExternThenInlineThenDefFn();
ExternThenInlineThenDefFn()95 void ExternThenInlineThenDefFn() {}
96 
97 // NORMAL-NOT: _Z25InlineThenExternThenDefFnv
98 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"?InlineThenExternThenDefFn@@YAXXZ"
99 inline void InlineThenExternThenDefFn();
100 extern void InlineThenExternThenDefFn();
InlineThenExternThenDefFn()101 void InlineThenExternThenDefFn() {}
102 
103 // NORMAL-NOT: _Z17ExternAndConstexprFnv
104 // MSVCCOMPAT-LABEL: define weak_odr dso_local i32 @"?ExternAndConstexprFn@@YAHXZ"
ExternAndConstexprFn()105 extern constexpr int ExternAndConstexprFn() { return 0; }
106 
107 // NORMAL-NOT: _Z11ConstexprFnv
108 // MSVCCOMPAT-NOT: @"?ConstexprFn@@YAHXZ"
ConstexprFn()109 constexpr int ConstexprFn() { return 0; }
110 
111 template <typename T>
112 extern inline void ExternInlineOnPrimaryTemplate(T);
113 
114 // NORMAL-LABEL: define{{.*}} void @_Z29ExternInlineOnPrimaryTemplateIiEvT_
115 // MSVCCOMPAT-LABEL: define dso_local void @"??$ExternInlineOnPrimaryTemplate@H@@YAXH@Z"
116 template <>
ExternInlineOnPrimaryTemplate(int)117 void ExternInlineOnPrimaryTemplate(int) {}
118 
119 template <typename T>
120 extern inline void ExternInlineOnPrimaryTemplateAndSpecialization(T);
121 
122 // NORMAL-NOT: _Z46ExternInlineOnPrimaryTemplateAndSpecializationIiEvT_
123 // MSVCCOMPAT-LABEL: define weak_odr dso_local void @"??$ExternInlineOnPrimaryTemplateAndSpecialization@H@@YAXH@Z"
124 template <>
ExternInlineOnPrimaryTemplateAndSpecialization(int)125 extern inline void ExternInlineOnPrimaryTemplateAndSpecialization(int) {}
126 
127 struct TypeWithInlineMethods {
128   // NORMAL-NOT: _ZN21TypeWithInlineMethods9StaticFunEv
129   // MSVCCOMPAT-NOT: @"?StaticFun@TypeWithInlineMethods@@SAXXZ"
StaticFunTypeWithInlineMethods130   static void StaticFun() {}
131   // NORMAL-NOT: _ZN21TypeWithInlineMethods12NonStaticFunEv
132   // MSVCCOMPAT-NOT: @"?NonStaticFun@TypeWithInlineMethods@@QEAAXXZ"
NonStaticFunTypeWithInlineMethods133   void NonStaticFun() { StaticFun(); }
134 };
135 
136 namespace PR22959 {
137 template <typename>
138 struct S;
139 
140 S<int> Foo();
141 
142 template <typename>
143 struct S {
144   friend S<int> Foo();
145 };
146 
Foo()147 __attribute__((used)) inline S<int> Foo() { return S<int>(); }
148 // NORMAL-LABEL: define linkonce_odr void @_ZN7PR229593FooEv(
149 // MSVCCOMPAT-LABEL: define linkonce_odr dso_local i8 @"?Foo@PR22959@@YA?AU?$S@H@1@XZ"(
150 }
151