1 ; Without -only-needed we should lazy link linkonce globals, and the
2 ; metadata reference should not cause them to be linked.
3 ; RUN: llvm-link -S %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s
4 ; CHECK-NOT:@U_linkonce
5 ; CHECK-NOT:@unused_linkonce()
7 ; With -only-needed the metadata references should not cause any of the
8 ; otherwise unreferenced globals to be linked. This also ensures that the
9 ; metadata references don't provoke the module linker to create declarations,
10 ; which are illegal for aliases and globals in comdats.
11 ; Note that doing -only-needed with the comdat shown below leads to a only
12 ; part of the comdat group being linked, which is not technically correct.
13 ; RUN: llvm-link -S -only-needed %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s -check-prefix=ONLYNEEDED
14 ; RUN: llvm-link -S -internalize -only-needed %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s -check-prefix=ONLYNEEDED
16 ; ONLYNEEDED-NOT:@U_linkonce
17 ; ONLYNEEDED-NOT:@unused()
18 ; ONLYNEEDED-NOT:@unused_linkonce()
19 ; ONLYNEEDED-NOT:@linkoncealias
20 ; ONLYNEEDED-NOT:@linkoncefunc2()
21 ; ONLYNEEDED-NOT:@weakalias
22 ; ONLYNEEDED-NOT:@globalfunc1()
23 ; ONLYNEEDED-NOT:@analias
24 ; ONLYNEEDED-NOT:@globalfunc2()
28 @U_linkonce = linkonce_odr hidden global i32 6
29 define i32 @foo() { ret i32 7 }
30 define i32 @unused() { ret i32 8 }
31 define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
32 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
34 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
35 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
37 define void @globalfunc1() #0 {
42 define void @globalfunc2() #0 {
47 $linkoncefunc2 = comdat any
48 define linkonce_odr void @linkoncefunc2() #0 comdat {
53 !llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
54 !0 = !{i32 ()* @unused}
56 !2 = !{i32 ()* @unused_linkonce}
57 !3 = !{i32* @U_linkonce}
58 !4 = !{void (...)* @weakalias}
59 !5 = !{void (...)* @analias}
60 !6 = !{void (...)* @linkoncealias}