1 ; RUN: split-file %s %t
2 ; RUN: opt -module-summary %t/a.ll -o %ta.bc
3 ; RUN: opt -module-summary %t/b.ll -o %tb.bc
5 ;; Test visibility propagation. The prevailing definitions are all from %tb.bc.
6 ; RUN: llvm-lto2 run -save-temps -enable-import-metadata -o %t1.bc %ta.bc %tb.bc \
7 ; RUN: -r=%ta.bc,var1,l -r=%ta.bc,var2,l \
8 ; RUN: -r=%ta.bc,hidden_def_weak_def,l -r=%ta.bc,protected_def_weak_def,l -r=%ta.bc,protected_def_weak_hidden_def,l \
9 ; RUN: -r=%ta.bc,protected_def_hidden_ref,l -r=%ta.bc,not_imported,l -r=%ta.bc,hidden_def_ref,l \
10 ; RUN: -r=%ta.bc,hidden_def_weak_ref,l \
11 ; RUN: -r=%ta.bc,ext, -r=%ta.bc,main,plx \
12 ; RUN: -r=%tb.bc,var1,plx -r=%tb.bc,var2,plx \
13 ; RUN: -r=%tb.bc,hidden_def_weak_def,pl -r=%tb.bc,protected_def_weak_def,pl -r=%tb.bc,protected_def_weak_hidden_def,pl \
14 ; RUN: -r=%tb.bc,protected_def_hidden_ref,pl -r=%tb.bc,not_imported,pl -r=%tb.bc,hidden_def_ref,pl \
15 ; RUN: -r=%tb.bc,hidden_def_weak_ref,pl
16 ; RUN: llvm-dis < %t1.bc.1.3.import.bc | FileCheck %s
18 ;; %tb.bc does not import anything, so we just check 1.promote.
19 ; RUN: llvm-dis < %t1.bc.2.1.promote.bc | FileCheck %s --check-prefix=CHECK2
22 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-unknown-linux-gnu"
25 ; CHECK: @var1 = external hidden global i32, align 4
26 ; CHECK-NEXT: @var2 = available_externally hidden global i32 1, align 4
28 @var1 = weak global i32 1, align 4
29 @var2 = extern_weak global i32
31 declare void @ext(ptr)
33 ; CHECK: declare hidden i32 @hidden_def_weak_def()
34 ; CHECK: declare protected void @protected_def_weak_def()
35 ; CHECK: declare hidden void @protected_def_weak_hidden_def()
36 ;; Currently the visibility is not propagated onto an unimported function,
37 ;; because we don't have summaries for declarations.
38 ; CHECK: declare extern_weak void @not_imported()
39 ; CHECK: define available_externally hidden void @hidden_def_ref() !thinlto_src_module !0 !thinlto_src_file !1
40 ; CHECK: define available_externally hidden void @hidden_def_weak_ref() !thinlto_src_module !0 !thinlto_src_file !1
41 ;; This can be hidden, but we cannot communicate the declaration's visibility
42 ;; to other modules because declarations don't have summaries, and the IRLinker
43 ;; overrides it when importing the protected def.
44 ; CHECK: define available_externally protected void @protected_def_hidden_ref() !thinlto_src_module !0 !thinlto_src_file !1
46 ; CHECK2: define hidden i32 @hidden_def_weak_def()
47 ; CHECK2: define protected void @protected_def_weak_def()
48 ; CHECK2: define hidden void @protected_def_weak_hidden_def()
49 ; CHECK2: define hidden void @hidden_def_ref()
50 ; CHECK2: define hidden void @hidden_def_weak_ref()
51 ; CHECK2: define protected void @protected_def_hidden_ref()
52 ; CHECK2: define hidden void @not_imported()
54 define weak i32 @hidden_def_weak_def() {
56 %0 = load i32, ptr @var2
60 define weak void @protected_def_weak_def() {
65 define weak hidden void @protected_def_weak_hidden_def() {
70 declare extern_weak void @not_imported()
72 declare void @hidden_def_ref()
73 declare extern_weak void @hidden_def_weak_ref()
74 declare hidden void @protected_def_hidden_ref()
78 call void @ext(ptr @hidden_def_weak_def)
79 call void @ext(ptr @protected_def_weak_def)
80 call void @ext(ptr @protected_def_weak_hidden_def)
81 call void @ext(ptr @hidden_def_ref)
82 call void @ext(ptr @hidden_def_weak_ref)
83 call void @ext(ptr @protected_def_hidden_ref)
84 call void @ext(ptr @not_imported)
86 ;; Calls ensure the functions are imported.
87 call i32 @hidden_def_weak_def()
88 call void @protected_def_weak_def()
89 call void @protected_def_weak_hidden_def()
90 call void @hidden_def_ref()
91 call void @hidden_def_weak_ref()
92 call void @protected_def_hidden_ref()
97 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
98 target triple = "x86_64-unknown-linux-gnu"
100 @var1 = hidden global i32 1, align 4
101 @var2 = hidden global i32 1, align 4
103 define hidden i32 @hidden_def_weak_def() {
105 %0 = load i32, ptr @var1
109 define protected void @protected_def_weak_def() {
114 define protected void @protected_def_weak_hidden_def() {
119 define hidden void @hidden_def_ref() {
124 define hidden void @hidden_def_weak_ref() {
129 define protected void @protected_def_hidden_ref() {
134 define hidden void @not_imported() {