1 // REQUIRES: x86-registered-target
2 
3 // Test that -fvisibility-from-dllstorageclass maps DLL storage class to visibility
4 // and that it overrides the effect of visibility options and annotations.
5 
6 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
7 // RUN:     -fvisibility hidden \
8 // RUN:     -fvisibility-from-dllstorageclass \
9 // RUN:     -x c++ %s -S -emit-llvm -o - | \
10 // RUN:   FileCheck %s --check-prefixes=DEFAULT
11 
12 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
13 // RUN:     -fvisibility hidden \
14 // RUN:     -fvisibility-from-dllstorageclass \
15 // RUN:     -fvisibility-dllexport=hidden \
16 // RUN:     -fvisibility-nodllstorageclass=protected \
17 // RUN:     -fvisibility-externs-dllimport=hidden \
18 // RUN:     -fvisibility-externs-nodllstorageclass=protected \
19 // RUN:     -x c++  %s -S -emit-llvm -o - | \
20 // RUN:   FileCheck %s --check-prefixes=EXPLICIT
21 
22 // Local
23 static void l() {}
24 void use_locals(){l();}
25 // DEFAULT-DAG: define internal void @_ZL1lv()
26 // EXPLICIT-DAG: define internal void @_ZL1lv()
27 
28 // Function
29 void f() {}
30 void __declspec(dllexport) exported_f() {}
31 // DEFAULT-DAG: define hidden void @_Z1fv()
32 // DEFAULT-DAG: define dso_local void @_Z10exported_fv()
33 // EXPLICIT-DAG: define protected void @_Z1fv()
34 // EXPLICIT-DAG: define hidden void @_Z10exported_fv()
35 
36 // Variable
37 int d = 123;
38 __declspec(dllexport) int exported_d = 123;
39 // DEFAULT-DAG: @d = hidden global
40 // DEFAULT-DAG: @exported_d = dso_local global
41 // EXPLICIT-DAG: @d = protected global
42 // EXPLICIT-DAG: @exported_d = hidden global
43 
44 // Alias
45 extern "C" void aliased() {}
46 void a() __attribute__((alias("aliased")));
47 void __declspec(dllexport) a_exported() __attribute__((alias("aliased")));
48 // DEFAULT-DAG: @_Z1av = hidden alias
49 // DEFAULT-DAG: @_Z10a_exportedv = dso_local alias
50 // EXPLICIT-DAG: @_Z1av = protected alias
51 // EXPLICIT-DAG: @_Z10a_exportedv = hidden alias
52 
53 // Declaration
54 extern void e();
55 extern void __declspec(dllimport) imported_e();
56 void use_declarations(){e(); imported_e();}
57 // DEFAULT-DAG: declare hidden void @_Z1ev()
58 // DEFAULT-DAG: declare void @_Z10imported_ev()
59 // EXPLICIT-DAG: declare protected void @_Z1ev()
60 // EXPLICIT-DAG: declare hidden void @_Z10imported_ev()
61 
62 // Show that -fvisibility-from-dllstorageclass overrides the effect of visibility annotations.
63 
64 struct __attribute__((type_visibility("protected"))) t {
65   virtual void foo();
66 };
67 void t::foo() {}
68 // DEFAULT-DAG: @_ZTV1t = hidden unnamed_addr constant
69 
70 int v __attribute__ ((__visibility__ ("protected"))) = 123;
71 // DEFAULT-DAG: @v = hidden global
72 
73 #pragma GCC visibility push(protected)
74 int p = 345;
75 #pragma GCC visibility pop
76 // DEFAULT-DAG: @p = hidden global
77