blob: 90e24ceaf98682c035f980417ac7d7583044efd5 [file] [log] [blame]
Teresa Johnson99ee8972015-11-06 17:50:53 +00001; Without -only-needed we should lazy link linkonce globals, and the
2; metadata reference should not cause them to be linked.
Rafael Espindolae29bf072015-11-27 23:47:15 +00003; RUN: llvm-link -S %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s
Teresa Johnson99ee8972015-11-06 17:50:53 +00004; CHECK-NOT:@U_linkonce
5; CHECK-NOT:@unused_linkonce()
6
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.
Rafael Espindolae29bf072015-11-27 23:47:15 +000013; 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
Teresa Johnson99ee8972015-11-06 17:50:53 +000015; ONLYNEEDED-NOT:@U
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()
Teresa Johnson46c7bcb2015-11-06 17:50:48 +000025
26@X = global i32 5
27@U = global i32 6
Teresa Johnson99ee8972015-11-06 17:50:53 +000028@U_linkonce = linkonce_odr hidden global i32 6
Teresa Johnson46c7bcb2015-11-06 17:50:48 +000029define i32 @foo() { ret i32 7 }
30define i32 @unused() { ret i32 8 }
Teresa Johnson99ee8972015-11-06 17:50:53 +000031define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
32@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
Teresa Johnson46c7bcb2015-11-06 17:50:48 +000033
Teresa Johnson99ee8972015-11-06 17:50:53 +000034@weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
35@analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
36
37define void @globalfunc1() #0 {
38entry:
39 ret void
40}
41
42define void @globalfunc2() #0 {
43entry:
44 ret void
45}
46
47$linkoncefunc2 = comdat any
48define linkonce_odr void @linkoncefunc2() #0 comdat {
49entry:
50 ret void
51}
52
Teresa Johnsond1fec242015-11-10 21:09:06 +000053!llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
Teresa Johnson46c7bcb2015-11-06 17:50:48 +000054!0 = !{i32 ()* @unused}
55!1 = !{i32* @U}
Teresa Johnson99ee8972015-11-06 17:50:53 +000056!2 = !{i32 ()* @unused_linkonce}
57!3 = !{i32* @U_linkonce}
58!4 = !{void (...)* @weakalias}
59!5 = !{void (...)* @analias}
60!6 = !{void (...)* @linkoncealias}