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: -fapply-global-visibility-to-externs \ 9 // RUN: -fvisibility-from-dllstorageclass \ 10 // RUN: -x c++ %s -S -emit-llvm -o - | \ 11 // RUN: FileCheck %s --check-prefixes=DEFAULTS 12 13 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \ 14 // RUN: -fvisibility hidden \ 15 // RUN: -fapply-global-visibility-to-externs \ 16 // RUN: -fvisibility-from-dllstorageclass \ 17 // RUN: -fvisibility-dllexport=hidden \ 18 // RUN: -fvisibility-nodllstorageclass=protected \ 19 // RUN: -fvisibility-externs-dllimport=hidden \ 20 // RUN: -fvisibility-externs-nodllstorageclass=protected \ 21 // RUN: -x c++ %s -S -emit-llvm -o - | \ 22 // RUN: FileCheck %s --check-prefixes=EXPLICIT 23 24 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \ 25 // RUN: -fvisibility hidden \ 26 // RUN: -fapply-global-visibility-to-externs \ 27 // RUN: -fvisibility-from-dllstorageclass \ 28 // RUN: -fvisibility-dllexport=default \ 29 // RUN: -fvisibility-nodllstorageclass=default \ 30 // RUN: -fvisibility-externs-dllimport=default \ 31 // RUN: -fvisibility-externs-nodllstorageclass=default \ 32 // RUN: -x c++ %s -S -emit-llvm -o - | \ 33 // RUN: FileCheck %s --check-prefixes=ALL_DEFAULT 34 35 // Local 36 static void l() {} 37 void use_locals(){l();} 38 // DEFAULTS-DAG: define internal void @_ZL1lv() 39 // EXPLICIT-DAG: define internal void @_ZL1lv() 40 // ALL_DEFAULT-DAG: define internal void @_ZL1lv() 41 42 // Function 43 void f() {} 44 void __declspec(dllexport) exported_f() {} 45 // DEFAULTS-DAG: define hidden void @_Z1fv() 46 // DEFAULTS-DAG: define void @_Z10exported_fv() 47 // EXPLICIT-DAG: define protected void @_Z1fv() 48 // EXPLICIT-DAG: define hidden void @_Z10exported_fv() 49 // ALL_DEFAULT-DAG: define void @_Z1fv() 50 // ALL_DEFAULT-DAG: define void @_Z10exported_fv() 51 52 // Variable 53 int d = 123; 54 __declspec(dllexport) int exported_d = 123; 55 // DEFAULTS-DAG: @d = hidden global 56 // DEFAULTS-DAG: @exported_d = global 57 // EXPLICIT-DAG: @d = protected global 58 // EXPLICIT-DAG: @exported_d = hidden global 59 // ALL_DEFAULT-DAG: @d = global 60 // ALL_DEFAULT-DAG: @exported_d = global 61 62 // Alias 63 extern "C" void aliased() {} 64 void a() __attribute__((alias("aliased"))); 65 void __declspec(dllexport) a_exported() __attribute__((alias("aliased"))); 66 // DEFAULTS-DAG: @_Z1av = hidden alias 67 // DEFAULTS-DAG: @_Z10a_exportedv = alias 68 // EXPLICIT-DAG: @_Z1av = protected alias 69 // EXPLICIT-DAG: @_Z10a_exportedv = hidden alias 70 // ALL_DEFAULT-DAG: @_Z1av = alias 71 // ALL_DEFAULT-DAG: @_Z10a_exportedv = alias 72 73 // Declaration 74 extern void e(); 75 extern void __declspec(dllimport) imported_e(); 76 // DEFAULTS-DAG: declare hidden void @_Z1ev() 77 // DEFAULTS-DAG: declare void @_Z10imported_ev() 78 // EXPLICIT-DAG: declare protected void @_Z1ev() 79 // EXPLICIT-DAG: declare hidden void @_Z10imported_ev() 80 // ALL_DEFAULT-DAG: declare void @_Z1ev() 81 // ALL_DEFAULT-DAG: declare void @_Z10imported_ev() 82 83 // Weak Declaration 84 __attribute__((weak)) 85 extern void w(); 86 __attribute__((weak)) 87 extern void __declspec(dllimport) imported_w(); 88 // DEFAULTS-DAG: declare extern_weak hidden void @_Z1wv() 89 // DEFAULTS-DAG: declare extern_weak void @_Z10imported_wv() 90 // EXPLICIT-DAG: declare extern_weak protected void @_Z1wv() 91 // EXPLICIT-DAG: declare extern_weak hidden void @_Z10imported_wv() 92 // ALL_DEFAULT-DAG: declare extern_weak void @_Z1wv() 93 // ALL_DEFAULT-DAG: declare extern_weak void @_Z10imported_wv() 94 95 void use_declarations(){e(); imported_e(); w(); imported_w();} 96 97 // Show that -fvisibility-from-dllstorageclass overrides the effect of visibility annotations. 98 99 struct __attribute__((type_visibility("protected"))) t { 100 virtual void foo(); 101 }; 102 void t::foo() {} 103 // DEFAULTS-DAG: @_ZTV1t = hidden unnamed_addr constant 104 105 int v __attribute__ ((__visibility__ ("protected"))) = 123; 106 // DEFAULTS-DAG: @v = hidden global 107 108 #pragma GCC visibility push(protected) 109 int p = 345; 110 #pragma GCC visibility pop 111 // DEFAULTS-DAG: @p = hidden global 112