a0df5bf2238c51711076860cd86d717b19abd97f
[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 @X = global i32 5
30 @U = global i32 6
31 @U_linkonce = linkonce_odr hidden global i32 6
32 define i32 @foo() { ret i32 7 }
33 define i32 @unused() { ret i32 8 }
34 define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
35 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
36
37 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
38 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
39
40 define void @globalfunc1() #0 {
41 entry:
42   ret void
43 }
44
45 define void @globalfunc2() #0 {
46 entry:
47   ret void
48 }
49
50 $linkoncefunc2 = comdat any
51 define linkonce_odr void @linkoncefunc2() #0 comdat {
52 entry:
53   ret void
54 }
55
56 !llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
57 !0 = !{i32 ()* @unused}
58 !1 = !{i32* @U}
59 !2 = !{i32 ()* @unused_linkonce}
60 !3 = !{i32* @U_linkonce}
61 !4 = !{void (...)* @weakalias}
62 !5 = !{void (...)* @analias}
63 !6 = !{void (...)* @linkoncealias}