1; RUN: opt -module-summary %s -o %t1.bc
2; RUN: opt -module-summary %p/Inputs/alias_import.ll -o %t2.bc
3; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
4; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t.index.bc %t2.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=PROMOTE
5; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t.index.bc %t2.bc -o - | llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t2.bc - -o - | llvm-dis -o - | FileCheck %s --check-prefix=PROMOTE-INTERNALIZE
6; RUN: llvm-lto -thinlto-action=import -thinlto-index %t.index.bc %t1.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT
7
8;
9; Alias can't point to "available_externally", so we can only import an alias
10; when we can import the aliasee with a linkage that won't be
11; available_externally, i.e linkOnceODR. (FIXME this limitation could be lifted)
12; PROMOTE-DAG: @globalfuncAlias = alias void (...), bitcast (void ()* @globalfunc to void (...)*)
13; PROMOTE-DAG: @globalfuncWeakAlias = weak alias void (...), bitcast (void ()* @globalfunc to void (...)*)
14; PROMOTE-DAG: @globalfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @globalfunc to void (...)*)
15; PROMOTE-DAG: @globalfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @globalfunc to void (...)*)
16; PROMOTE-DAG: @globalfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @globalfunc to void (...)*)
17; PROMOTE-DAG: @internalfuncAlias = alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
18; PROMOTE-DAG: @internalfuncWeakAlias = weak alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
19; PROMOTE-DAG: @internalfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
20; PROMOTE-DAG: @internalfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
21; PROMOTE-DAG: @internalfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
22; PROMOTE-DAG: @linkoncefuncAlias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
23; PROMOTE-DAG: @linkoncefuncWeakAlias = weak alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
24; PROMOTE-DAG: @linkoncefuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
25; PROMOTE-DAG: @linkoncefuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
26; PROMOTE-DAG: @linkoncefuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
27; PROMOTE-DAG: @weakfuncAlias = alias void (...), bitcast (void ()* @weakfunc to void (...)*)
28; PROMOTE-DAG: @weakfuncWeakAlias = weak alias void (...), bitcast (void ()* @weakfunc to void (...)*)
29; PROMOTE-DAG: @weakfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @weakfunc to void (...)*)
30; PROMOTE-DAG: @weakfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakfunc to void (...)*)
31; PROMOTE-DAG: @weakfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @weakfunc to void (...)*)
32; PROMOTE-DAG: @weakODRfuncAlias = alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
33; PROMOTE-DAG: @weakODRfuncWeakAlias = weak alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
34; PROMOTE-DAG: @weakODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
35; PROMOTE-DAG: @weakODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
36; PROMOTE-DAG: @weakODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
37
38; Only alias to LinkonceODR aliasee can be imported
39; PROMOTE-DAG: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
40; PROMOTE-DAG: @linkonceODRfuncWeakAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
41; PROMOTE-DAG: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
42; Amongst these that are imported, check that we promote only linkonce->weak
43; PROMOTE-DAG: @linkonceODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
44; PROMOTE-DAG: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
45
46; These will be imported, check the linkage/renaming after promotion
47; PROMOTE-DAG: define void @globalfunc()
48; PROMOTE-DAG: define hidden void @internalfunc.llvm.0()
49; PROMOTE-DAG: define linkonce_odr void @linkonceODRfunc()
50; PROMOTE-DAG: define weak_odr void @weakODRfunc()
51; PROMOTE-DAG: define linkonce void @linkoncefunc()
52; PROMOTE-DAG: define weak void @weakfunc()
53
54; On the import side now, verify that aliases to a linkonce_odr are imported, but the weak/linkonce (we can't inline them)
55; IMPORT-DAG:  declare void @linkonceODRfuncWeakAlias
56; IMPORT-DAG: declare void @linkonceODRfuncLinkonceAlias
57; IMPORT-DAG:  @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
58; IMPORT-DAG:  @linkonceODRfuncWeakODRAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
59; IMPORT-DAG:  @linkonceODRfuncLinkonceODRAlias = linkonce_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
60; IMPORT-DAG:  define linkonce_odr void @linkonceODRfunc()
61
62
63; On the import side, these aliases are not imported (they don't point to a linkonce_odr)
64; IMPORT-DAG: declare void @globalfuncAlias()
65; IMPORT-DAG: declare void @globalfuncWeakAlias()
66; IMPORT-DAG: declare void @globalfuncLinkonceAlias()
67; IMPORT-DAG: declare void @globalfuncWeakODRAlias()
68; IMPORT-DAG: declare void @globalfuncLinkonceODRAlias()
69; IMPORT-DAG: declare void @internalfuncAlias()
70; IMPORT-DAG: declare void @internalfuncWeakAlias()
71; IMPORT-DAG: declare void @internalfuncLinkonceAlias()
72; IMPORT-DAG: declare void @internalfuncWeakODRAlias()
73; IMPORT-DAG: declare void @internalfuncLinkonceODRAlias()
74; IMPORT-DAG: declare void @weakODRfuncAlias()
75; IMPORT-DAG: declare void @weakODRfuncWeakAlias()
76; IMPORT-DAG: declare void @weakODRfuncLinkonceAlias()
77; IMPORT-DAG: declare void @weakODRfuncWeakODRAlias()
78; IMPORT-DAG: declare void @weakODRfuncLinkonceODRAlias()
79; IMPORT-DAG: declare void @linkoncefuncAlias()
80; IMPORT-DAG: declare void @linkoncefuncWeakAlias()
81; IMPORT-DAG: declare void @linkoncefuncLinkonceAlias()
82; IMPORT-DAG: declare void @linkoncefuncWeakODRAlias()
83; IMPORT-DAG: declare void @linkoncefuncLinkonceODRAlias()
84; IMPORT-DAG: declare void @weakfuncAlias()
85; IMPORT-DAG: declare void @weakfuncWeakAlias()
86; IMPORT-DAG: declare void @weakfuncLinkonceAlias()
87; IMPORT-DAG: declare void @weakfuncWeakODRAlias()
88; IMPORT-DAG: declare void @weakfuncLinkonceODRAlias()
89
90; Promotion + internalization should internalize all of these, except for aliases of
91; linkonce_odr functions, because alias to linkonce_odr are the only aliases we will
92; import (see selectCallee() in FunctionImport.cpp).
93; PROMOTE-INTERNALIZE-DAG: @globalfuncAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*)
94; PROMOTE-INTERNALIZE-DAG: @globalfuncWeakAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*)
95; PROMOTE-INTERNALIZE-DAG: @globalfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*)
96; PROMOTE-INTERNALIZE-DAG: @globalfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*)
97; PROMOTE-INTERNALIZE-DAG: @globalfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*)
98; PROMOTE-INTERNALIZE-DAG: @internalfuncAlias = internal alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
99; PROMOTE-INTERNALIZE-DAG: @internalfuncWeakAlias = internal alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
100; PROMOTE-INTERNALIZE-DAG: @internalfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
101; PROMOTE-INTERNALIZE-DAG: @internalfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
102; PROMOTE-INTERNALIZE-DAG: @internalfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @internalfunc.llvm.0 to void (...)*)
103; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
104; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncWeakAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
105; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
106; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
107; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
108; PROMOTE-INTERNALIZE-DAG: @weakODRfuncAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
109; PROMOTE-INTERNALIZE-DAG: @weakODRfuncWeakAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
110; PROMOTE-INTERNALIZE-DAG: @weakODRfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
111; PROMOTE-INTERNALIZE-DAG: @weakODRfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
112; PROMOTE-INTERNALIZE-DAG: @weakODRfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
113; PROMOTE-INTERNALIZE-DAG: @linkoncefuncAlias = internal alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
114; PROMOTE-INTERNALIZE-DAG: @linkoncefuncWeakAlias = internal alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
115; PROMOTE-INTERNALIZE-DAG: @linkoncefuncLinkonceAlias = internal alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
116; PROMOTE-INTERNALIZE-DAG: @linkoncefuncWeakODRAlias = internal alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
117; PROMOTE-INTERNALIZE-DAG: @linkoncefuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
118; PROMOTE-INTERNALIZE-DAG: @weakfuncAlias = internal alias void (...), bitcast (void ()* @weakfunc to void (...)*)
119; PROMOTE-INTERNALIZE-DAG: @weakfuncWeakAlias = internal alias void (...), bitcast (void ()* @weakfunc to void (...)*)
120; PROMOTE-INTERNALIZE-DAG: @weakfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @weakfunc to void (...)*)
121; PROMOTE-INTERNALIZE-DAG: @weakfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @weakfunc to void (...)*)
122; PROMOTE-INTERNALIZE-DAG: @weakfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @weakfunc to void (...)*)
123; PROMOTE-INTERNALIZE-DAG: define internal void @globalfunc()
124; PROMOTE-INTERNALIZE-DAG: define internal void @internalfunc.llvm.0()
125; PROMOTE-INTERNALIZE-DAG: define internal void @linkonceODRfunc()
126; PROMOTE-INTERNALIZE-DAG: define internal void @weakODRfunc()
127; PROMOTE-INTERNALIZE-DAG: define internal void @linkoncefunc()
128; PROMOTE-INTERNALIZE-DAG: define internal void @weakfunc()
129
130define i32 @main() #0 {
131entry:
132  call void @globalfuncAlias()
133  call void @globalfuncWeakAlias()
134  call void @globalfuncLinkonceAlias()
135  call void @globalfuncWeakODRAlias()
136  call void @globalfuncLinkonceODRAlias()
137
138  call void @internalfuncAlias()
139  call void @internalfuncWeakAlias()
140  call void @internalfuncLinkonceAlias()
141  call void @internalfuncWeakODRAlias()
142  call void @internalfuncLinkonceODRAlias()
143  call void @linkonceODRfuncAlias()
144  call void @linkonceODRfuncWeakAlias()
145  call void @linkonceODRfuncLinkonceAlias()
146  call void @linkonceODRfuncWeakODRAlias()
147  call void @linkonceODRfuncLinkonceODRAlias()
148
149  call void @weakODRfuncAlias()
150  call void @weakODRfuncWeakAlias()
151  call void @weakODRfuncLinkonceAlias()
152  call void @weakODRfuncWeakODRAlias()
153  call void @weakODRfuncLinkonceODRAlias()
154
155  call void @linkoncefuncAlias()
156  call void @linkoncefuncWeakAlias()
157  call void @linkoncefuncLinkonceAlias()
158  call void @linkoncefuncWeakODRAlias()
159  call void @linkoncefuncLinkonceODRAlias()
160
161  call void @weakfuncAlias()
162  call void @weakfuncWeakAlias()
163  call void @weakfuncLinkonceAlias()
164  call void @weakfuncWeakODRAlias()
165  call void @weakfuncLinkonceODRAlias()
166
167  ret i32 0
168}
169
170
171declare void @globalfuncAlias()
172declare void @globalfuncWeakAlias()
173declare void @globalfuncLinkonceAlias()
174declare void @globalfuncWeakODRAlias()
175declare void @globalfuncLinkonceODRAlias()
176
177declare void @internalfuncAlias()
178declare void @internalfuncWeakAlias()
179declare void @internalfuncLinkonceAlias()
180declare void @internalfuncWeakODRAlias()
181declare void @internalfuncLinkonceODRAlias()
182
183declare void @linkonceODRfuncAlias()
184declare void @linkonceODRfuncWeakAlias()
185declare void @linkonceODRfuncLinkonceAlias()
186declare void @linkonceODRfuncWeakODRAlias()
187declare void @linkonceODRfuncLinkonceODRAlias()
188
189declare void @weakODRfuncAlias()
190declare void @weakODRfuncWeakAlias()
191declare void @weakODRfuncLinkonceAlias()
192declare void @weakODRfuncWeakODRAlias()
193declare void @weakODRfuncLinkonceODRAlias()
194
195declare void @linkoncefuncAlias()
196declare void @linkoncefuncWeakAlias()
197declare void @linkoncefuncLinkonceAlias()
198declare void @linkoncefuncWeakODRAlias()
199declare void @linkoncefuncLinkonceODRAlias()
200
201declare void @weakfuncAlias()
202declare void @weakfuncWeakAlias()
203declare void @weakfuncLinkonceAlias()
204declare void @weakfuncWeakODRAlias()
205declare void @weakfuncLinkonceODRAlias()
206
207
208