c08d68a76eb9f7fdc5735901758bd3d63907ed92
[oota-llvm.git] / test / Linker / only-needed-named-metadata.ll
1 ; RUN: llvm-as %S/only-needed-named-metadata.ll -o %t.bc
2 ; RUN: llvm-as %S/Inputs/only-needed-named-metadata.ll -o %t2.bc
3
4 ; Without -only-needed we should lazy link linkonce globals, and the
5 ; metadata reference should not cause them to be linked.
6 ; RUN: llvm-link -S %t2.bc %t.bc | FileCheck %s
7 ; CHECK-NOT:@U_linkonce
8 ; CHECK-NOT:@unused_linkonce()
9
10 ; With -only-needed the metadata references should not cause any of the
11 ; otherwise unreferenced globals to be linked. This also ensures that the
12 ; metadata references don't provoke the module linker to create declarations,
13 ; which are illegal for aliases and globals in comdats.
14 ; Note that doing -only-needed with the comdat shown below leads to a only
15 ; part of the comdat group being linked, which is not technically correct.
16 ; RUN: llvm-link -S -only-needed %t2.bc %t.bc | FileCheck %s -check-prefix=ONLYNEEDED
17 ; RUN: llvm-link -S -internalize -only-needed %t2.bc %t.bc | FileCheck %s -check-prefix=ONLYNEEDED
18 ; ONLYNEEDED-NOT:@U
19 ; ONLYNEEDED-NOT:@U_linkonce
20 ; ONLYNEEDED-NOT:@unused()
21 ; ONLYNEEDED-NOT:@unused_linkonce()
22 ; ONLYNEEDED-NOT:@linkoncealias
23 ; ONLYNEEDED-NOT:@linkoncefunc2()
24 ; ONLYNEEDED-NOT:@weakalias
25 ; ONLYNEEDED-NOT:@globalfunc1()
26 ; ONLYNEEDED-NOT:@analias
27 ; ONLYNEEDED-NOT:@globalfunc2()
28
29 ; Test -only-needed link with the modules preserved instead of freeing to
30 ; catch any cross-module references to metadata, which the bitcode writer
31 ; will assert on.
32 ; RUN: llvm-link -preserve-modules -o %t3.bc -only-needed %t2.bc %t.bc
33
34 @X = global i32 5
35 @U = global i32 6
36 @U_linkonce = linkonce_odr hidden global i32 6
37 define i32 @foo() { ret i32 7 }
38 define i32 @unused() { ret i32 8 }
39 define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
40 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
41
42 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
43 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
44
45 define void @globalfunc1() #0 {
46 entry:
47   ret void
48 }
49
50 define void @globalfunc2() #0 {
51 entry:
52   ret void
53 }
54
55 $linkoncefunc2 = comdat any
56 define linkonce_odr void @linkoncefunc2() #0 comdat {
57 entry:
58   ret void
59 }
60
61 !llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
62 !0 = !{i32 ()* @unused}
63 !1 = !{i32* @U}
64 !2 = !{i32 ()* @unused_linkonce}
65 !3 = !{i32* @U_linkonce}
66 !4 = !{void (...)* @weakalias}
67 !5 = !{void (...)* @analias}
68 !6 = !{void (...)* @linkoncealias}