1// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
2// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
3// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
4
5// REQUIRES: amdgpu-registered-target
6
7// FVIS-DEFAULT:  @glob = local_unnamed_addr
8// FVIS-PROTECTED: @glob = protected local_unnamed_addr
9// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
10int glob = 0;
11// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
12// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
13// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
14__attribute__((visibility("hidden"))) int glob_hidden = 0;
15// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
16// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
17// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
18__attribute__((visibility("protected"))) int glob_protected = 0;
19// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
20// FVIS-PROTECTED: @glob_default = local_unnamed_addr
21// FVIS-HIDDEN: @glob_default = local_unnamed_addr
22__attribute__((visibility("default"))) int glob_default = 0;
23
24// FVIS-DEFAULT:  @ext = external local_unnamed_addr
25// FVIS-PROTECTED: @ext = external protected local_unnamed_addr
26// FVIS-HIDDEN: @ext = external hidden local_unnamed_addr
27extern int ext;
28// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
29// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
30// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
31__attribute__((visibility("hidden"))) extern int ext_hidden;
32// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
33// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
34// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
35__attribute__((visibility("protected"))) extern int ext_protected;
36// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
37// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
38// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
39__attribute__((visibility("default"))) extern int ext_default;
40
41// FVIS-DEFAULT: define amdgpu_kernel void @kern()
42// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
43// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
44kernel void kern() {}
45// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_hidden()
46// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_hidden()
47// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_hidden()
48__attribute__((visibility("hidden"))) kernel void kern_hidden() {}
49// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_protected()
50// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_protected()
51// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_protected()
52__attribute__((visibility("protected"))) kernel void kern_protected() {}
53// FVIS-DEFAULT: define amdgpu_kernel void @kern_default()
54// FVIS-PROTECTED: define amdgpu_kernel void @kern_default()
55// FVIS-HIDDEN: define amdgpu_kernel void @kern_default()
56__attribute__((visibility("default"))) kernel void kern_default() {}
57
58// FVIS-DEFAULT: define void @func()
59// FVIS-PROTECTED: define protected void @func()
60// FVIS-HIDDEN: define hidden void @func()
61void func() {}
62// FVIS-DEFAULT: define hidden void @func_hidden()
63// FVIS-PROTECTED: define hidden void @func_hidden()
64// FVIS-HIDDEN: define hidden void @func_hidden()
65__attribute__((visibility("hidden"))) void func_hidden() {}
66// FVIS-DEFAULT: define protected void @func_protected()
67// FVIS-PROTECTED: define protected void @func_protected()
68// FVIS-HIDDEN: define protected void @func_protected()
69__attribute__((visibility("protected"))) void func_protected() {}
70// FVIS-DEFAULT: define void @func_default()
71// FVIS-PROTECTED: define void @func_default()
72// FVIS-HIDDEN: define void @func_default()
73__attribute__((visibility("default"))) void func_default() {}
74
75extern kernel void ext_kern();
76__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
77__attribute__((visibility("protected"))) extern kernel void ext_kern_protected();
78__attribute__((visibility("default"))) extern kernel void ext_kern_default();
79
80extern void ext_func();
81__attribute__((visibility("hidden"))) extern void ext_func_hidden();
82__attribute__((visibility("protected"))) extern void ext_func_protected();
83__attribute__((visibility("default"))) extern void ext_func_default();
84
85void use() {
86    glob = ext + ext_hidden + ext_protected + ext_default;
87    ext_kern();
88    ext_kern_hidden();
89    ext_kern_protected();
90    ext_kern_default();
91    ext_func();
92    ext_func_hidden();
93    ext_func_protected();
94    ext_func_default();
95}
96
97// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern()
98// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern()
99// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern()
100
101// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_hidden()
102// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_hidden()
103// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_hidden()
104
105// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_protected()
106// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_protected()
107// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_protected()
108
109// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern_default()
110// FVIS-PROTECTED: declare amdgpu_kernel void @ext_kern_default()
111// FVIS-HIDDEN: declare amdgpu_kernel void @ext_kern_default()
112
113
114// FVIS-DEFAULT: declare void @ext_func()
115// FVIS-PROTECTED: declare protected void @ext_func()
116// FVIS-HIDDEN: declare hidden void @ext_func()
117
118// FVIS-DEFAULT: declare hidden void @ext_func_hidden()
119// FVIS-PROTECTED: declare hidden void @ext_func_hidden()
120// FVIS-HIDDEN: declare hidden void @ext_func_hidden()
121
122// FVIS-DEFAULT: declare protected void @ext_func_protected()
123// FVIS-PROTECTED: declare protected void @ext_func_protected()
124// FVIS-HIDDEN: declare protected void @ext_func_protected()
125
126// FVIS-DEFAULT: declare void @ext_func_default()
127// FVIS-PROTECTED: declare void @ext_func_default()
128// FVIS-HIDDEN: declare void @ext_func_default()
129